Code Snippet: Stamp Duty Commission Scheme

If you are based in the UK or just have an interest in trading UK equities, one thing that you need to be aware of is the UK stamp duty when buying stocks and shares:

An excerpt from https://www.gov.uk/guidance/stamp-duty-reserve-tax-the-basic

You pay SDRT on paperless transactions when you buy:

  • shares in a UK company
  • shares in a foreign company with a share register in the UK
  • an option to buy shares
  • rights arising from shares already owned
  • an interest in shares, like an interest in the money made from selling them

The tax you need to pay is 0.5% on any equity on listed on the main market. Note that you do not have to pay stamp duty on AIM listed stocks at the time of writing.

Adding the stamp duty commission scheme to backtrader

Defining our own commission schemes in backtrader is possible and defined in the documentation. What makes stamp duty a little unique is that we need to apply the extra tax to purchases and not sales.

The code

As you will see in the code, we just need to simply check whether the size of the trade is above or below 0 in order to tell whether transaction is long or short (buy or a sell). Once we have this information we can alter the return value accordingly.

The stamp duty value and fixed transaction fee apply to my broker in the UK. That might not be the case for you, therefore they have been added as parameters so the default value can be changed when calling the class.

To add it to your script (using the default settings) simply do the following:

That is all there is to it!

Find This Post Useful?

If this post saved you time and effort, please consider support the site! There are many ways to support us and some won’t even cost you a penny. 

Backtest Rookies is a registered with Brave publisher!

Brave users can drop us a tip.

Alternatively, support us by switching to Brave using this referral link and we will receive some BAT! 


https://brave.com/bac691

Referral Link

Enjoying the content and thinking of subscribing to Tradingview? Support this site by clicking the referral link before you sign up! 

https://tradingview.go2cloud.org/SHpB


Donate with PayPal using any payment method you are comfortable with! 


3HxNVyh5729ieTfPnTybrtK7J7QxJD9gjD

0x9a2f88198224d59e5749bacfc23d79507da3d431

M8iUBnb8KamHR18gpgi2sSG7jopddFJi8S