In [42]:
%matplotlib inline
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
class Plan:
def __init__(self): pass
p1 = Plan()
p1.family_deductible = 1200.00
p1.individual_deductible = 600.00
p1.family_oopmax = 3600.00
p1.individual_oopmax = 1800.00
p1.family_cost_monthly = 910.00
p1.hsa_contribution = 0.00
p1.coinsurance_rate = 0.2
p2 = Plan()
p2.family_deductible = 3000.00
p2.individual_deductible = 1500.00
p2.family_oopmax = 6000.00
p2.individual_oopmax = 3000.00
p2.family_cost_monthly = 480.00
p2.hsa_contribution = 900.00
p2.coinsurance_rate = 0.2
p3 = Plan()
p3.family_deductible = 4600.00
p3.individual_deductible = 2300.00
p3.family_oopmax = 9200.00
p3.individual_oopmax = 4600.00
p3.family_cost_monthly = 186.00
p3.hsa_contribution = 900.00
p3.coinsurance_rate = 0.2
In [43]:
# For the purposes of this estimation, we are assuming the deductible
# is always larger than the HSA contribution amount
def apply_deductible_and_hsa(cost, deductible, hsa):
cost_to_you = 0
cost_remaining = 0
# Apply HSA
deductible_minus_hsa = deductible - hsa
if cost <= hsa:
cost_to_you = 0
cost_remaining = 0
elif cost <= deductible:
cost_to_you = cost - hsa
cost_remaining = 0
elif cost > deductible:
cost_to_you = deductible_minus_hsa
cost_remaining = cost - deductible
return (cost_to_you, cost_remaining)
def apply_coinsurance(cost, coinsurance_rate):
return cost * coinsurance_rate
def apply_oopmax(cost, oopmax):
if cost >= oopmax:
return oopmax
else:
return cost
def setup_graph(title='', x_label='', y_label='', fig_size=None):
fig = plt.figure()
if fig_size != None:
fig.set_size_inches(fig_size[0], fig_size[1])
ax = fig.add_subplot(111)
ax.set_title(title)
ax.set_xlabel(x_label)
ax.set_ylabel(y_label)
In [44]:
def individual_cost(plan, gross_cost):
(cost_to_you, cost_remaining) = apply_deductible_and_hsa(gross_cost,
plan.individual_deductible,
plan.hsa_contribution)
cost_to_you += apply_coinsurance(cost_remaining, plan.coinsurance_rate)
cost_to_you = apply_oopmax(cost_to_you, plan.individual_oopmax)
# Apply yearly premiums - note that the out-of-pocket max doesn't include
# the premiums; thus, we apply them after applying out-of-pocket max.
cost_to_you += (plan.family_cost_monthly * 12)
return cost_to_you
def family_cost(plan, gross_cost):
(cost_to_you, cost_remaining) = apply_deductible_and_hsa(gross_cost,
plan.family_deductible,
plan.hsa_contribution)
cost_to_you += apply_coinsurance(cost_remaining, plan.coinsurance_rate)
cost_to_you = apply_oopmax(cost_to_you, plan.family_oopmax)
# Apply yearly premiums - note that the out-of-pocket max doesn't include
# the premiums; thus, we apply them after applying out-of-pocket max.
cost_to_you += (plan.family_cost_monthly * 12)
return cost_to_you
In [45]:
# Should be the monthly premium times 12 (to make up the yearly premium).
family_cost(p1, 0)
Out[45]:
In [46]:
p1.family_cost_monthly * 12
Out[46]:
In [47]:
family_cost(p2, 0)
Out[47]:
In [48]:
p2.family_cost_monthly * 12
Out[48]:
In [49]:
family_cost(p3, 0)
Out[49]:
In [50]:
p3.family_cost_monthly * 12
Out[50]:
In [51]:
# Should be monthly premium times 12
family_cost(p3, 500) == p3.family_cost_monthly * 12
Out[51]:
In [52]:
(p3.family_cost_monthly * 12) + \
(p3.family_deductible - p3.hsa_contribution) + \
(6000 - p3.family_deductible) * p3.coinsurance_rate
Out[52]:
In [53]:
family_cost(p3, 6000)
Out[53]:
In [54]:
# Calculate costs
gross_costs = range(0, 40000)
p1_costs = [family_cost(p1, cost) for cost in gross_costs]
p2_costs = [family_cost(p2, cost) for cost in gross_costs]
p3_costs = [family_cost(p3, cost) for cost in gross_costs]
# Do graph
setup_graph(title='Family costs', x_label='Gross cost', y_label='Cost to you', fig_size=(12,7))
ax = plt.subplot(1,1,1)
p1_graph, = ax.plot(gross_costs, p1_costs, label="Plan 1")
p2_graph, = ax.plot(gross_costs, p2_costs, label="Plan 2")
p3_graph, = ax.plot(gross_costs, p3_costs, label="Plan 3")
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles, labels)
plt.show()
In [55]:
# Calculate costs
gross_costs = range(0, 40000)
p1_costs = [individual_cost(p1, cost) for cost in gross_costs]
p2_costs = [individual_cost(p2, cost) for cost in gross_costs]
p3_costs = [individual_cost(p3, cost) for cost in gross_costs]
# Do graph
setup_graph(title='Individual costs', x_label='Gross cost', y_label='Cost to you', fig_size=(12,7))
ax = plt.subplot(1,1,1)
p1_graph, = ax.plot(gross_costs, p1_costs, label="Plan 1")
p2_graph, = ax.plot(gross_costs, p2_costs, label="Plan 2")
p3_graph, = ax.plot(gross_costs, p3_costs, label="Plan 3")
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles, labels)
plt.show()
In [56]:
from IPython.display import YouTubeVideo
YouTubeVideo('4F4qzPbcFiA')
Out[56]:
In [ ]: