Skip to content

Instantly share code, notes, and snippets.

@misterhay
Created October 16, 2019 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save misterhay/01439dc9ba8e273872ce61fe231a3e5f to your computer and use it in GitHub Desktop.
Save misterhay/01439dc9ba8e273872ce61fe231a3e5f to your computer and use it in GitHub Desktop.
Construct a graph of net income (Alberta) versus hourly wage
def calculateFederalTax(income):
taxBrackets = [47630, 95259, 147667, 210371]
taxRates = [.15, .205, .26, .29, .33]
taxes = []
for i in range(0, len(taxBrackets)):
taxes.append(taxBrackets[i] * taxRates[i])
if income < taxBrackets[0]:
tax = income * taxRates[0]
elif income < taxBrackets[1]:
tax = taxes[0] + (income - taxBrackets[0]) * taxRates[1]
elif income < taxBrackets[2]:
tax = taxes[1] + (income - taxBrackets[1]) * taxRates[2]
elif income < taxBrackets[3]:
tax = taxes[2] + (income - taxBrackets[2]) * taxRates[3]
else:
tax = taxes[3] + (income - taxBrackets[3]) * taxRates[4]
return tax
def calculateProvincialTax(income):
taxBrackets = [131220, 157464, 209952, 314928] # for Alberta
taxRates = [.1, .12, .13, .14, .15]
taxes = []
for i in range(0, len(taxBrackets)):
taxes.append(taxBrackets[i] * taxRates[i])
if income < taxBrackets[0]:
tax = income * taxRates[0]
elif income < taxBrackets[1]:
tax = taxes[0] + (income - taxBrackets[0]) * taxRates[1]
elif income < taxBrackets[2]:
tax = taxes[1] + (income - taxBrackets[1]) * taxRates[2]
elif income < taxBrackets[3]:
tax = taxes[2] + (income - taxBrackets[2]) * taxRates[3]
else:
tax = taxes[3] + (income - taxBrackets[3]) * taxRates[4]
return tax
def calculateEI(income):
eiMaxInsurableEarnings = 53100
eiRate = 0.0162
if income >= eiMaxInsurableEarnings:
eiPremium = eiMaxInsurableEarnings * eiRate
else:
eiPremium = income * eiRate
return eiPremium
def calculateCPP(income):
cppMaxContributoryEarnings = 53900
cppRate = 0.051
if income >= cppMaxContributoryEarnings:
cppPremium = cppMaxContributoryEarnings * cppRate
else:
cppPremium = income * cppRate
return cppPremium
wages = []
grossIncomes = []
netIncomes = []
for wage in range(15, 150):
wages.append(wage)
grossAnnualIncome = wage * 8 * 240
grossIncomes.append(grossAnnualIncome)
incomeTax = calculateFederalTax(grossAnnualIncome) + calculateProvincialTax(grossAnnualIncome)
eiPremium = calculateEI(grossAnnualIncome)
cppPremium = calculateCPP(grossAnnualIncome)
netIncome = grossAnnualIncome - (incomeTax + eiPremium + cppPremium)
netIncomes.append(netIncome)
import plotly.graph_objects as go
fig = go.Figure()
#fig.add_trace(go.Scatter(x=wages, y=grossIncomes, name='Gross Income'))
fig.add_trace(go.Scatter(x=wages, y=netIncomes, name='Net Income'))
fig.update_layout(
title=go.layout.Title(text='Net Income vs Hourly Wage'),
xaxis=go.layout.XAxis(title=go.layout.xaxis.Title(text='Hourly Wage')),
yaxis=go.layout.YAxis(title=go.layout.yaxis.Title(text='Income')))
fig.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment