AI for Trading Series №1: The Stock Prices

Photo by M. B. M. on Unsplash

Terminologies

Basics

  1. Stock : An asset that represents ownership in a company. A claim on part of a corportation’s assets and earnings. There are two main types, common and preferred.
  2. Share : A single share represents partial ownership of a company relative to the total number of shares in existence.
  3. Common Stock : One main type of stock; entitles the owner to receive dividends and to vote at shareholder meetings.
  4. Preferred Stock : The other main type of stock; generally does not entail voting rights, but entitles the owner to a higher claim on the assets and earnings of a company.
  5. Dividend : A partial distribution of a company’s profits to shareholders.
  6. Capital Gains : Profits that result from the sale of an asset at a price higher than the purchase price.
  7. Security : A tradable financial asset.
  8. Debt Security : Money that is owed and must be repaid, like government or corporate bonds, or certificates of deposit. Also called fixed-income securities.
  9. Derivative Security : A financial instrument whereby its value is derived from other assets.
  10. Equity : The value of an owned asset minus the amount of all debts on that asset.
  11. Equity Security : A security that represents fractional ownership in an entity, such as stock.
  12. Option Contract : A contract which gives the buyer the right, but not the obligation, to buy or sell an underlying asset at a specified price on or by a specified date
  13. Futures Contract : A contract that obligates the buyer to buy or the seller to sell an asset at a predetermined price at a specified time in the future

Buy and Sell Side

  1. Buyers and sellers are those who go through the stock exchange to buy a stock that they think will do well, or sell a stock that they wish to remove from their investments.
  2. Market maker, is the one who serves as the counterparty of these buyers or sellers. Since every buyer needs a seller, and every seller needs a buyer, a market maker plays the role of seller to those who wish to buy, and plays the role of buyer for those who wish to sell and by convention they are known as sell side of the finance industry. The sell side usually includes investment banks such as Goldman Sachs, Morgan Stanley.
  3. The buy side refers to individual investors, and investment funds such as mutual funds and hedge funds.

Liquidity

Tick Data

Tick Data Source: AI for Trading nano degree course on Udacity

OHLC : Open, High, Low, Close

  • Open is the stock price at the begining of the period.
  • High and Low capture its range of movement
  • Close is where it ends.
  • Daily closing price is the one that is quoted most often. This is usually used by casual traders and investors interested in long term gains.
  • Opening price is where the first trade of the day to take place. There might be a gap from last day’s closing price due to pre-market trading or trading in other markets.
  • High-Low captures the movement of the stocks

Volume

  • large volume of buy order tends to increased stock price.
  • large volume of net sell orders tends to decreased stock price.

Intraday Volume

Intraday Volume, Source: AI for Trading nano degree course on Udacity
Intraday Volume Pattern , Source: AI for Trading nano degree course on Udacity

Data Processing

Stock Splits

  1. Stock Splits
  2. Divident
Market Capitalization = Stock Price X Total number of shares outstanding
Stock Split for AMZN, Source: AI for Trading nano degree course on Udacity

Stock Split Normalization

Source: AI for Trading nano degree course on Udacity
Normalization of Stock Split data, Source: AI for Trading nano degree course on Udacity

Dividends

Dividends Normalization

Adjusted Price Factor = 1 + Dividend/(Stock price at ex-dividend date)

Technical Indicators

  1. Moving Window/ Rolling Mean/ Simple Moving Average
  2. Bollinger Bands
  3. Price to Earnings Ratio
  4. Exchange Traded Funds (ETFs)
  5. Stock Returns : Raw Returns and Log Returns

Moving Window or Rolling Mean

Simple Moving Average (Rolling Mean), Source: AI for Trading nano degree course on Udacity
Source: AI for Trading nano degree course on Udacity

Bollinger Bands

  1. 2 Standard Deviations above the mean.
  2. 2 Standard Deviations below the mean.
Bollinger Bands, Source: AI for Trading nano degree course on Udacity
Source: AI for Trading nano degree course on Udacity
  1. When a particular point below the lower Bollinger band tries to crawl back inside the mean, that’s when we should buy the stocks.
  2. On the other hand, we can sell the stock if it starts to decrease towards the mean.
Buy/Sell Strategy using Bollinger Bands, Source: AI for Trading nano degree course on Udacity

Price to Earnings Ratio

PE Ratio = (stock’s current market price) / (most recently reported earnings per share (EPS))

Exchange Traded Funds (ETFs)

  1. Lower rate of return : Reduced risk
  2. Higher rate of return : High risk

Stock Returns

Raw Returns

Stock Returns, Source: AI for Trading nano degree course on Udacity

Log Returns

Why log returns?

  1. Log returns can be interpreted as continuously compounded returns.
  2. Log returns are time-additive. The multi-period log return is simply the sum of single period log returns.
  3. The use of log returns prevents security prices from becoming negative in models of security returns.
  4. For many purposes, log returns of a security can be reasonably modeled as distributed according to a normal distribution.
  5. When returns and log returns are small (their absolute values are much less than 1), their values are approximately equal.
  6. Logarithms can help make an algorithm more numerically stable

Trading Strategies

Momentum Trading Strategy

Long and Short Positions

  1. Stock has an upward momentum.
    In this case, you will buy the stocks and hold on to it for a fixed time or until stock starts to fall. This is known as taking a long position on the stock. And when you sell your stock at a higher position than you bought it, that is known as closing your position.
Long Position, Source: AI for Trading nano degree course on Udacity
  1. Stock has a downward momentum.
    In this case, you believe that, due to momentum strategy, it will continue to fall down for some time. In this scenario, you take a short position on stock, where you sell first and buy back later.
Short Position, Source: AI for Trading nano degree course on Udacity

Cross-sectional Strategy

Cross-sectional Trading Strategy, Source: AI for Trading nano degree course on Udacity

Portfolio

Long

Short

Trading Strategy

  • Stock Universe : group of stocks that share some common features or belong to the same market.
  • By daily close prices, the figure means adjusted closing prices.
  • In the example below, we have chosen a stock universe from S&P500. Make sure that the dataset you choose for testing your strategy for a particular year, say 2020, contains the companies that were a part of stock universe in 2020.
Formulating your Trading Strategy, Source: AI for Trading nano degree course on Udacity

Calculating the performance of our trading strategy

Statistical Test

t-statistic test, Source: AI for Trading nano degree course on Udacity
p-value, Source: AI for Trading nano degree course on Udacity
  • p-value is very small : unlikely that true mean is zero. We need to also set a threshold for p-value to conclude that if p-value falls below this threshold, the true-mean is unlikely to be zero. This threshold is denoted by the term alpha. Commonly used value is 0.1.
t-Test, Source: AI for Trading nano degree course on Udacity

Hi! I am a tech enthusiast currently working on leveraging language technologies to solve financial use-cases! View my work here: https://purvasingh96.github.io

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Your Generosity is Keeping You in Debt

MANAGING MONEY USING THE CEO PRINCIPLE — Winners Ways

DO PREPAID CREDIT CARDS WORK TO ORDER CONCERT TICKETS ONLINE?

The Miseducation of Dollar Bill, Vol. 1

Difference 401(k) and IRA?

Key Takeaways from The Magic of Owning Your Own Home

Here’s How I Leverage My Finances to Get Free Flights

The IPO Fund — Outperform The Index 💸

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Purva Singh

Purva Singh

Hi! I am a tech enthusiast currently working on leveraging language technologies to solve financial use-cases! View my work here: https://purvasingh96.github.io

More from Medium

Dynamic Portfolio Using Technical Analysis

Futures and Options Trading in The Stock Market — My Trade Logic

8 indicators for your charts — What they are and how to use them

Is There a Trend in Highest and Lowest Bitcoin Trading Volume?