Trading the Trade War – Sentiment-Based Trading using Google Trends

You can find the web application, made using Dash here :

Prospect Theory and Loss Aversion

Prospect Theory is a theory in cognitive psychology that describes the way people choose between probabilistic alternatives that involve risk, where the probabilities of outcomes are uncertain. The theory states that people make decisions based on the potential value of losses and gains rather than the final outcome, and that people evaluate these losses and gains using some heuristics. A layman way to think of Prospect Theory is an analysis of decision under risk.

One easy illustration of loss aversion in prospect theory is when we are faced with two choices:

  1. Get $50 dollars straightaway
  2. Flip a coin – get $100 if heads, nothing if tails.

Most people go for choice (1), because we can’t bear the thought of getting nothing should we choose (2) and the coin says tails. We are loss-avoiding creatures, even if mathematically (1) and (2) are the same.

Relating Prospect Theory to Google Trends

Dr. Tobias Preis from Warwick Business School suggested in 2013 that Google Trends could be used to predict stock movements in his paper “Quantifying Trading Behavior in Financial Markets Using Google Trends”. 

Here is a link to his presentation. A simple trading strategy proposed by him is as follows:

Why does this strategy work? Apparently, according to prospect theory, we tend to search more when bad news happens. We over-react to bad news (searching frantically and worrying) and under-react to routine news like reliable growth in a company. So, when something bad happens, a lot of people search for it, and cause a upwards spike in Google Trends, and that is generally when it is time to sell. Conversely, when the data point in Google trend drops, it means less folks are searching for the topic and hence no bad sentiment is evident. Arguably, it is a better time to buy in “calmer” times.

Of course, for the individual investor, there are a number of issues with the trading strategy above, even if the paper claims it to be profitable.

  1. The number of trading transactions will be too large if we are doing a transaction every week. If we are charged $20 per transaction, the transaction costs will balloon and prove to be too much for the individual investor.
  2. Individual investors do not have the advantage of speed – by the time it is his/her turn to buy/sell, the effect may already be priced in.

Hence, for the individual investor, we can only make use of this knowledge in the broad sense, perhaps as a danger alert indicator for bad times ahead. In this article, we will investigate how we can make use of this knowledge and how it may be applied to the individual retail investor’s trading activities.

Defining the Terms for the Experiment

We will use some popular stocks like AAPL and GOOG to run the experiment. Before we begin, we have to define some terms that we will use throughout the article as well as the web application, as follows:

  • Upper Sell Threshold : This is the percentage increase of the google trend from one data point to another beyond which we sell. Default for the program developed is set at 45%.
  • Lower Buy Threshold : This is the percentage decrease of the google trend from one data point to another beyond which we buy. Default for the program developed is set at -40%.
  • Keyword : This is the keyword to be entered for the Google Trends. The default keyword we use here is “Trade War” as a topic in Google Trends.
  • Shares to Buy: This is the number of shares to buy for each transaction.
  • Shares to Sell: This is the number of shares to sell for each transaction.
  • Initial Money: We also define in the program the initial amount of money that we have to do the transactions.

Rules of the Game

There are some other important rules to consider in our experiment as well:

  • Bench-marking against Buy-and-Hold: Naturally, we would benchmark this trading strategy against buy-and-hold, where we buy the stock at the first buying opportunity (same first buying opportunity as the Google Trends strategy) and hold it till the end of the experimental period. We will then check to see if the strategy has earned more or less money than buy-and-hold.
  • Number of transactions are recorded and transaction costs are accounted for: The cost of each transaction is set at $20, and is multiplied by the number of transactions that took place as a result of the strategy. This is for added realism with the individual retail investor in mind.
  • If Not Enough Funds to Buy: If we do not have “cash” on hand to buy more shares, we will buy the maximum number of shares that we can afford.
  • If Not Enough Shares to Sell: If we do not have the stipulated number of shares to sell, we will sell whatever remaining shares we have. In this sense, if we have not bought anything yet, we will not be able to sell anything, even if it is a “sell” line.
  • Period of Testing: The experiment is set over the Trade War timeline, from early 2017 to the current date. The web app will be kept alive and running throughout the trade war.


You can find the web application, made using Dash here :

Running the experiment, we are able to “devise” a strategy that out-performs the buy-and-hold strategy. This shows that there is some truth to the claim that Google Trends is capable of aiding investment strategies.

In the web app, the red dotted lines are “sell” actions and the blue dotted lines are”buy” actions. You are able to choose your own parameters to run the experiment to your liking.

Disclaimer: Do not blame me for any loss of money should you decide to follow this strategy. This is a purely academic endeavour that explores the link between prospect theory, trends and the stock market.

That said, there is a emotional hurdle here to overcome if we are to abide fully with the strategy. For example, when the algorithm tells me to sell when I will clearly lose money. Greed is also something I had to overcome, when the algorithm told me to sell when it is clear the trend is going up.

I will keep the web application alive on Heroku so that it can serve as a continuous point of reference for this article. It can be a little slow on first access as it is a free app hosting tier and this is the default behaviour (I’m cheap) – the app has to start itself up. For me personally, this app is useful as a “chicken-little” early warning signal. It’ll be interesting to see how the future plays out!

Let me know at what you think! I would be interested in ideas and suggestions for the web app. Thanks!

Lastly, I would like to thank Mr. Eric Tham from the NUS-ISS Sentiment Mining course for introducing us to this as well as other finance related topics. 

You can find Part 2 of this article here, where I describe some extensions I made to the app, and some findings. 

Image result for chicken little the sky is falling