python
import pandas as pd
import numpy as np
# ===============================================
# SALES COMP PLAN MONITORING TOOL
# ===============================================
# This Python script monitors sales compensation plans for multiple reps.
# It calculates:
# - ATTAINMENT: % of quota achieved (sales / quota * 100)
# - GROSS PAYOUT: Tiered commission before cap
# - CAPPED PAYOUT: Final payout after applying cap
# - CAP STATUS: Whether cap was hit
#
# SAMPLE COMP PLAN (CUSTOMIZABLE):
# - Base: 10% commission on sales up to 100% quota
# - Accelerator 1: 15% on sales from 100% to 150% quota
# - Accelerator 2: 20% on sales above 150% quota
# - Cap: 200% of target earnings (target = 10% * quota)
#
# USAGE:
# 1. Edit the `reps_data` list with your data (Name, Quota, Actual Sales)
# 2. Optionally tweak plan params in calculate_payout()
# 3. Run the script → Outputs a monitoring dashboard table
# ===============================================
def calculate_payout(quota: float, sales: float,
base_rate: float = 0.10,
accel1_start: float = 1.0, accel1_rate: float = 0.15,
accel2_start: float = 1.5, accel2_rate: float = 0.20,
cap_multiple: float = 2.0) -> dict:
"""
Core payout calculator with tiers and cap.
Returns dict with attainment, payouts, and cap info.
"""
if quota <= 0:
return {'attainment_pct': 0, 'gross_payout': 0, 'capped_payout': 0,
'cap_applied': False, 'target': 0, 'cap_limit': 0}
target = base_rate * quota
cap_limit = cap_multiple * target
# Tiered sales calculations
tier1_sales = min(quota * accel1_start, sales) # Base tier (up to 100%)
tier2_sales = max(0, min(quota * accel2_start, sales) - quota * accel1_start) # 100-150%
tier3_sales = max(0, sales - quota * accel2_start) # 150%+
gross_payout = (tier1_sales * base_rate +
tier2_sales * accel1_rate +
tier3_sales * accel2_rate)
capped_payout = min(gross_payout, cap_limit)
cap_applied = capped_payout < gross_payout
attainment_pct = (sales / quota) * 100
return {
'attainment_pct': round(attainment_pct, 1),
'gross_payout': round(gross_payout, 0),
'capped_payout': round(capped_payout, 0),
'cap_applied': cap_applied,
'target': round(target, 0),
'cap_limit': round(cap_limit, 0)
}
def monitor_comp_plan(reps_data: list) -> pd.DataFrame:
"""
Monitors a list of reps: [(name, quota, sales), ...]
Returns a styled Pandas DataFrame for easy viewing/export.
"""
results = []
for name, quota, sales in reps_data:
result = calculate_payout(quota, sales)
result['rep_name'] = name
result['quota'] = quota
result['sales'] = sales
results.append(result)
df = pd.DataFrame(results)
# Reorder columns for dashboard view
cols = ['rep_name', 'quota', 'sales', 'attainment_pct', 'target',
'gross_payout', 'capped_payout', 'cap_limit', 'cap_applied']
df = df[cols].round(0).astype({'attainment_pct': 'float', 'cap_applied': 'bool'})
# Style for monitoring dashboard (green for on-target, red for caps, etc.)
def style_dashboard(df):
return df.style\
.format({'attainment_pct': '{:.1f}%', 'quota': '${:,.0f}', 'sales': '${:,.0f}',
'target': '${:,.0f}', 'gross_payout': '${:,.0f}', 'capped_payout': '${:,.0f}',
'cap_limit': '${:,.0f}'})\
.bar(subset=['attainment_pct'], color='lightgreen')\
.background_gradient(subset=['gross_payout', 'capped_payout'], cmap='YlGn')\
.applymap(lambda x: 'background-color: #ffcccb' if x else '', subset=['cap_applied'])\
.hide(axis='index')
return style_dashboard(df)
# ===============================================
# SAMPLE DATA - EDIT THIS FOR YOUR TEAM
# ===============================================
reps_data = [
('Alice Johnson', 1000000, 800000), # Underperformer
('Bob Smith', 1000000, 1200000), # Solid accelerator
('Charlie Lee', 1000000, 2500000), # Overachiever (will hit cap)
('Dana Kim', 1500000, 2000000), # High quota example
('Eve Patel', 500000, 750000), # Low quota accelerator
]
# ===============================================
# RUN THE MONITOR
# ===============================================
if __name__ == "__main__":
print("🔍 SALES COMP PLAN MONITORING DASHBOARD\n")
dashboard = monitor_comp_plan(reps_data)
print(dashboard.to_string())
print("\n💡 Export to HTML/Excel: dashboard.to_excel('sales_monitor.xlsx') or .to_html('dashboard.html')")
This gives real-time monitoring—attainment tracking, cap alerts, and payout transparency. Ping me for tweaks! 🚀