import streamlit as st
import pandas as pd
import numpy as np
import plotly.express as px
from plotly.subplots import make_subplots
import plotly.graph_objects as go
from datetime import datetime, timedelta
import io
# Page config
st.set_page_config(
page_title="Purchase Accounting Tracker",
page_icon="📊",
layout="wide",
initial_sidebar_state="expanded"
)
# Custom CSS for better styling
st.markdown("""
<style>
.main-header {font-size: 2.5rem; font-weight: bold; color: #1f77b4; text-align: center; margin-bottom: 2rem;}
.sub-header {font-size: 1.5rem; font-weight: bold; color: #ff7f0e;}
.metric-card {background-color: #f0f2f6; padding: 1rem; border-radius: 10px; text-align: center;}
</style>
""", unsafe_allow_html=True)
# Sidebar: Acquisition Details
st.sidebar.header("🏢 Acquisition Details")
acq_date = st.sidebar.date_input("Acquisition Date", value=datetime.now().date() - timedelta(days=365))
company_name = st.sidebar.text_input("Target Company Name", value="Acme Corp")
purchase_price_cash = st.sidebar.number_input("Cash Consideration ($)", value=10000000, step=100000)
purchase_price_equity = st.sidebar.number_input("Equity Consideration ($)", value=0, step=100000)
earnout_initial_fv = st.sidebar.number_input("Initial Earn-out Fair Value ($)", value=2000000, step=100000)
total_consideration = purchase_price_cash + purchase_price_equity + earnout_initial_fv
# Measurement Period
meas_period_months = st.sidebar.slider("Measurement Period (Months)", 1, 24, 12)
meas_period_end = (datetime.combine(acq_date, datetime.min.time()) + timedelta(days=30*meas_period_months)).date()
st.sidebar.info(f"**Total Consideration: ${total_consideration:,.0f}**\n**Measurement Period Ends: {meas_period_end}**")
# Main App
st.markdown('<h1 class="main-header">📈 Purchase Accounting Tracker</h1>', unsafe_allow_html=True)
st.markdown("Track fair value allocations, earn-outs, and changes for M&A purchase price accounting (PPA). Supports measurement period adjustments and post-closing remeasurements.")
# Tabs
tab1, tab2, tab3, tab4, tab5 = st.tabs(["💰 PPA Allocation", "🎯 Earn-outs", "🔄 Changes Log", "📊 Dashboard", "📥 Export"])
with tab1:
st.markdown('<h2 class="sub-header">Purchase Price Allocation (PPA)</h2>', unsafe_allow_html=True)
# Default PPA categories
default_assets = {
'Category': ['Cash & Equivalents', 'Accounts Receivable', 'Inventory', 'PP&E', 'Identified Intangibles', 'Other Assets'],
'Book Value': [500000, 1500000, 800000, 2000000, 3000000, 500000],
'Fair Value': [500000, 1450000, 900000, 2200000, 3200000, 500000],
'Provisional': [False, True, True, True, True, False],
'Notes': ['', 'Collectibility adj.', 'NRA adjustment', 'Appraisal', 'Valuation model', '']
}
default_liabs = {
'Category': ['Accounts Payable', 'Debt', 'Deferred Revenue', 'Contingent Liabilities', 'Other Liabilities'],
'Book Value': [600000, 1000000, 400000, 0, 200000],
'Fair Value': [600000, 1000000, 500000, 300000, 200000],
'Provisional': [False, False, True, True, False],
'Notes': ['', '', 'FV adjustment', 'Legal estimate', '']
}
# Assets Editor
st.subheader("Assets")
assets_df = st.data_editor(
pd.DataFrame(default_assets),
column_config={
"Book Value": st.column_config.NumberColumn("Book Value ($)", format="$%.0f"),
"Fair Value": st.column_config.NumberColumn("Fair Value ($)", format="$%.0f"),
"Provisional": st.column_config.CheckboxColumn("Provisional?"),
},
use_container_width=True,
hide_index=False
)
# Liabilities Editor
st.subheader("Liabilities")
liabs_df = st.data_editor(
pd.DataFrame(default_liabs),
column_config={
"Book Value": st.column_config.NumberColumn("Book Value ($)", format="$%.0f"),
"Fair Value": st.column_config.NumberColumn("Fair Value ($)", format="$%.0f"),
"Provisional": st.column_config.CheckboxColumn("Provisional?"),
},
use_container_width=True,
hide_index=False
)
# Calculations
total_fv_assets = assets_df['Fair Value'].sum()
total_fv_liabs = liabs_df['Fair Value'].sum()
net_identifiable = total_fv_assets - total_fv_liabs
goodwill = total_consideration - net_identifiable
col1, col2, col3, col4 = st.columns(4)
with col1:
st.metric("Total FV Assets", f"${total_fv_assets:,.0f}")
with col2:
st.metric("Total FV Liabs", f"${total_fv_liabs:,.0f}")
with col3:
st.metric("Net Identifiable Assets", f"${net_identifiable:,.0f}")
with col4:
st.metric("Goodwill", f"${goodwill:,.0f}", delta_color="normal")
with tab2:
st.markdown('<h2 class="sub-header">Earn-outs & Contingent Consideration</h2>', unsafe_allow_html=True)
# Earn-out details
col1, col2 = st.columns(2)
with col1:
earnout_milestones = st.text_area("Milestones/Targets", value="Year 1 EBITDA: $2M\nYear 2 Revenue: $10M", height=100)
discount_rate = st.number_input("Discount Rate (%)", value=10.0, step=0.5) / 100
with col2:
prob_weighted = st.number_input("Probability-Weighted Expected ($)", value=earnout_initial_fv)
current_fv = st.number_input("Current Fair Value ($)", value=earnout_initial_fv)
fv_change = current_fv - earnout_initial_fv
st.metric("FV Change (P&L Impact)", f"${fv_change:,.0f}", delta=fv_change)
# Earn-out History Editor
default_earnout_history = {
'Date': [acq_date, acq_date + timedelta(days=90), datetime.now().date()],
'Fair Value': [earnout_initial_fv, 2200000, current_fv],
'Change': [0, 200000, fv_change],
'P&L Impact': [0, 200000, fv_change],
'Notes': ['Initial recognition (Balance Sheet)', 'Q1 remeasurement', 'Latest valuation']
}
earnout_df = st.data_editor(
pd.DataFrame(default_earnout_history),
column_config={
"Date": st.column_config.DateColumn("Date"),
"Fair Value": st.column_config.NumberColumn("Fair Value ($)", format="$%.0f"),
"Change": st.column_config.NumberColumn("Change ($)", format="$%.0f"),
"P&L Impact": st.column_config.NumberColumn("P&L Impact ($)", format="$%.0f"),
},
use_container_width=True
)
with tab3:
st.markdown('<h2 class="sub-header">Changes & Adjustments Log</h2>', unsafe_allow_html=True)
# Changes Editor
default_changes = {
'Date': [acq_date + timedelta(days=30), acq_date + timedelta(days=180), datetime.now().date()],
'Item': ['Inventory FV', 'Intangibles FV', 'Earn-out Remeasurement'],
'Adjustment Amount': [-50000, 250000, fv_change],
'Within Meas. Period?': [True, True, False],
'Impact': ['Adjust Goodwill', 'Adjust Goodwill', 'P&L (Other Income/Expense)'],
'Notes': ['Working capital true-up', 'Final valuation report', 'Performance update']
}
changes_df = st.data_editor(
pd.DataFrame(default_changes),
column_config={
"Date": st.column_config.DateColumn("Date"),
"Adjustment Amount": st.column_config.NumberColumn("Adjustment ($)", format="$%.0f"),
"Within Meas. Period?": st.column_config.CheckboxColumn("Within Measurement Period?"),
},
use_container_width=True
)
# Summary of adjustments
meas_adj_total = changes_df[changes_df['Within Meas. Period?'] == True]['Adjustment Amount'].sum()
post_meas_total = changes_df[changes_df['Within Meas. Period?'] == False]['Adjustment Amount'].sum()
col1, col2 = st.columns(2)
with col1:
st.metric("Measurement Period Adjustments", f"${meas_adj_total:,.0f}")
with col2:
st.metric("Post-Measurement Changes (P&L)", f"${post_meas_total:,.0f}")
with tab4:
st.markdown('<h2 class="sub-header">Dashboard</h2>', unsafe_allow_html=True)
# Key Metrics Row
col1, col2, col3, col4, col5 = st.columns(5)
with col1:
st.markdown('<div class="metric-card"><h3>Total Consideration</h3><h2>${:,.0f}</h2></div>'.format(total_consideration), unsafe_allow_html=True)
with col2:
st.markdown('<div class="metric-card"><h3>Goodwill</h3><h2>${:,.0f}</h2></div>'.format(goodwill), unsafe_allow_html=True)
with col3:
st.markdown('<div class="metric-card"><h3>Earn-out Current FV</h3><h2>${:,.0f}</h2></div>'.format(current_fv), unsafe_allow_html=True)
with col4:
st.markdown('<div class="metric-card"><h3>Provisional Items</h3><h2>{}</h2></div>'.format(int(assets_df['Provisional'].sum() + liabs_df['Provisional'].sum())), unsafe_allow_html=True)
with col5:
st.markdown('<div class="metric-card"><h3>Days Since Acq.</h3><h2>{}</h2></div>'.format((datetime.now().date() - acq_date).days), unsafe_allow_html=True)
# Charts
row1_col1, row1_col2 = st.columns(2)
with row1_col1:
# PPA Pie Chart
ppa_data = pd.DataFrame({
'Category': ['Assets', 'Liabilities', 'Goodwill'],
'Amount': [total_fv_assets, total_fv_liabs, goodwill]
})
fig1 = px.pie(ppa_data, values='Amount', names='Category', title="PPA Allocation Breakdown")
st.plotly_chart(fig1, use_container_width=True)
with row1_col2:
# Earn-out History Line
fig2 = px.line(earnout_df, x='Date', y='Fair Value', title="Earn-out Fair Value Over Time")
fig2.add_hline(y=earnout_initial_fv, line_dash="dash", annotation_text="Initial FV")
st.plotly_chart(fig2, use_container_width=True)
# Changes Bar Chart
fig3 = px.bar(changes_df, x='Item', y='Adjustment Amount', color='Within Meas. Period?',
title="Adjustments Log", color_discrete_map={True: 'blue', False: 'red'})
st.plotly_chart(fig3, use_container_width=True)
with tab5:
st.markdown('<h2 class="sub-header">Export Data</h2>', unsafe_allow_html=True)
# Compile all data into Excel
output = io.BytesIO()
with pd.ExcelWriter(output, engine='openpyxl') as writer:
assets_df.to_excel(writer, sheet_name='Assets', index=False)
liabs_df.to_excel(writer, sheet_name='Liabilities', index=False)
pd.DataFrame({
'Total Consideration': [total_consideration],
'Total FV Assets': [total_fv_assets],
'Total FV Liabs': [total_fv_liabs],
'Net Identifiable': [net_identifiable],
'Goodwill': [goodwill]
}).to_excel(writer, sheet_name='PPA_Summary', index=False)
earnout_df.to_excel(writer, sheet_name='Earnouts', index=False)
changes_df.to_excel(writer, sheet_name='Changes', index=False)
st.download_button(
label="📥 Download Excel Tracker",
data=output.getvalue(),
file_name=f"{company_name}_PPA_Tracker_{datetime.now().strftime('%Y%m%d')}.xlsx",
mime="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
)
# Footer
st.markdown("---")
st.markdown("*Built by Sherlock (Trailblazer Labs). Supports US GAAP/IFRS PPA rules. Consult accounting standards for specifics.*")
🚀 How to Use This Tracker
-
Run the App: Copy-paste this code into a file ppa_tracker.py, then run streamlit run ppa_tracker.py (install deps: pip install streamlit pandas numpy plotly openpyxl).
-
Key Features:
- PPA Allocation: Edit assets/liabilities fair values. Auto-calculates goodwill.
- Earn-outs: Track fair value changes over time (remeasurements hit P&L post-acquisition).
- Changes Log: Log adjustments. Measurement period ones adjust goodwill retrospectively; others hit P&L.
- Dashboard: Visuals + KPIs.
- Export: Full Excel workbook.
-
Accounting Logic:
- Initial: Consideration = Cash + Equity + Earn-out FV.
- Measurement Period (e.g., 12 months): Provisional → Final adjustments change goodwill (no P&L).
- Post-Period: Earn-out FV changes → P&L; other FV changes → Prospective/P&L.
This is production-ready—customize categories, add DCF for earn-outs, or integrate with your ERP! 🔍