Over the last few decades, Computer Science has increasingly integrated itself into finance and economics. Leading financial institutions are now depending on computers to produce outcomes. For instance, JP Morgan, Chase, and Barclays rely on supercomputers to assess the risk of a stock portfolio or forecast an asset’s future value. How is this achieved?
In this article, I will examine how computers interpret sentiment and apply machine learning to optimize investment returns.
## Sentiment Analysis
The market has transitioned from making investment decisions based on instinct to placing confidence in computer programs. The era of traders hurriedly buying and selling stocks on the trading floor is diminishing. In place of floor traders are quantitative analysts, often referred to as quants. Quants create computer algorithms that heavily leverage mathematics to execute trades and predict the future performance of stocks.
Acknowledging the change in the market, Dow Jones has created a lexicon to simplify how computers can analyze stock movement. Another term for lexicon is *dictionary*. The Dow Jones Lexicon (DJL) compiles financial news and transforms it into a format that computers can interpret. Additionally, the DJL contains six distinct dictionaries, all developed by Bill McDonald, a finance professor at the University of Notre Dame. Financial firms, however, have the option to create their own dictionaries tailored to their specific requirements.
With a lexicon, a computer can distinguish between positive and negative news. This information then guides traders in determining whether it would be prudent to execute a trade concerning that stock.
Below is a graphic illustrating whether the sentiment for a stock is bullish (positive) or bearish (negative)
Let’s analyze a news article to understand how the sentiment lexicon functions. [This](https://www.cnbc.com/2021/11/26/stock-futures-open-to-close-market-news.html) article from CNBC was published on November 26, 2021, just days following the discovery of a new variant of COVID by scientists in South Africa.
This is the opening line of the article. You will notice that one of the initial words is “dropped.” A computer that examines this fragment of text would classify it in the negative category, lowering the sentiment score and signaling that the stock market is bearish. The positioning of the word is also crucial. Keywords that appear in headlines or early sections carry more influence on the sentiment score than those that might be hidden in the body of the text.
In this screenshot, you will observe keywords such as “down,” “dropped,” “lost,” and “fell.” These words will again be interpreted by the computer as negative, thus reducing the sentiment score.
So, what does this process look like on the computer side? It turns out to be a relatively straightforward procedure. Developing a sentiment analysis program is accomplished through XML code. XML stands for extensible markup language and is closely associated with HTML; however, it is not a standalone language. HTML specifies how a document should be presented, while XML defines the actual data within the document. For instance, HTML includes tags that a programmer uses to generate specific objects. The `
` tag signifies the primary heading of a webpage (h for heading; 1 for the first heading). In contrast, XML allows a programmer to customize their code more specifically. Instead of a vaguely defined `
` tag, XML enables the programmer to assign a tag something like “ to clarify what is being defined. This customization facilitates code interpretation and allows it to cater to a business’s requirements.
Note: the following code was compiled by sqlauthority.com
“`xml
White
Blue
Black
Green
Red
Apple
Pineapple
Grapes
Melon
“`
In the illustration above, quants or traders would adhere to a similar format as shown, merely altering the tags to fit a sentiment analysis algorithm.
Sentiment analysis merely scratches the surface of what computers can accomplish on Wall Street. While I will not discuss all applications, I will proceed with the article by addressing the role of Machine Learning in predicting market movements.
## Machine Learning
Machine Learning (ML) is a subset of Artificial Intelligence (AI) that collects information for systems like Siri to make decisions. In this context, rather than Siri, we are referring to computer algorithms. Read more about ML and AI in a prior [post](https://stemfromscratch.org/