Created
May 11, 2014 12:35
-
-
Save ereli/d3936691c49345131f7a to your computer and use it in GitHub Desktop.
ofx-to-csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 10/5/2014 | |
# so if you're using google finance and wanted to export your porfolio, including your transactions to a CSV format -> here is a script that lets you do that. | |
# you can also print the current portflio - located on ofx.security_list | |
# inspired by https://github.com/chrisroos/ofx-to-csv | |
from ofxparse import OfxParser | |
import csv | |
ofx = OfxParser.parse(file('portfo.ofx')) | |
with open('output.csv', 'wb') as csvfile: | |
csvoutput = csv.writer(csvfile, delimiter=',',quotechar='"', quoting=csv.QUOTE_MINIMAL) | |
csvoutput.writerow(['BuyMF', 'BuyStock', 'Reinvest', 'SellMF', 'SellStock', 'Unknown', 'id', 'memo', 'security', 'settleDate', 'tradeDate', 'type', 'unit_price', 'units', 'x']) | |
for i in range(len(ofx.account.statement.transactions)): | |
csvoutput.writerow([ofx.account.statement.transactions[i].BuyMF, ofx.account.statement.transactions[i].BuyStock, ofx.account.statement.transactions[i].Reinvest, ofx.account.statement.transactions[i].SellMF, ofx.account.statement.transactions[i].SellStock, ofx.account.statement.transactions[i].Unknown, ofx.account.statement.transactions[i].id, ofx.account.statement.transactions[i].memo, ofx.account.statement.transactions[i].security, ofx.account.statement.transactions[i].settleDate, ofx.account.statement.transactions[i].tradeDate, ofx.account.statement.transactions[i].type, ofx.account.statement.transactions[i].unit_price, ofx.account.statement.transactions[i].units, ofx.account.statement.transactions[i].x]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment