How Pandemics Impact Financial Markets

Take cues from the pandemics in the past and quantitatively analyze the impact on financial markets. Visualize and analyze the data in Python

Ishan Shah
Towards Data Science

--

We are under an uncertain environment which is also reflected in the financial markets. You would have many questions such as how COVID19 would impact financial markets, how much more will it fall, when it will end and how will it end. In this article, we will analyse and take cues from past pandemics to answer these questions and what we can expect in the future. This article is written along the lines of the webinar conducted by QuantInsti on this topic on 2 April 2020. The recording and the codes can be accessed from the below.

Before we start our deep dive into impact on the markets, below are the news which we are seeing all around us or are expected.

  • Business closures and manufacturing plant shutdowns
  • Job losses and an increase in the unemployment rate
  • Supply chain disruption
  • Shortages of daily essentials
  • Pressure on healthcare systems
  • Exponentially rising infection and death tolls
  • And many more……

You have seen that shops are closed and the manufacturing plants are shut down. No one is producing anything and they don’t have a salary to pay so they are laying off people and thus, unemployment has increased. There is a disruption in the supply chain, and people are hoarding daily essentials including toilet papers. This will result in shortages. The number of cases related to infections is rising which is causing tremendous pressure on healthcare systems. The developed markets are coping somewhat with this unprecedented situation, but the developing markets such as India will find it very difficult to manage pressure on the healthcare system.

Combined with these are steep falls in financial markets. In these circumstances, the question which might come to you is when can we expect some good news, when will markets recover and many more questions.

COVID19 Impact on Financial Markets

Risk velocity is elevated in today’s markets compared to 10 years ago. The social-media driven news cycle, the interconnectedness of global supply chains and a pricey stock market, make Wall Street more vulnerable to a black swan.

~ Seema Shah, chief strategist at Principal Global Investors

Let’s begin by assessing the current impact on the financial markets due to COVID19. I have used Python freely available APIs and code to create all the charts in this article. All these codes are available on GitHub.

If you are new to Python and haven’t used financial libraries such as NumPy and Pandas, then I would recommend you to brush up the concepts in the below free interactive course on Python for Trading.

Let me walk you through this piece of code which is used to plot the daily percentage change for the S&P 500.

The code is given below:

Plot daily percentage change of SP500

I have used pandas_datareader’s get_data_yahoo method to fetch the prices of S&P500.

The get_data_yahoo method takes two arguments, first is the ticker which is “^GPSC” for S&P 500 in Yahoo Finance, and the second is the date from which I want the data for. If you have checked, the first case of coronavirus was identified on 17th November. Therefore, I have used the same date.

When I run this code, I will get the dataset with six columns which are open, high, low, close, volume and adjusted close. Since we are interested in daily percentage change, I will calculate it by using pct_change() function of Python and it is called on the close column. For example, if the daily percentage change is changing from one hundred to hundred and two, then I will have a value of 0.02 in this data frame.

If you want to plot this series in Python, you simply have to pass the name of the series which in this case is “data_pc” and call the function plot and it will plot the data series. So this is how the daily return will look. Since it looks smaller, I have added a grid and done a few improvements to enhance its readability.

Daily Percentage Change

Apart from the S&P500, I have also plotted the graphs for crude oil, Gold and TLT, which is the 20 years Treasury in the US markets.

I have plotted the daily percentage change for each of them. To give some more detail to these graphs, the blue line is the date on which the first case was identified and the red line is the date on which WHO declared a public health emergency.

So we can see the volatility or the change in the price on a daily basis for S&P500 was very close to zero and we can see that a few days after the WHO declared emergency, there was a sharp change in its volatility. It is ranging from 5 to 10% in daily moments. Also, it is not just the S&P500 which is a barometer for the US market, but it can also be seen in crude oil, gold and our TLT, which is 20 years Treasury bonds of US market. Thus, we can easily conclude that Corona is making the financial markets jittery.

Another way to look at these graphs would be to say there are a lot of down movements but there are a lot of up movements also. Thus, how do I actually assess how the markets would move?

Cumulative Returns

For this, I have plotted the cumulative returns of the four cases. The start date is a few days before the first case was reported and the last day is 30 March.

As you can see the red line is for crude oil and it seems like it has been impacted the most. It’s a decline of almost 60% from the top. The blue line indicating the S&P 500 has also shown a sharp decline. But if you check gold, you would realise that the impact is not as significant as the S&P500 and Crude oil.

Does that mean we should include gold in our portfolio as a reasonable hedge in these uncertain times?

It seems like it but let us not jump to conclusions so fast. We will come back to it later. The last but not the least is the US treasury which saw a sharp decline but quickly recovered.

Drawdowns

Another way to look at this graph is the drawdown graph. In simple terms, drawdown measures the fall from the peak at any particular time period in time. Let’s see the graph now.

For example, in the S&P500 graph, there was a peak around February and then it fell close to 33%. The drawdown values for each are given below:

Maximum drawdowns
Crude Oil 67.07%
SP500 33.92%
Gold 11.80%
TLT 15.72%

Relationship of SP500 with Crude Oil, Gold and TLT

The drawdown helps us understand how much the asset class can fall but they are still different asset classes, right? How can we compare them, or in other words, what is the relationship between them?

To answer that we will create a scatter plot. A scatter plot helps us to understand the relationship between the instruments we have.

First, we will plot a scatter plot of the different instruments with respect to the S&P500. Let’s see how they look.

The red scatter plot is the S&P500 in relation to the TLT, which shows a negative relationship. We all know that in a moment of crisis, there is an economic slowdown and the Feds and other Govt. agencies step in and there is a reduction in the rate. Since there is an inverse relationship between the rates and price, the reduction in the rate results in an increase in price. Hence, we see this negative relationship between the S&P500 and the TLT. However, we have a few data points and hence a conclusion would be unwise here.

With gold, we see no relationship with the S&P500 as the data points are spread out in this plot. When it comes to Crude oil and S&P500, it seems that the faraway points are negatively correlated but the nearer points are positively correlated. Hence we cannot really conclude anything at this point.

This was one way to establish a relationship between the different instruments. Based on these relationships, we could create a portfolio which will work for us in the time of pandemics.

Sector Performance

So far we were talking about the S&P500 as a whole. But what about the individual sectors comprising the index?

One way to look at it is the sectoral performance. I have created a graph which takes into account the major sectors of the market.

One observation from this graph is that you can see Pharma and Technology are two sectors which are relatively less impacted. In the graph above, Technology is this orange line which you can see at the very top which is followed by Pharma as the blue line. Overall, you can see that all the sectors are in the same direction but the relative magnitude, or the fall, is different. As I stated earlier, Pharma and Technology are relatively less impacted.

You can see the pink line representing energy as the most impacted. This is logical considering we have seen earlier how crude oil was the most impacted, which in turn impacted the energy sector since they both are directly related. Another observation is the green line, which indicates financials, has also fallen. The reason for this is that whenever the economy slows down there are a lot of loan defaults which result in the rise of non-performing assets for a bank and eventually they will take a hit on their P&L. The rise in NPAs makes it really difficult for a bank to survive. One classic example of this in the Indian market is Yes bank. Thus, in this economic crisis, financial sectors are bearing the brunt.

Does this mean we should ignore financials and load up on, let’s say Technology and Pharma and what should my portfolio look like?

Along with this, we all have these questions as shown below:

  • When will it end?
  • How will it end?
  • Will markets fall more from here? And how it will move from here?
  • Should I buy Gold as safe haven? How should my portfolio look?
  • It is so contagious, will everyone be affected by it?
  • How the earnings will be impacted and which sector will be impacted the most?

Let’s try to answer these questions by looking at past pandemics and how the world fared. I would like to add a small disclaimer here that I do not have any crystal balls which will give me a 100% correct answer but I believe data is always the best way to come to a reasonably good conclusion. Let us begin now.

Past Pandemics

“Those who do not remember the past are condemned to repeat it.”

~ George Santayana

If you think that this is a special scenario, well, you will be surprised to know that pandemics have been affecting us since the past few centuries. I have compiled some data in a simple table which is shown below

Source: World Economic Forum

I have highlighted the top three pandemics according to the death toll in red and the bottom four in green.

There is one significant trend which is coming out here. Can you figure it out?

There are actually two trends which are emerging here. One is that there is a significant fall in the number of deaths over the years. Another trend is the period has also significantly reduced. The reason for these is an improved healthcare system which is available to us and also a lot of effort which goes in finding and deploying vaccinations to the general public.

But this was a look at the past. How is Coronavirus affecting the infection and death toll? Let’s quickly understand how contagious is the Corona Virus

Source: World Economic Forum

What is this infographic telling you?

It shows us how quickly the infection can spread. Measles tops the list here at 16. It means that a person suffering from measles can infect 16 other people who are unvaccinated. In comparison, Coronavirus stands at 2.5, implying that a person infected with Coronavirus can impact on an average of 2.5 people.

But then why do we see an exponential rise in the number of cases?

I would like to draw an analogy with our investment world and bring your attention to compounding. A single person gets impacted on day one. So next day 2.5 will be impacted. The third day we will see a count of around six people who are getting infected. These six people will again impact (6*2.5) around 15. In this manner, the number of people infected rises exponentially.

The best way to contain this is is social distancing which is what is followed by most of the Governments in the world.

So how will this thing end?

Past performance is the best predictor of success

~ Jim Simons

There are actually two scenarios here which I would like to talk about. Let’s start with the first one.

Scenario 1: Strict measures are taken

SARS

There is one analogy in our history and it is regarding the SARS outbreak. SARS was of a similar nature and it started in southern China in 2002. It was brought under control by the measures which we are seeing around us which is through isolation, quarantine, and contact tracing.

In this pandemic, around 8,500 people were infected. Currently, there is no vaccine for this but they were able to contain this through social distancing and the number of new infections was flattened out and consequently, the number of deaths eventually reduced. But while it was easy to identify people who were infected with SARS, it is slightly trickier for the coronavirus carriers. Nevertheless, we can still use this as a reference to understand the impact of Coronavirus on the industry.

Source: Financial Times (FT)

Over here, we the cumulative count and along with that the number of days since the 100th case. You can also see the trajectories if the cases double every day, the second day and so on.

For example, the U.S. took 24 days to reach 100,000 counts and similarly for other countries. The objective here is to make this exponential rising curve a flat as soon as possible. Here, let me direct your attention to South Korea dirt who made it quite flat and a similar thing was done in SARS. Let’s see that chart now.

Source: Wikipedia

This was taken from Wikipedia, and here you can see the cumulative cases in the form of the orange line, which stands at 8437. Initially, the number of cases rose exponentially, right from April to May, but because of social distancing and other measures, the number of incremental case started reducing. This created an “S” or a logistic curve which we see above. The death rate followed the orange curve and flattened out.

If we believe that SARS is a good analogy of what will happen with the Coronavirus, then the following timelines will help us understand how the current situation will pan out.

Source: CDC

Let’s see how the financial markets performed during the SARS outbreak.

Source: Yahoo finance and GitHub Code

This is the same daily percentage change of the four instruments which we are working with. To recall, Crude oil, S&P 500, Gold and 20 years US Treasury bonds. Since this was pretty much a disease epidemic which was in China so we see less impact on the financial markets but nevertheless the red line indicates when it was announced that this was a possible health emergency. You can see that there are some sharp movements in both directions indicating an increase in volatility. The following graph will make it clearer.

Source: Yahoo finance and GitHub Code

You can see Crude oil fell quite sharply in this period but the S&P500 was relatively less impacted in comparison to the coronavirus scenario. The same is seen in the case of Gold and TLT.

Let’s see the drawdowns for this period.

Source: Yahoo finance and GitHub Code

You can see that the drawdowns were pretty bad. S&P500 was around 15% during that period and Crude oil was 30%. But gold was again in mid-teens and US Treasury was down around 5%. I should point out that since this was managed very well by containing the epidemic, the fall was not as significant as we are seeing right now.

We will try the correlation analysis and we see that everything is negatively correlated with S&P500.

Source: Yahoo finance and GitHub Code

This wouldn’t be the right data to work with since this epidemic happened in China. A better metric would be to compare it with the Shanghai index. But nevertheless, we are seeing a very high negative correlation with S&P500 and the Treasury bonds, gold, and crude oil in this period of time.

Let’s see how the things pan out after the crisis is over.

Source: Yahoo finance and GitHub Code

The blue shaded region is when WHO announced that the crisis has been averted. You can see that while there is quite a fall after the WHO declared an emergency, but the index actually recovered quite sharply and the number of days since this happened was also quite short.

I have just taken four instruments for simplicity and you can use your own local index for any correlation analysis you might want to undertake. Do share your insights with me in the comments.

The measures taken for containing SARS are similar to the measures being undertaken for Corona Virus. Actually, it was very well handled and hence it didn’t spread very much away from China.

We will see the returns from the time the WHO declared emergency which is 26th March.

Source: Yahoo finance and GitHub Code

Do understand that it is the one month, three-month, six-month and one-year returns. You can see that the returns for the S&P 500 are very robust like 5%, 10%, 15% and 25% for the respective time periods. It is a similar case for the others as well. Here, CL=F stands for crude oil futures, GC=F stands for gold futures and TLT is the treasury.

If you were to ask which sectors will be impacted the most and how the performance of this sector will be after the crisis, I have tried to answer that with this graph.

Source: FT and JPMorgan

You can see that the sector’s which are most impacted are at the top and sectors which have shown a positive return or the least impacted are shown at the bottom. This graph is of MSCI China sectors. As you can see the most impacted were consumer durables, Software, hotels, restaurants and leisure and Airlines. The least impacted were healthcare, food, beverage and tobacco. The dark blue indicates the performance of the sector during the crisis and the light blue indicates the performance of the sector after the crisis. You can see that food and beverage not only had a positive return during the crisis, but it continued the positive performance after the epidemic was over too. This gives us some cues like the products which are in FMCG or daily essentials are something which we can look for and similarly healthcare and pharma companies are showing similar trends. Interestingly, retailing showed a negative trend during and after the epidemic was over.

So if we think that this scenario is quite possible, then you will know which sectors will be showing a healthy recovery and which will take more time to recover.

This was a scenario where we are able to contain the epidemic by strong measures. We will now move on to the next scenario.

Scenario 2: The disease spreads widely

Source: Wikipedia

Something similar actually happened in the past too. We are talking about the Spanish flu which started during World War one and affected nearly 56% of the world population.

The other two are the Asian flu and Hong Kong flu which impacted around half a million. For comparison, I have given the numbers for coronavirus. So this numbers which might not be most recent but it can help compare the present scenario with the past.

Swine Flu

For this second scenario, we will draw an analogy with the Swine flu which was started in 2009 and impacted around 20% of the population. Let us take the financial impact during this time period.

This is the timeline for Swine Flu.

Source: CDC

Let us look at the financial markets now.

Source: Yahoo finance and GitHub Code

The blue line is when the first case was reported and the red line is when the WHO declared an emergency.

So you will see a stark difference to what is seen currently in the markets because the markets were recovering from the 2008 financial crisis and the stocks were significantly undervalued in that particular period in time. Therefore, the movements were not as sharp as the movements which we are seeing currently.

Source: Yahoo finance and GitHub Code

But nevertheless, when the pandemic was declared, there was this falling crude oil after the red line. This was the case with Gold and S&P 500 as well. Only the TLT was rising and the reason was that the Fed had lowered the interest rate to support the economy.

Let’s check out the drawdowns now.

Source: Yahoo finance and GitHub Code

Maximum drawdowns

Crude Oil -21.68%
SP500 -16.00%
Gold -13.56%
TLT -14.37%

So S&P 500 had a 6% drop after the pandemic was declared. Crude oil was down around 18%, Gold around 7% and TLT in the range of 13%. However, there were multiple waves and while it was not thought of as severe initially, it started spreading to a lot of people in the U.S. Hence, we see a lot of our fall not when the pandemic was declared but sometime later.

Let’s see what the scatter plot tells us now.

Source: Yahoo finance and GitHub Code

Here you can see a clear relationship emerge from the asset classes. For example, the S&P 500 and TLT is negative, which implies that the S&P500 will fall if TLT rises. The relationship with gold is not exactly clear and thus we can’t be sure if Gold is a safe haven or not.

With crude oil, we are seeing a positive relationship between the two, implying that if S&P500 falls, Crude oil will decline too.

To summarise, S&P500 has a positive correlation with Crude oil, negative with TLT and no relation with Gold.

Let’s see how things turned out after WHO said everything is good.

Source: Yahoo finance and GitHub Code

As we have seen before, The blue shaded region is after the WHO declared the pandemic is over. You can see the returns are pretty strong. The data is for a year after the declaration and these are the returns. Do keep in mind that the returns are calculated from the start date when the first case was reported.

Returns from the first date

Crude Oil 73.62%
SP500 42.20%
Gold 29.89%
TLT -10.46%

Thus, when everything gets sorted out, the market tries to catch up and enters into a bullish mode and everything looks perfectly normal. Let’s see the returns in a bar format for added emphasis.

Source: Yahoo finance and GitHub Code

You can see the performance of all the instruments with respect to the time horizon here.

Let’s see the sector performance.

Source: Yahoo finance and GitHub Code

It is interesting to note that unlike the previous scenario, here the financial sector performed relatively well and was actually at the top. The reason is basically the world had plunged into an economic recession a year from the swine flu epidemic, which had led to significant sell-offs and causing the financial market to be undervalued. It was a similar case for technology stocks as well.

The energy sector was significantly impacted during the epidemic but rallied up sharply after the situation turned for the better. This is similar to the crude oil rally which we saw earlier.

Asian Flu

Source: Yahoo finance and GitHub Code
Source: Yahoo finance and GitHub Code

I hope this gives some perspective on how the situation will turn out at present. In fact, just for an added exercise let us look at the Asian flu epidemic too.

The following is the performance of S&P500.

Here, the red line indicates the time it started spreading in the U.S. The blue area is after WHO declared that it was over.

The same story is repeated for drawdowns where we see a maximum drawdown of 20% after WHO declared a public emergency.

Hong Kong Flu

Let’s see what Hong Kong Flu tells us now.

Source: Yahoo finance and GitHub Code

The red line indicates the time when WHO declared an emergency while the blue shaded region shows us the period after WHO said it was over.

Coming to the drawdowns, we see a maximum drawdown of 35%.

Source: Yahoo finance and GitHub Code

An important observation here is that the market does not like uncertainty. Thus, when the emergency is declared, the market declines sharply. But once we have taken the necessary steps to contain the situation and once the WHO has declared it is safe, the market immediately responds and rallies up to the pre-crisis levels or in some cases, even surpassing it.

Spanish Flu

Let’s see what the Spanish flu teaches us. The Spanish flu can be said to have occurred in three waves. June and July of 1918, then in October to December of 1918 and finally from January to March in 1919. I have used the Dow Jones Index here and the S&P500 was created in 1927. You can see the performance below.

Source: macrotrend

You can see that the market was going up even through the worst phases of the Spanish flu. The reason is that, similar to swine flu, there was a bigger event which impacted the markets, and this was world war 1. The world was actually recovering from world war 1, which ended in 1918, when the Spanish flu struck. This is why there is an uptrend in the markets.

