Skip to content

Instantly share code, notes, and snippets.

@kmosher
Last active April 16, 2019 05:07
Show Gist options
  • Save kmosher/b1f54ee90fbe20ac1f552dfee22952cc to your computer and use it in GitHub Desktop.
Save kmosher/b1f54ee90fbe20ac1f552dfee22952cc to your computer and use it in GitHub Desktop.
Turns csv exports from etrade into sched D ready imports for TaxAct. This is of course provided with NO WARRANTY or guarantee that it is fit for any purpose. Use at your own risk
#!/usr/bin/env python
import csv
import sys
from pprint import pprint
with open(sys.argv[1]) as infile:
with open(sys.argv[2], 'wb') as outfile:
reader = csv.DictReader(infile)
writer = csv.DictWriter(outfile, ['Description', 'Date Acquired', 'Sales Proceeds', 'Date Sold', 'Cost', 'Adjustment Code', 'Adjustment Amount', 'Reporting Category'])
writer.writeheader()
for row in reader:
new_row = {}
if row['Record Type'] != 'Sell':
continue
short = row['Term'] == 'Short Term'
plan = row['Plan Type']
new_row['Description'] = "%s %s (%s)" % (row['Qty.'], row['Symbol'], plan)
new_row['Date Acquired'] = row['Date Acquired']
new_row['Date Sold'] = row['Date Sold']
new_row['Sales Proceeds'] = row['Total Proceeds'].strip()
cost = row['Acquisition Cost'].strip()
income = row['Ordinary Income Recognized'].strip()
if plan == 'ESPP':
new_row['Adjustment Code'] = 'B'
new_row['Cost'] = cost
new_row['Adjustment Amount'] = '-'+income
if short:
# transaction for which basis was reported
new_row['Reporting Category'] = 'A'
else:
new_row['Reporting Category'] = 'D'
if plan == 'RS':
new_row['Adjustment Code'] = 'B'
new_row['Cost'] = income
new_row['Adjustment Amount'] = '$0.00'
if short:
# transaction for which basis was NOT reported
new_row['Reporting Category'] = 'B'
else:
new_row['Reporting Category'] = 'E'
if plan == 'SO':
new_row['Cost'] = cost
if income != "$0.00":
new_row['Adjustment Code'] = 'B'
new_row['Adjustment Amount'] = '-'+income
if short:
# transaction for which basis was reported
new_row['Reporting Category'] = 'A'
else:
new_row['Reporting Category'] = 'D'
writer.writerow(new_row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment