When negotiating job offers or evaluating compensation packages, one common headache employees face is calculating their exact net cashflow. In Sri Lanka, macroeconomic reforms and progressive personal income tax (APIT) brackets often lead to misunderstandings—with many professionals mistakenly assuming their entire earnings are taxed at the highest marginal rate.
To solve this everyday financial challenge, I engineered an interactive web simulator using Python, Streamlit, and Plotly, calibrated with the official Inland Revenue Department (IRD) tax tables.
Live Application & Source Code
- Live Web App: https://sri-lanka-salary-tax-simulator.streamlit.app
- GitHub Repository: https://github.com/rasindupramith-oss/sri-lanka-salary-tax-simulator
1. The Mathematical Engine: Progressive Tax Slabs
Under current Sri Lankan tax legislation (effective for Year of Assessment 2025/2026 onwards), the first Rs. 150,000 per month (Rs. 1.8M per year) is 100% tax-free personal relief.
Earnings above this threshold are taxed progressively across structured tiers:
- Next Rs. 83,333.33 at 6%
- Next Rs. 41,666.67 at 18%
- Next Rs. 41,666.67 at 24%
- Next Rs. 41,666.67 at 30%
- Balance above Rs. 358,333.33 at 36%
Additionally, statutory retirement funds are modeled accurately:
- Employee EPF (8%): Deducted from basic pay.
- Employer EPF (12%) + ETF (3%): Paid by the company on top of gross salary.
2. Core Python Implementation
Here is the core logic calculating the progressive tax slabs:
def calculate_apit_tax(gross_salary):
tax = 0.0
if gross_salary > 150000:
excess = gross_salary - 150000
# Tier 1: Next 83,333.33 at 6%
slab1 = min(excess, 83333.33)
tax += slab1 * 0.06
excess -= slab1
# Subsequent progressive tiers (18%, 24%, 30%, 36%)
rates = [0.18, 0.24, 0.30]
for rate in rates:
if excess > 0:
slab = min(excess, 41666.67)
tax += slab * rate
excess -= slab
if excess > 0:
tax += excess * 0.36
return tax
3. Visualizing Cashflow with Plotly Waterfall Charts
Rather than displaying flat numbers, I used Plotly Graph Objects to render an interactive Waterfall Chart mapping the journey from Gross Salary down to final In-Pocket Cash:
import plotly.graph_objects as go
fig_waterfall = go.Figure(go.Waterfall(
name="Salary Flow",
orientation="v",
measure=["absolute", "relative", "relative", "relative", "total"],
x=["Gross Salary", "Employee EPF (8%)", "APIT Tax", "Other Deductions", "Net Take-Home"],
textposition="outside",
y=[gross_salary, -employee_epf, -tax, -other_deductions, 0],
decreasing={"marker": {"color": "#ef4444"}},
totals={"marker": {"color": "#0ea5e9"}}
))
4. Key Takeaways from the Data
- The Marginal Tax Reality: On a typical gross salary of Rs. 240,000, the effective tax rate is only 2.6% (Rs. 6,200), completely debunking the fear of double-digit percentage losses.
- Hidden Retirement Compounding: While 8% employee EPF is deducted, the 15% employer contribution (EPF+ETF) quietly adds over Rs. 46,000 monthly in wealth accumulation into central bank accounts.
Feel free to test out the live simulator and share your feedback!
Author: Rasindu Pramith — Undergraduate in Applied Statistics, Faculty of Science, University of Colombo
Connect on LinkedIn: https://www.linkedin.com/in/rasindu-pramith
Portfolio Website: https://rasindupramith-oss.github.io
Top comments (0)