World War II

As an aside, here is how world war 2 impacted the financial markets.

Source: Yahoo finance and GitHub Code

The V shape is similar to the past graphs we have seen, just time of recovery is different.

Source: Yahoo finance and GitHub Code

We know that world war 2 ended in 1945, but the markets started rising from 1942. As I said earlier, the market does not like uncertainty. That is why the market dipped below, but in 1942 the allied forces had come together and started planning a coordinated plan to defeat the enemy. Thus, the market factored in this information and hence, once we were certain of the plans, the markets started recovering. The maximum drawdown here can be seen around 43%.

Factor Investing

How would you invest in the current situation? One emerging method is factor investing. One example of a factor is momentum which states that if anything rises for a year, it will continue to rise.

Let us see the performance of some factors during COVID19.

Source: van Vliet, Pim and Baltussen, Guido, Equity Styles and the Spanish Flu (March 30, 2020)

The monthly performance of various factors from the months of January to March 20 is shown above.

Here you can see that while the others are generally negative, momentum-based factor investing is outperforming the market. To some extent, even low-volatility has outperformed the market. But will this continue?

It is actually very difficult to answer this question based on the current table. Let’s try to see how things played out in the past.

Source: van Vliet, Pim and Baltussen, Guido, Equity Styles and the Spanish Flu (March 30, 2020)

We can see that while momentum is close to the market (in black) the small-cap is underperforming. But in the recovery phase, the small caps outperform all other forms of investing. You can also see momentum and low volatile stock during the recovery phase have underperformed the market.

But so far, we have seen data which was related to pandemics. I will try to present the data about market corrections happening before 1926, or more specifically 1872–1918. These corrections are not exactly related to pandemics but they were a time of great uncertainty, Let’s see how this plays out.

Source: van Vliet, Pim and Baltussen, Guido, Equity Styles and the Spanish Flu (March 30, 2020)

As we have seen earlier, the low volatility and momentum-based investing do not fall as low as the market but do not outperform the market in the recovery phase. In contrast, small caps decline more than the market during the correction phase but outperform it in the recovery phase.

When will this end?

Research on pandemics by Hackett Financial shows that most major viral outbreaks, such as the Great Plague of 1665 and the Spanish flu a little over a century ago, played out within 3 months. In other words, those bad events came and went mainly within 12 weeks.

Considering the past data which shows that the number of days till WHO declares it is safe has reduced, we could be looking at anywhere between three to six weeks.

Swine Flu: 116 days
SARS: 101 days

However, I cannot stress enough the importance of social distancing. The governments across the world should be proactive in imposing social distancing. In fact, the following is the chart of various cities in America at the time the Spanish flu was spreading across the US.

Source: National Geographic

The shaded region is the time when the lockdown was imposed and you can see the death toll declining rapidly. Thus, social distancing is really effective to overcome this crisis.

How to protect your equity heavy portfolio?

If you’re thinking about your portfolio, then TLT makes sense since it has a negative correlation to the S&P500. You should avoid crude oil as the demand for it could weaken due to the current crisis.

Note: You should consult with a financial advisor before adopting any of the recommendations.

Summary

Phew! We have gone through quite a few scenarios. Let us try to summarise these in a table somehow.

Source: Yahoo finance and GitHub Code

You can see in terms of drawdown, COVID is in third place at 33%. But if you check the returns after a period of six months, they look really promising. This will give you some idea on how the returns will look after 6 months and a year after COVID 19.

Note from Towards Data Science’s editors: While we allow independent authors to publish articles in accordance with our rules and guidelines, we do not endorse each author’s contribution. You should not rely on an author’s works without seeking professional advice. See our Reader Terms for details.

--

--

Machine learning, Data Science and quant trading enthusiast. Working as Quant Researcher in Quantra. LinkedIn: https://www.linkedin.com/in/ishan-shah-18393828/