STF Stamp Duty
Calculate stamp duty in batches
As at 20th June 2018, the Stamp Duty on share consideration is 0.5% rounded up to the nearest £5.00, for consideration which is more than £1,000.
We need to take a list of numbers, and write a formula to spit out the numbers. Instead of creating two text files, let's dip into the 'csv' data type.
Csv files can be opened with a text editor but are best used with spreadsheet software such as Excel or Libreoffice Calc.
Tasklist
Convert the spreadsheet to a csv file.
Write a script that reads the file into our script.
1. Convert the spreadsheet into a csv.
Like most things, this can be done in Python. Heck, you can read and write straight to the spreadsheet in Python. However for simplicity, we will just use the graphical interface. Using a csv (which stands for comma separated values) has the advantage of learning how to work with csv, a common and wonderfully simple data format.
Open up a new file in your spreadsheet software. What we're making is just a table of plain numbers and letters starting from the top left cell (A1). Lose any merged cells and other fanciness if you didn't start from a blank file.
In a csv file, the top row is where you put the headings, and the rows beneath correspond to each row of information. Csv files split each value with a comma (hence comma separated values), and in the background your spreadsheet software splits the row into the next cell when it reaches a comma to present it as a nice table without showing you the commas. If you opened it in a text editor, you would see the commas! This data style can sometimes result in funky things if there are commas in your values which are not meant to delineate the end of that value, but this can be avoided by using a value other than a comma as the delineator, or wrapping the values in "quotes".
Since we are calculating stamp duty, let's add two columns of data. In the top left cell (A1) write 'consideration', and in the second write 'duty'. I hope you see where I'm going with this.
Enter your consideration values by typing or copy-pasting them into the 'consideration' column (A). Remember, one value per cell! Because you are using spreadsheet software you don't need to add the commas, but if you used a text editor you would add the commas.
Leave the corresponding 'duty' column blank for now, as our script will calculate it and write it in.
To save your file, simply save in the normal way, and name the file ending in '.csv'. You may have to delete any default filename like "untitled.xls". We'll call ours 'stampduty.csv'. You may also have to manually select the file type in a dropdown menu which will be next to the save button.
Your spreadsheet file might give you a warning about features not being supported in csv. Since our file needs no fancy features, we can ignore this warning. We now have our csv file saved and ready to go!
Open up the csv file in your spreadsheet software, and make sure nothing gory has happened in the conversion process.
2. Write a script
Now that you have confirmed the numbers have stayed intact, let's write our script. Create a new python file in the same folder as 'stampduty.csv'. Call it whatever you want - go crazy. Actually don't call 'python.py', 'setup.py' or 'test.py', as when python runs on your computer it sometimes makes use of files called by these names.
In the python file, enter the following script:
Now re-open your csv file to see the calculated stamp duty!
You may also have seen the program spits out the answers as it goes too - this is not necessary but it's nice to check if things are going well.