ALIBABA STOCK PRICE PREDICTION MODEL

The stock price of AliBaba has grown intriguingly over time. With this model, I will compare moving averages of historical data to predict the stock price of BABA after 7 years, i.e. the Market Price of BABA in 2026. Step 1: Taking the Market Price for BABA from 2014-01-01 to 2019-02-01, create a time series and calculate the mean and standard deviation of the market price. Step 2: Use Technical Analysis tools such as Bollinger Bands and Moving Averages to analyze the stock outcomes. Step 3: Use the price data to determine the mean and standard deviation of the log return of the stock. Step 4: Create a Probability Distribution Function in order to calculate the probability of return in each quantile. Step 5:Use the mean log return to extraplote prices for the next 7 years using Random Walk.

DATA SET:

Using the data directly from the Yahoo Finance page to make calculations. Use the quantmod package to directly input data from Yahoo Finance into R. The data is collected from 1/1/17 to 17/10/18.

options("getSymbols.warning4.0"=FALSE)
getSymbols("BABA", from = "2014-01-01", to = "2019-02-10")
## 
## WARNING: There have been significant changes to Yahoo Finance data.
## Please see the Warning section of '?getSymbols.yahoo' for details.
## 
## This message is shown once per session and may be disabled by setting
## options("getSymbols.yahoo.warning"=FALSE).
## [1] "BABA"

BABA Summary & Structure

summary(BABA$BABA.Open)
##      Index              BABA.Open     
##  Min.   :2014-09-19   Min.   : 57.30  
##  1st Qu.:2015-10-23   1st Qu.: 83.34  
##  Median :2016-11-28   Median :103.84  
##  Mean   :2016-11-28   Mean   :120.59  
##  3rd Qu.:2018-01-03   3rd Qu.:165.36  
##  Max.   :2019-02-08   Max.   :209.95
str(BABA)
## An 'xts' object on 2014-09-19/2019-02-08 containing:
##   Data: num [1:1105, 1:6] 92.7 92.7 88.9 88.5 91.1 ...
##  - attr(*, "dimnames")=List of 2
##   ..$ : NULL
##   ..$ : chr [1:6] "BABA.Open" "BABA.High" "BABA.Low" "BABA.Close" ...
##   Indexed by objects of class: [Date] TZ: UTC
##   xts Attributes:  
## List of 2
##  $ src    : chr "yahoo"
##  $ updated: POSIXct[1:1], format: "2019-03-18 00:50:48"

The graph below shows us the Market Price of BABA stock price from 01/01/14 to 02/01/19. As we can see, BABA has seen a steady increase in price, showing a bullish trend along the years. However as of recent there was a steep drop in market price and growth has been slower ever since.

ggplot(data = BABA, aes(x = Index, y = BABA.Open)) + 
    geom_line(color = "#D12803", size = 1) + labs(title = "Graph #1 - Alibaba (BABA) price trend since IPO")

This next graph shows us the trend in Market Price of BABA in 2018, along with other Technical Indicators such as Bollinger Bands, Volume Graphs and Moving Averages.

BABA %>% chartSeries(TA = "addBBands();
              addBBands();
              addVo();
              addMACD()", 
    subset = "2018", theme = "black")

Using Market price data for BABA from 1/1/14 to 02/08/19, we calculate the Percentage return of the stock in natural log form.

Since Log price scales adjust prices based on percentage change rather than magnitude.

In the graph below, we create a histogram, with 100 bins. From the graph below, we can tell that the Percentage log return of BABA stock is crowded around 1%, however further analysis needs to be done to find out the potential return.

BABA_log_returns <- BABA$BABA.Open %>% dailyReturn(type = "log", leading = 'True')
names(BABA_log_returns) <- "BABA.Log.Returns"
BABA_log_returns %>% exp() %>% ggplot(aes(x = BABA.Log.Returns)) + 
    geom_histogram(bins = 100) + geom_density() + geom_rug(alpha = 0.5) + 
    labs(title = "Graph #3 - Alibaba Log Returns")

The graph shows that the return can be approximated to a normal distribution. We know this because on calculating the mean and median for the BABA log returns, the results is the same.

Now we create a quantile in order to represent the daily rate of return in another format. From the Quantiles below we can find the probability of the Log return at Each Quantile.

probs <- c(0.25, 0.5, 0.75)
dist_log_returns <- BABA_log_returns %>% exp() %>% 
    quantile(probs, na.rm = TRUE)
dist_log_returns
##       25%       50%       75% 
## 0.9885137 1.0003446 1.0125937

The median return per day of Alibaba stock is 1.00034%

Analysis

With the Log Price data we calculated above, the mean and standard deviation of the log return can be calculated.

Mean_Log_Returns <- mean(BABA_log_returns, na.rm = TRUE)
sd_log_returns <- sd(BABA_log_returns, na.rm = TRUE)
# Mean Log Returns
Mean_Log_Returns
## [1] 0.0005153492
#SD log Returns
sd_log_returns
## [1] 0.02380338

Predicting AliBaba stock price:

Using the Random Walk method, I will predict the stock prices for long term price trends. The mean and standard deviation of the log return will be used to randomly generate the growth rate.

The generated exponential growth rate will help us find the cumulative price of the stock in 2026.

# Price on 02/08/2019

price = 167.36

# Predicting Price for 2026

set.seed(50)
for (i in 2:length(BABA$BABA.Open)) {
    price[i] <- price[i - 1] * exp(rnorm(1, Mean_Log_Returns, 
        sd_log_returns))
}

# Creating Data frame for 7 years worth of data in
# the future

BABA_data = cbind(price, 1:length(BABA$BABA.Open))
colnames(BABA_data) = c("Price", "Day")
BABA_data = as.data.frame(BABA_data)
BABA_data %>% ggplot(aes(Day, Price)) + geom_line() + 
    labs(title = "Graph #4 - AliBaba (BABA) price simulation for 7 years")

The graph above show us that the Market Price of AliBaba will follow a “Bullish” trend. This model predicts that the value will fall in between $350 and $380.

Now to understand the last 6 days of the last week of the BABA market price simulation:

knitr::opts_chunk$set(echo = TRUE)
last_BABA = tail(BABA_data)

Market_Price = tail(BABA_data$Price)
Day_no = c("Day 6 - ", "Day 5 - ", "Day 4 - ", "Day 3 - ", 
    "Day 2 - ", "Day 1 - ")

df = data.frame(Day_no, Market_Price)

stargazer(df, type = "html", header = FALSE, title = "Last Week Market Price: BABA", 
    summary = FALSE, rownames = FALSE)
Last Week Market Price: BABA
Day_no Market_Price
Day 6 - 334.917
Day 5 - 329.004
Day 4 - 330.361
Day 3 - 327.765
Day 2 - 326.080
Day 1 - 318.250

Results

probs <- c(0.25, 0.5, 0.75)
price_quantile <- Market_Price %>% quantile(probs = probs, 
    na.rm = TRUE)
price_quantile
##      25%      50%      75% 
## 326.5014 328.3846 330.0216
ggplot(last_BABA, aes(Day, Price, group = 1)) + geom_boxplot() + 
    labs(title = "Graph #5 - Boxplot of AliBaba Prices in Last Week")

In the penultimate week of simulation, BABA Market price has the following properties:

summary(last_BABA$Price)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   318.2   326.5   328.4   327.7   330.0   334.9

Confidence Interval

ci = t.test(Market_Price, level = 0.95)$conf.int
CI = t.test(Market_Price, Level = 0.95)
result = c(ci[1], ci[2])
names(result) = c("lower", "upper")
CI
## 
##  One Sample t-test
## 
## data:  Market_Price
## t = 145.22, df = 5, p-value = 2.938e-10
## alternative hypothesis: true mean is not equal to 0
## 95 percent confidence interval:
##  321.9282 333.5309
## sample estimates:
## mean of x 
##  327.7295

#95% Confidence Interval Estimates

result
##    lower    upper 
## 321.9282 333.5309

Conclusion

The model predicts with a 95% confidence interval that the market price value of Alibaba stock will be between $321.93 and $333.5309 by 2026.

This growth rate of 15.29% per year might as well be accurate. However, if we look at the trend in Prices of Alibaba since it’s Initial Public Offering, it has increased from $68 to $167. This is an increase in percentage of nearly 145% and 36.25% per year.

Therefore, this model predicts that Alibaba is currently undervalued based on it’s expected growth rate in the next 7 years, and confirms the hypothesis that investing in Alibaba may be a good decision.

Limitations of the Model

I set the seed on this model to 50 while simulating the prices. The results will change slightly for every different seed value.

This model only takes into account the quantitive technical factors that would affect the stock price. This is not always true since qualitative factors can greatly affect the performance of the company, which may not adhere to the mean and standard deviation in it’s price historically.