| name | roi-calculator |
| description | Calculate ROI for marketing campaigns, investments, and business decisions. Includes break-even analysis, payback period, and comparative ROI. |
ROI Calculator
Comprehensive ROI calculations for marketing, investments, and business decisions.
Features
- Simple ROI: Basic return on investment calculation
- Marketing ROI: Campaign performance with attribution
- Investment ROI: Time-adjusted returns with CAGR
- Break-Even Analysis: Find profit threshold
- Payback Period: Time to recover investment
- Comparative Analysis: Compare multiple options
- What-If Scenarios: Sensitivity analysis
Quick Start
from roi_calculator import ROICalculator
calc = ROICalculator()
roi = calc.simple_roi(investment=10000, return_value=15000)
print(f"ROI: {roi['roi_percent']}%")
marketing = calc.marketing_roi(
ad_spend=5000,
revenue_generated=25000,
cost_of_goods=10000
)
print(f"Marketing ROI: {marketing['roi_percent']}%")
breakeven = calc.break_even(
fixed_costs=50000,
price_per_unit=100,
variable_cost_per_unit=60
)
print(f"Break-even units: {breakeven['units']}")
CLI Usage
python roi_calculator.py --investment 10000 --return 15000
python roi_calculator.py --marketing --spend 5000 --revenue 25000 --cogs 10000
python roi_calculator.py --breakeven --fixed 50000 --price 100 --variable 60
python roi_calculator.py --investment 10000 --return 20000 --years 5
python roi_calculator.py --payback --investment 100000 --annual-return 25000
python roi_calculator.py --compare investments.csv
API Reference
ROICalculator Class
class ROICalculator:
def __init__(self)
def simple_roi(self, investment: float, return_value: float) -> Dict
def net_roi(self, investment: float, gain: float, costs: float = 0) -> Dict
def marketing_roi(self, ad_spend: float, revenue_generated: float,
cost_of_goods: float = 0) -> Dict
def campaign_roi(self, campaigns: List[Dict]) -> pd.DataFrame
def roas(self, ad_spend: float, revenue: float) -> Dict
def investment_roi(self, initial: float, final: float, years: float) -> Dict
def cagr(self, initial: float, final: , years: ) ->
() ->
() ->
() ->
() ->
() ->
() -> pd.DataFrame
() -> []
() -> pd.DataFrame
() -> pd.DataFrame
() ->
ROI Calculations
Simple ROI
result = calc.simple_roi(investment=10000, return_value=15000)
Net ROI (with additional costs)
result = calc.net_roi(
investment=10000,
gain=8000,
costs=2000
)
Marketing ROI
Campaign ROI
result = calc.marketing_roi(
ad_spend=5000,
revenue_generated=25000,
cost_of_goods=10000
)
Return on Ad Spend (ROAS)
result = calc.roas(ad_spend=1000, revenue=4000)
Multi-Campaign Comparison
campaigns = [
{"name": "Facebook", "spend": 2000, "revenue": 8000, "cogs": 3000},
{"name": "Google", "spend": 3000, "revenue": 15000, "cogs": 6000},
{"name": "Email", "spend": 500, "revenue": 3000, "cogs": 1000}
]
results = calc.campaign_roi(campaigns)
Investment ROI
Time-Adjusted ROI with CAGR
result = calc.investment_roi(
initial=10000,
final=20000,
years=5
)
Total Return with Dividends
result = calc.total_return(
initial=10000,
final=12000,
dividends=1500
)
Break-Even Analysis
Unit Break-Even
result = calc.break_even(
fixed_costs=50000,
price_per_unit=100,
variable_cost_per_unit=60
)
Revenue Break-Even
result = calc.break_even_revenue(
fixed_costs=50000,
contribution_margin_ratio=0.4
)
Payback Period
Simple Payback
result = calc.payback_period(
investment=100000,
annual_cash_flow=25000
)
Uneven Cash Flows
result = calc.payback_period_uneven(
investment=100000,
cash_flows=[20000, 30000, 40000, 35000, 25000]
)
Comparative Analysis
Compare Multiple Investments
investments = [
{"name": "Project A", "investment": 50000, "return": 75000, "years": 2},
{"name": "Project B", "investment": 30000, "return": 48000, "years": 3},
{"name": "Project C", "investment": 100000, "return": 180000, "years": 5}
]
comparison = calc.compare_investments(investments)
Rank by ROI
ranked = calc.rank_by_roi(investments)
Sensitivity Analysis
Variable Sensitivity
base_case = {
"fixed_costs": 50000,
"price_per_unit": 100,
"variable_cost_per_unit": 60,
"units_sold": 2000
}
sensitivity = calc.sensitivity_analysis(
base_case=base_case,
variables={
"price_per_unit": [80, 90, 100, 110, 120],
"units_sold": [1500, 1750, 2000, 2250, 2500]
}
)
Scenario Analysis
scenarios = [
{"name": "Pessimistic", "units": 1500, "price": 90},
{"name": "Base", "units": 2000, "price": 100},
{"name": "Optimistic", "units": 2500, "price": 110}
]
results = calc.scenario_analysis(scenarios)
Example Workflows
Marketing Campaign Analysis
calc = ROICalculator()
campaigns = [
{"name": "Black Friday Email", "spend": 2000, "revenue": 45000, "cogs": 20000},
{"name": "Holiday Facebook", "spend": 8000, "revenue": 35000, "cogs": 14000},
{"name": "Google Shopping", "spend": 5000, "revenue": 28000, "cogs": 12000}
]
results = calc.campaign_roi(campaigns)
print(results.sort_values("roi_percent", ascending=False))
best = results.loc[results["roi_percent"].idxmax()]
print(f"Best ROI: {best['name']} at {best['roi_percent']:.1f}%")
Business Investment Decision
calc = ROICalculator()
options = [
{"name": "New Location", "investment": 200000, "annual_return": 45000},
{"name": "Equipment Upgrade", "investment": 75000, "annual_return": 20000},
{"name": "Digital Marketing", "investment": 30000, "annual_return": 12000}
]
for opt in options:
payback = calc.payback_period(opt["investment"], opt["annual_return"])
roi = calc.simple_roi(opt["investment"], opt["investment"] + opt["annual_return"] * 5)
print(f"{opt['name']}: Payback={payback['payback_years']:.1f}yr, 5yr ROI={roi['roi_percent']:.1f}%")
Pricing Strategy Analysis
calc = ROICalculator()
fixed_costs = 100000
variable_cost = 25
for price in [40, 50, 60, 75, 100]:
be = calc.break_even(fixed_costs, price, variable_cost)
print(f"Price ${price}: Break-even at {be['break_even_units']:,} units (${be['break_even_revenue']:,.0f})")
Dependencies
- pandas>=2.0.0
- numpy>=1.24.0