The function takes in three arguments: (a) the counter symbol, (b) the start date, and (c) the end date.
The function consists of the following steps:
1). Use quantmod to import the historical data for a given counter into R, with the start date and the end date specified by the user.
2). Retain only the closing price for said counter
3). Use quantmod to download the dividend data, and their corresponding payout dates, into R. The start date and the end date are the same as that in step 1.
4). Sum up the dividends received across the time period.
5). For each day, divide the sum of dividends received by the closing price to produce the daily dividend yield.
6). Plot the data as a line graph using ggplot, where the x-axis and y-axis are date and daily dividend yield, respectively.
7). As a cautionary measure, produce a data frame of the data. If there is any error in the data manipulation/data presentation, I will be able to drill-down to the source of the error rapidly.
The good thing about writing your own functions is that you know what goes into it. Different firms adopt different fiscal years in their reporting. To simplify comparisons across counters, I defined total annual dividends in my function as the total amount received when the counter goes ex-dividend (because Yahoo Finance tracks the ex-dividend date, and not the payment date) during the calendar year. To better illustrate what I am saying, please refer to the visualization below.
Consider a company that ends their fiscal year in June. By right, annual dividends are computed based on total dividends paid out between Q3 2007 to Q2 2008. However, my function will only consider total dividends, for the same counter, based on the counter going ex-dividend between Q1 2008 to Q4 2008.
I'll reserve my thoughts to the end of the post.
Let's start with some STI constituents k?
Capitaland Mall Trust
Capitaland Commercial Trust
Hong Kong Land
Enough with STI constituents. Let's take a look at other equally interesting counters.
Frasers Commercial Trust
Fraser and Neave
AIMS AMP Capital Industrial REIT
Parkway Life REIT
Hong Leong Finance
Lippo Malls Trust
1). Thai Beverage yielded more than 100% during the GFC?!?!?!? Is that accurate? The raw data looks fine when I checked it though. However, according to SGX's Corporate Action section, the dividends paid during the 2008 calendar year was in thai baht while the stock price was in Singapore Dollars. Okay, that explains the supposed crazy results.
2). On the internet, I have encountered a particular type of hearsay stating that ST Engineering would yield 7% during recessions. Apparently, my chart does not corroborate that particular hearsay. When I created another chart (not shown above) for ST Engineering from 01 January 2009 to 31 December 2009, the maximum yield is still around 3.5%.
I initiated my position in ST Engineering on February 2016. According to other online yield trackers, I got into the counter at 5+% yield. When I tried to compute the yield at around February 2016 with my function, the result showed that I got the counter at around 3.60% yield.
I shall attribute this to the difference between calendar year and ST Engineering's fiscal year.
3). When I look at these yield charts, it clearly reminded me of my inexperience in the market. How was a particular company like in, let's say, 2007? What direction was the management taking then? What was their attitude towards cheap money? Name some major corporate actions that the company took. What could be gleaned from these actions, their pros and their cons? How are their competitors faring? What about the overall shape of the industry? Is there a structural decline in the industry? What were investors' sentiment back then? Obviously, I can't even provide a comprehensive enough answer to the questions I have set for myself.
Experience is built up through time spent as an investor, coupled with active reflection on the ins and outs of the market, their various industries, and the individual companies that make up those industries. At this juncture, I have but only 2.5 years' worth of experience in the market. Textbook-learning aside, I just have to progress, open my eyes wide, and breathe in the "feel" of the markets.