Skip to content

Instantly share code, notes, and snippets.

@blippy
Last active November 8, 2017 10:58
Show Gist options
  • Select an option

  • Save blippy/fb8c6983c78d1707cde547de29c9fd82 to your computer and use it in GitHub Desktop.

Select an option

Save blippy/fb8c6983c78d1707cde547de29c9fd82 to your computer and use it in GitHub Desktop.
Stockopedia portfolio constructor
#!/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
}
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
@blippy

blippy commented Nov 8, 2017

Copy link
Copy Markdown
Author

stocko.awk takes as input lines consisting of the following fields, separated by tabs:

1. DATE - of form YYYY-MM-DD
2. TICKER - the symbol for the stock, with exchange. e.g. Vodafone has the ticker LON:VOD
3. TYPE - use B for a buy, and S for a sell
4. QUANTITY - number of shares bought/sold
5. CONSIDERATION - the (total) amount paid or received for the shares

You can add further tab-separated fields, as they will be ignored.

Example usage:
awk -f stocko.awk <xample-stocko.txt >xample-stock.csv

Import the generated CSV file into Stockopedia:

  1. In menu "Folios", select the item "Create Folio"
  2. Click button "Import Folio"
  3. Click tab "Excel"
  4. Click the Browse button next to "Select the CSV file"
  5. Select the CSV file that you generated
  6. Click "Import to Stockopedia"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment