-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtesla-stock-prediction.Rmd
92 lines (65 loc) · 1.84 KB
/
tesla-stock-prediction.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---
title: "Tesla Stock Prediction"
author: "G ADITYA KUMAR"
date: "29/9/2023"
output: ioslides_presentation
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
echo = FALSE,
warning = FALSE,
message = FALSE
)
options(knitr.table.format = "html")
```
```{r libraries}
# plotting
library(ggplot2)
# table format
library(kableExtra)
# forecasting
library(quantmod)
library(forecast)
library(tseries)
theme_set(theme_classic() + theme(
axis.text = element_text(size = 12),
axis.title = element_text(size = 14, face = "bold")
))
```
## Description
In this project, I will be using R to predict the TSLA stock.
I will use the ARIMA modelling, more specifically, auto ARIMA to predict the stock
rise.
(Disclaimer) This is presentation is not to be taken as an investment advice.
## The Tesla Stock Data
The data will be is from [Yahoo! Finance](https://finance.yahoo.com/).
Here's a peek at the data
```{r results="hide"}
# specify to and from dates
from.dat <- as.Date("09/27/21", format="%m/%d/%y")
to.dat <- as.Date("09/27/23", format="%m/%d/%y")
# get data for AAPL from Google Finance for the specified dates
getSymbols("TSLA", src="yahoo", from = from.dat, to = to.dat, auto.assign=TRUE)
```
```{r }
head(TSLA) %>%
kbl() %>%
kable_classic(full_width = F, html_font = "Cambria")
```
## Plot of TSLA.close stock
```{r}
mTSLA <- to.monthly(TSLA)
# extract the closing price and convert it to yearly time series (12 observations per year)
ts <- ts(Cl(mTSLA))
# plot time series
plot(ts)
# add the moving average in red
lines(ma(ts,order=3),col="red")
```
## Prediction from ARIMA Model
```{r}
modFit <- auto.arima(ts, lambda = "auto")
price_forecast <- forecast(modFit, h=30)
plot(price_forecast)
```
From our prediction, it shows there was little possiblity our ARIMA model could ever predict the huge stock rise of tesla.