Last active
November 8, 2017 10:58
-
-
Save blippy/fb8c6983c78d1707cde547de29c9fd82 to your computer and use it in GitHub Desktop.
Stockopedia portfolio constructor
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
| #!/usr/bin/env awk | |
| BEGIN { | |
| IFS="\t" ; OFS = ","; | |
| print "TICKER,DATE,TIME,TYPE,SHARES,FX,PRICE,CURRENCY,COMMISSION,TAX,TOTAL"; | |
| } | |
| { | |
| #print ""; | |
| #print $0; | |
| dstamp = substr($1, 9, 2) "/" substr($1, 6, 2) "/" substr($1, 1, 4) | |
| consid = $5 | |
| if($3=="B") { | |
| sconsid = consid; | |
| typa = "Buy" | |
| typb = "Deposit" | |
| } else { | |
| sconsid = -consid | |
| typa = "Sell"; | |
| typb = "Withdrawal"; | |
| } | |
| qty = $4; | |
| price = consid * 100 / qty; | |
| print $2, dstamp, "10:10:10", typa, qty, 1, price, "GBX", 0 , "", sconsid | |
| print "", dstamp, "10:10:10", typb, "", "", "" , "" , "", "", sconsid | |
| } | |
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
| 2017-01-01 LON:VOD B 100 199.98 | |
| 2017-02-20 LON:BP. B 200 1027.00 | |
| 2017-05-30 LON:VOD S 15 34.73 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
stocko.awktakes as input lines consisting of the following fields, separated by tabs:You can add further tab-separated fields, as they will be ignored.
Example usage:
awk -f stocko.awk <xample-stocko.txt >xample-stock.csvImport the generated CSV file into Stockopedia: