import pandas as pd
import numpy as np
from datetime import datetime, timedelta
# ---------------------------------------------------------
# 1. INPUT DATA: GRANTS & EVENTS
# ---------------------------------------------------------
# Define Grants
# Vesting_Schedule_Months: Total months to vest
# Cliff_Months: Months before any vesting happens
grants_data = [
{'Grant_ID': 'G100', 'Employee': 'Alice', 'Grant_Date': '2023-01-01', 'Shares': 10000,
'Fair_Value_Per_Share': 10.0, 'Vesting_Months': 36, 'Cliff_Months': 12},
{'Grant_ID': 'G200', 'Employee': 'Bob', 'Grant_Date': '2023-01-01', 'Shares': 5000,
'Fair_Value_Per_Share': 10.0, 'Vesting_Months': 36, 'Cliff_Months': 12},
{'Grant_ID': 'G300', 'Employee': 'Charlie', 'Grant_Date': '2023-01-01', 'Shares': 8000,
'Fair_Value_Per_Share': 10.0, 'Vesting_Months': 36, 'Cliff_Months': 12},
]
# Define Events (Forfeitures & Modifications)
# Types: 'FORFEITURE', 'MODIFICATION'
# For Modifications: 'New_Fair_Value' represents the value of the new instrument at mod date
events_data = [
# Bob leaves at month 6 (before cliff). All expense reversed.
{'Grant_ID': 'G200', 'Event_Date': '2023-07-01', 'Event_Type': 'FORFEITURE', 'New_Fair_Value': 0},
# Charlie gets a modification at month 12.
# Original Value remaining: $10. New Value of modified award: $15. Incremental = $5.
{'Grant_ID': 'G300', 'Event_Date': '2024-01-01', 'Event_Type': 'MODIFICATION', 'New_Fair_Value': 15.0}
]
df_grants = pd.DataFrame(grants_data)
df_events = pd.DataFrame(events_data)
# Convert dates
df_grants['Grant_Date'] = pd.to_datetime(df_grants['Grant_Date'])
df_events['Event_Date'] = pd.to_datetime(df_events['Event_Date'])
# ---------------------------------------------------------
# 2. MODEL ENGINE
# ---------------------------------------------------------
def calculate_equity_expense(grants_df, events_df, start_date, end_date):
# Create a monthly date range for the schedule
date_range = pd.date_range(start=start_date, end=end_date, freq='MS') # Month Start
# Explode grants into a monthly schedule
records = []
for _, grant in grants_df.iterrows():
grant_date = grant['Grant_Date']
vest_end_date = grant_date + pd.DateOffset(months=grant['Vesting_Months'])
# Generate monthly periods for this grant
for period_date in date_range:
# Only include periods after grant date
if period_date <= grant_date:
continue
# Calculate Months Elapsed
months_elapsed = (period_date.year - grant_date.year) * 12 + (period_date.month - grant_date.month)
# Determine expense fraction (Straight Line)
# Note: Simplified logic - assuming even monthly expense
total_months = grant['Vesting_Months']
# Logic: If within vesting period
if months_elapsed <= total_months:
# Base Expense Logic
monthly_expense = (grant['Shares'] * grant['Fair_Value_Per_Share']) / total_months
# Determine if this period is affected by an event
active_shares = grant['Shares']
incremental_expense = 0
# --- Handle Events ---
grant_events = events_df[events_df['Grant_ID'] == grant['Grant_ID']]
for _, event in grant_events.iterrows():
months_until_event = (event['Event_Date'].year - grant_date.year) * 12 + \
(event['Event_Date'].month - grant_date.month)
# 1. FORFEITURE LOGIC
if event['Event_Type'] == 'FORFEITURE':
# If current period is AFTER the forfeiture, expense is 0
if months_elapsed > months_until_event:
monthly_expense = 0
active_shares = 0
# If current period IS the forfeiture month (True-up)
# We calculate the total recognized so far vs total required and reverse the diff
elif months_elapsed == months_until_event:
# In a real model, you'd look at cumulative.
# Here we simply zero out future and assume reversal handles in reporting layer.
# For this simple schedule, we flag it.
monthly_expense = 0 # Set to 0 logic for simplicity in this snippet
active_shares = 0
# 2. MODIFICATION LOGIC
if event['Event_Type'] == 'MODIFICATION':
# Only affects periods AFTER modification
if months_elapsed >= months_until_event:
# Calculate Incremental Value
original_fv = grant['Fair_Value_Per_Share']
new_fv = event['New_Fair_Value']
incremental_fv = max(0, new_fv - original_fv)
# Remaining months
remaining_months = total_months - months_until_event
if remaining_months > 0:
incremental_expense = (active_shares * incremental_fv) / remaining_months
# Finalize Record
total_recognized = monthly_expense + incremental_expense
# Handle Cliff Logic (Expense is recognized, but 'Vested Shares' column is 0)
vested_shares = 0
if months_elapsed > grant['Cliff_Months']:
# Simplified vesting rate
vested_rate = min(months_elapsed / total_months, 1.0)
vested_shares = int(grant['Shares'] * vested_rate)
records.append({
'Date': period_date,
'Grant_ID': grant['Grant_ID'],
'Employee': grant['Employee'],
'Original_Shares': grant['Shares'],
'Active_Shares': active_shares, # Shares still accounting for
'Monthly_Expense': monthly_expense,
'Incremental_Expense': incremental_expense,
'Total_Expense': total_recognized,
'Cumulative_Expense': 0, # Calculate later
'Vested_Shares': vested_shares
})
# Create Output DataFrame
model_df = pd.DataFrame(records)
if not model_df.empty:
# Calculate Cumulative Expense per Grant
model_df['Cumulative_Expense'] = model_df.groupby('Grant_ID')['Total_Expense'].cumsum()
return model_df
# ---------------------------------------------------------
# 3. EXECUTE AND DISPLAY
# ---------------------------------------------------------
# Run model for 3 years
start = datetime(2023, 1, 1)
end = datetime(2025, 12, 1)
result_df = calculate_equity_expense(df_grants, df_events, start, end)
# Filter to show only key months (Quarter ends) or specific events for readability
key_dates = result_df[result_df['Date'].dt.month.isin([1, 4, 7, 10])]
print("--- Equity Compensation Expense Schedule (Quarterly Snapshots) ---")
print(key_dates[['Date', 'Grant_ID', 'Active_Shares', 'Monthly_Expense', 'Incremental_Expense', 'Total_Expense', 'Cumulative_Expense']].to_string(index=False))
# Pivot for Financial Reporting View
pivot_report = result_df.groupby('Date')['Total_Expense'].sum().reset_index()
print("\n--- Total Monthly Expense (Income Statement Impact) ---")
print(pivot_report[pivot_report['Date'].dt.month.isin([1, 4, 7, 10])].to_string(index=False))