-
Notifications
You must be signed in to change notification settings - Fork 0
/
stockincome.py
executable file
·93 lines (75 loc) · 3.06 KB
/
stockincome.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/python
"""Find employment income from Google shares in various countries.
Attempts to calculate employment income from GSUs and options based on
residence, business trips, and foreign exchange rates.
USE AT YOUR OWN RISK.
GET TAX ADVICE FROM SOMEONE WHO ACTUALLY KNOWS WHAT THEY'RE DOING.
"""
import argparse
import datetime
import sys
import currencyconverter
import stocktable
import taxcalendar
__version__ = "0.2"
# Figure out what year it is so we can set flag defaults.
thisyear = datetime.date.today().year
defaultyear = thisyear - 1
flags = argparse.ArgumentParser(
description=__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
flags.add_argument("--calendar", type=str,
default="calendar.csv",
help="CSV file listing residence and business trips")
flags.add_argument("--grants", type=str,
default="grants.csv",
help="CSV file with GSU and option stock grants")
flags.add_argument("--check_percentages", type=int,
default=0,
help="Check US / US_CA percentages against Google numbers")
flags.add_argument("--year", type=int, default=defaultyear, help="Tax year")
flags.add_argument("--fx", type=str,
default=None,
help="CSV file with exchange rates, default murc_<year>.csv")
FLAGS = flags.parse_args(sys.argv[1:])
def main():
converter = currencyconverter.MURCCurrencyConverter(FLAGS.year, FLAGS.fx)
print "Read exchange rate data."
calendar = taxcalendar.TaxCalendar.ReadFromCSV(FLAGS.calendar)
print "Read location data."
for year in calendar.GetYears():
locations = calendar.FindLocationsForYear(year)
print " %s: %s" % (year, str(dict(locations)))
grant_data = stocktable.GrantTable.ReadFromCSV(FLAGS.grants)
print
print "Read grant data."
sales = stocktable.StockTable.ReadFromCSV(FLAGS.year, grant_data,
converter, calendar)
all_countries = set()
for table in sales.values():
table.SetCheckPercentages(int(FLAGS.check_percentages))
all_countries.update(table.GetAllCountries())
print
print "Read stock data."
print " Sections:", sales.keys()
print " Countries:", all_countries
print
# GSUS = sales["GSUS"]
# assert 0.00 == GSUS.GetCountryPercentage(GSUS["A10751504"]["US"], "US")
print "Country totals:"
for section, table in sales.iteritems():
column = table.FindTotalColumn()
print " %s" % section
for country in all_countries:
print " %5s: %12s" % (country, table.GetCountryTotal(country,
column))
print " Worldwide: %12s" % table.GetWorldwideTotal()
print
for country in all_countries:
for section, table in sales.iteritems():
report = table.GenerateCountryReport(country)
filename = "stockincome.%s.%s.html" % (section, country)
open(filename, "w").write(report)
print "Wrote report on %s for %s to %s" % (section, country, filename)
if "__name__" == "__main__":
main()