Sourcecode You can also read another version of this post that also has all the R code I used for analysis and generating plots.
I came across a time series analysis of German Market in the light of federal elections and decided to try the same for BSE SENSEX(Bombay Stock Exchange Sensitive Index) and Indian Lok Sabha Elections. Sensex is a stock market index of 30 companies listed at Dalal Street, Mumbai(Bombay).
I downloaded the dataset from BSEIndia.com. I believe this should also be available on Quandl.
Lok Sabha Election Dates
The election date I chose is the date of counting of votes. When I couldn’t find that date, I picked the dates when the next Lok Sabha started. There’s usually a gap of couple of days when the last Lok Sabha is dissolved and new Lok Sabha sworns in.
elections <- as.Date(c("1980-01-18", "1984-12-31", "1989-12-02", "1991-06-20", "1996-03-10", "1998-03-10", "1999-10-06", "2004-05-13", "2009-05-16", "2014-05-16"), format = "%Y-%m-%d")
Here I also calculate something called rolling variance. Rolling variance can be also called moving variance. It is variance calculated on overlapping windows of time. Example, if window width is fixed at 10 then variance will be calculated on time values from 1-10 then 2-11 then 3-12 then 4-13.
I’m not completely convinced by using rolling variance as a measure of volatility so I will also explore other quantities.
I see two things here,
- Sensex has become volatile over time.
- There is a slight hint that market is effected by the results, but it can only be seen in 2004, 2009 and 2014 elections.
Sensex volatality(in terms of rolling variance) 100 days before and after the election results.
I see a sign that markets have started becoming nervous around the elections and that volatality has increased.
Need for Normalization
There’s still a problem here. Some large values in rolling variance are making it harder to see the complete picture. We need a measure that normalizes the data. Daily differences when measured in percentages might prove to be a good candidate here. They’re generally called returns.
Return on i day ri is calculated as,
where pi is the price on day i
This is a complete mess! I cannot infer anything from daily values. This calls for aggregation!
If this also shows the variations then it would imply that the elections effect market for more than a day or two.
There’s a clear linear trend visible. This is an example of a non-stationary time-series. We can detrend it to make it stationary, in other words make it horizontal.
To detrend a time series, remove the upward linear trend from the series without effecting it’s shape at all. Or subtract the linear trend from the time series.
Linear model or linear trend is essentially a line that best explains the series. For each point on x-axis, there’s a point on y-axis corresponding to the line. These set of points on y-axis are called fitted values. To detrend, I just need to subtract the data from the fitted values for the whole x-axis.
yi − (β1xi+β2)
β1 and β2 are parameters from the linear model. This difference is called residuals in regression theory.
- Make a linear model with variables on y and x axis.
- Plot the residuals
I should plot the returns to see the effect more pronounced
Whoa a 20% crash in 2008!
I need to look in the daily charts for this,
I’m thinking mean change(in percent) for the month might be better able to represent the volatility through the month.
2008 was a rough year for markets worldwide with the global financial crisis. The 10% fall visible in October is the largest crash ever from BSE Sensex. Let’s check how other years compare to this.
Look at the 5th month! The results came out on 16th May, 2004 and clearly the market was more nervous than anytime in the year! If I’m not wrong, I should see a similar trend in the year 2009.
Trivia: Stable governments imply date of elections do not change. Results for general elections have been coming out exactly around 3rd week of May every 5 years in 21st century.
I can set the y-axis scale free to adjust itself for the values in each facet but that wouldn’t emphasize the difference between May and other months.
“Investors rejoiced the coming of a stable government in power. Bulls got encouraged as investors were screaming to buy in apprehension that stability will come in the economic policies,” brokerage firm Unicorn Financial CEO G Nagpal said.
There’s a clear spike of massive 15%. Market looks like in indifference till the results are announced followed by a sigh of relief. Markets like political stabiity. 2009 elections meant 5 more years of nearly the same economic policy. 
Back to the election spike, Is this statistically significant? Is that even a right question to ask?
I’m exciting to see how does Narendra Modi’s election look like. If I remember correctly Congress never even looked like they had a chance. There was some nervousness about a messy coalition government involving the 3rd front but market would have loved as one party got the required majority to make the government.
Look at the 5th panel, this is interesting! I was completely wrong! There’s no sign of nervousness for the chance of a coalition government, which is odd.
Financial analysts love log-returns. Paul Teetor mentions in R Cookbook that volatility is measured as the standard deviation of daily log-returns.
This makes log-returns relevant to the subject of this post. In my quest to find “How does Lok Sabha Election effect Sensex”, I’ve failed to find a direct correlation between the two. Using log-returns I can check if it makes the market volatile or, in a way, nervous.
Let’s plot a couple of graphs to see where do they take us.
I need a grid to see the volatility around elections!
This looks like the conclusive graph I was looking for. Sensex was nervous when an economist became the prime minister. Hah!
So, do the Lok Sabha elections make Sensex nervous?
Well, we can only see volatality in 2004 and 2009. There’s a kind of plain indifference that is widespread elsewhere. I’m not sure what to take away from this. Other than that it’s a remarkably complex interaction which we shouldn’t have hoped to find a simple answer to.
Addressing the real oddity in the room,
Why was market so indifferent to general elections before 2000? (and even 2014)
One simple explanation is that market doesn’t care about elections at all and 2004, 2009 were plain coincidences.
Another explanation might be that indifference is a negative reaction. I’m probably missing something substantial as 1991 was a crucial year for Indian Economy but the market charts don’t show that at all!
Grid of charts,
When I switch to daily variations,
This isn’t all that helpful. There’s something important that’s still missing. We need insights!
Other Analysis Methods I Missed
Changepoint algorithms find abrupt variations in the series. 
I can also add changepoints to this mix,
Add the segments, and a vertical blue line to show election
I just learnt that base R supports a time series class that can be
ts(). It has some cool functions, one being
decompose. Decomposition of BSE Sensex values since 2000
There’s something called intervention analysis that was referred by a lot of people in this question at Research Gate. Someone there also mentions introducing dummy variables which I also didn’t understood.
This post was my attempt to learn more about analysis of data and time series. Please let me know your thoughts and if I missed something!
- That makes me think how much difference is really there in the financial policies of UPA and NDA governments, is it possible to measure?
- changepoint: An R Package for Changepoint Analysis, Rebecca Killick and Idris A. Eckley, 2013