Warning: Declaration of ElementorPro\Modules\Posts\Skins\Skin_Content_Base::register_controls(Elementor\Widget_Base $widget) should be compatible with Elementor\Controls_Stack::register_controls() in /home/customer/www/backtest-rookies.com/public_html/wp-content/plugins/elementor-pro/modules/theme-builder/widgets/post-content.php on line 17
If you trade equities, dividends are a huge part of the game. However, their impact is often overlooked in backtesting. This can lead you to ditch profitable strategies and incorrectly estimate the expected returns of a strategy. In this article, we will take a look at dividends, how to account for them and how they can affect the overall returns of your strategy.As we can see the difference is stark. Nearly, double the returns when dividends are factored in.
Dividend PrimerDividends are payments made from a company to its shareholders. More often than not, a dividend is a payment of a portion of a companies’ the net profits. However, sometimes shares are provided instead of cash. The amount and type of dividend given is decided by the companies board members at their discretion. This means that a company may issue dividends one year and not the next. In fact, it is common for companies to focus on growth and not pay dividends out at all. Instead, they return value to the shareholder through the growth of the company and share price. When distributed, dividends have several implications for both your backtest test setup. This is because stock prices are adjusted (downwards) on the day that a stock goes ex-dividend. Why are they adjusted downwards? Because the money is no longer owned by the company and as such, the company is now a little less valuable than it was before. The percentage that the price is adjusted by is sometimes referred to as the “dividend impact”. On a price, chart we can sometimes see this impact. It can look like the stock dropped in price and you lost some equity. However, in reality, you didn’t because you are now going to receive some cash to offset that drop in price. The problem relating to backtesting is that we need to be aware of this and handle it accordingly. Otherwise, our results can be skewed to the downside. For example:
- Assume we have $100 in cash and 0 shares.
- We then buy a stock for $100. Now we have $100 dollars of shares and $0 cash.
- That stock then pays a $5 dividend and the price is adjusted. Now we have $95 dollars in shares and $5 in cash
- Our total equity is still $100 ($95 + $5).
- However, if you were just passing pure price data to a backtest engine, it would just see that your asset has dropped in price. So now you have a 5% loss / drawdown.
Re-InvestmentSpeaking of re-investment, adjusting the prices following a dividend also helps to simulate dividend re-investment. Investors often choose to re-invest their dividends in order to compound gains over time. This again can have a huge affect on the long term outcome of a portfolio. An interesting piece of research from Schroders highlights the impact of dividend re-investment on an investors returns:
If you had invested $1,000 on 01 January 1993 in the MSCI World, the capital growth would have produced a notional return of $3,231 (by 7 March 2018). Annually, that represents a growth rate of 5.9%. But the picture changes again once dividends, the regular payments made by companies to their shareholders, and the miracle effects of “compounding” are included. By reinvesting all dividends, the same $1,000 investment in the MSCI World would have produced a notional return of $6,416, representing annualised growth of 8.3%. In percentage terms, it’s the difference between your money growing by 323%, without dividends reinvested, or 640% with dividends reinvested, nearly twice as much.Source: https://www.schroders.com/en/insights/economics/how-reinvesting-dividends-has-affected-returns-over-25-years/ So not only do we have to account for the cash, ideally, we also want to capture some of the expected returns from dividend re-investment.
Re-Adjusting PriceA lot of data providers provide “adjusted” prices. Alpha Vantage is one of them. If you have ever downloaded price data and asked yourself whether you should use “close” prices or the “adjusted close” price, then this article is for you. Adjusted close prices don’t just solve the problem of dividends, they also take into account other corporate actions that might have had a negative price impact but no real impact to the investor. One example of this is a stock split, where price halves but each investor receives 2 shares for 1. In this case, the investor has the same value of shares as before. Quandl has a great article which dives deep into the mechanics and formulas for readjusting data. The article also contains a striking comparison of adjusted and non adjusted data that really highlight the difference:
PlatformsThis section provides brief guides and suggestions to working with dividends on each of the main platforms covered on this site.
TradingviewTradingview has an option to adjust prices for dividends. However, it is disabled by default! So if you are backtesting, you really need to be aware of this option. To give an idea of the difference take the following example code and place is on LSE:LLOY. You will see a striking difference in the PnL reported after holding the stock for 1 year through two dividends.
//@version=3 strategy("Price Adjustment Testing", overlay=false, default_qty_type=strategy.percent_of_equity, default_qty_value=100) FromMonth = input(defval = 12, title = "From Month", minval = 1, maxval = 12) FromDay = input(defval = 31, title = "From Day", minval = 1, maxval = 31) FromYear = input(defval = 2016, title = "From Year") ToMonth = input(defval = 12, title = "To Month", minval = 1, maxval = 12) ToDay = input(defval = 31, title = "To Day", minval = 1, maxval = 31) ToYear = input(defval = 2017, title = "To Year") start = timestamp(FromYear, FromMonth, FromDay, 00, 00) // backtest start window finish = timestamp(ToYear, ToMonth, ToDay, 23, 59) // backtest finish window window = time >= start and time <= finish ? true : false // create function "within window of time" longCondition = window if (longCondition) strategy.entry("Long", strategy.long) closeCondition = not window if (closeCondition) strategy.close("Long")Once run on the chart you should differences in the PnL like this:
BacktraderBacktrader is very much a do it yourself platform. It is the most flexible of the platforms covered but this flexibility comes with responsibility. Backtrader will just process anything you give it. If you give it unadjusted prices, that is what will be calculated. As such, we need to get our hands on adjusted data ourselves. After you have the it, all we need to do is load it like any other data. Alpha Vantage do provide adjusted
closedata. However, they do not adjust the
lowdata. As such, this data source should only be used with
closeprices or you should re-adjust the
lowyourself using the same factor as the
closeadjustment. A code snippet and tutorial on how to do this is available here: https://backtest-rookies.com/2018/10/19/backtrader-manage-dividends-and-splits-with-adjusted-close-data/
QuantConnectQuanConnect offers the most data and options out of the box. As such, a dedicated dividends article focused soley on QuanConnect is also planned in the future. In short though, we can choose to work with unadjusted data and receive the dividend as cash. After that, it is up to you to decide whether to re-invest or hold it. The alternative is to adjust prices and not receive cash. We do this by settings a
DataNormalizationModeduring init. For those that cannot wait for the article, check out the following links for more information: Docs: https://www.quantconnect.com/docs/algorithm-reference/handling-data Forums: https://www.quantconnect.com/forum/discussion/508/update-dividends-splits-and-custom-price-normalization/p1
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.