Skip to content

Instantly share code, notes, and snippets.

@tommycarstensen
Created August 16, 2018 21:44
Show Gist options
  • Save tommycarstensen/acf871456137ffe4fb5500ef07025cc7 to your computer and use it in GitHub Desktop.
Save tommycarstensen/acf871456137ffe4fb5500ef07025cc7 to your computer and use it in GitHub Desktop.
import random
import matplotlib.pyplot as plt
var = 0.10
colors = ('#a6cee3', '#1f78b4', '#b2df8a', '#33a02c')
##for iColor, (tax1, tax2) in enumerate(((0.42, 0), (0.27, 0), (0, 0.42), (0, 0.27))):
for tax1, tax2 in ((0.42, 0),):
## for rate in (0.08,):
for iColor, rate in enumerate((0.04, 0.08, 0.12, 0.16)):
## for iColor, years in enumerate((10, 20, 30, 40)):
for years in (30,):
x = []
for i in range(100000):
v0 = v = 100000
for year in range(years):
v *= 1 + ((rate - var + 2 * var * random.random()) * (1 - tax1))
## print(i, year, v)
print(v, (v - v0), (v - v0) * (1 - tax2))
v -= (v - v0) * tax2
print(v)
## print(tax1, tax2, rate, i, v)
x.append(v)
plt.hist(
x, bins=100, alpha=.5,
color = colors[iColor % 4],
label='Tax {}%/{}%, Compounding {}%, Years {}'.format(
100*tax1, 100*tax2, 100*rate, years),
)
plt.legend()
##plt.savefig('compounding_tax.png')
plt.savefig('compounding_rate.png')
##plt.savefig('compounding_years.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment