AAPL’s stock analyzing

This project is to analyze the stock price data of Apple Inc from 2007 to 2024. The data is directly taken from Yahoo Finance.

Install packages

library(quantmod)
## Loading required package: xts
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: TTR
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo

Summerize the stock data

symbolBasket <- c('AAPL')
getSymbols(symbolBasket , src='yahoo')
## [1] "AAPL"
summary(`AAPL`)
##      Index              AAPL.Open         AAPL.High          AAPL.Low      
##  Min.   :2007-01-03   Min.   :  2.835   Min.   :  2.929   Min.   :  2.793  
##  1st Qu.:2011-06-01   1st Qu.: 12.502   1st Qu.: 12.621   1st Qu.: 12.399  
##  Median :2015-10-29   Median : 27.843   Median : 28.093   Median : 27.489  
##  Mean   :2015-10-31   Mean   : 55.623   Mean   : 56.220   Mean   : 55.055  
##  3rd Qu.:2020-03-31   3rd Qu.: 76.710   3rd Qu.: 77.859   3rd Qu.: 76.005  
##  Max.   :2024-08-30   Max.   :236.480   Max.   :237.230   Max.   :233.090  
##    AAPL.Close       AAPL.Volume        AAPL.Adjusted    
##  Min.   :  2.793   Min.   :2.405e+07   Min.   :  2.358  
##  1st Qu.: 12.517   1st Qu.:9.646e+07   1st Qu.: 10.570  
##  Median : 27.883   Median :1.911e+08   Median : 25.250  
##  Mean   : 55.662   Mean   :3.464e+08   Mean   : 53.754  
##  3rd Qu.: 77.343   3rd Qu.:4.679e+08   3rd Qu.: 75.084  
##  Max.   :234.820   Max.   :3.373e+09   Max.   :234.549

Data preparation-cleanup and preparing for charting

APPL.Co <- as.xts(`AAPL`)
names(APPL.Co)
## [1] "AAPL.Open"     "AAPL.High"     "AAPL.Low"      "AAPL.Close"   
## [5] "AAPL.Volume"   "AAPL.Adjusted"
names(APPL.Co) <- c("AAPL.Co.Open", "AAPL.Co.High", "AAPL.Co.Low", "AAPL.Co.Close", "AAPL.Co.Volume", "AAPL.Co.Adjusted")
names(APPL.Co)
## [1] "AAPL.Co.Open"     "AAPL.Co.High"     "AAPL.Co.Low"      "AAPL.Co.Close"   
## [5] "AAPL.Co.Volume"   "AAPL.Co.Adjusted"

#Plot Charting

plot(APPL.Co$AAPL.Co.Open)

This chart is for the opening stock price of Apple Inc. from Jan,2007 to Aug,2024. The chart clearly shows the growth of the price. Surely there have been some hiccups yet shows that the hiccpus could not stop the ongoing growth.

Some more variables with volumn

lineChart(APPL.Co, line.type = 'h', theme = 'white')

This chart is a horizontal line chart for showing the volumns (millions).

Barchart for High, Low, Close

barChart(APPL.Co, bar.type = 'hlc', TA = NULL) 

This is a bar chart for showing the High, Low, Close price of the price.

A subset and in candle sticks for 2024

candleChart(APPL.Co, TA=NULL, subset = '2024')

This is a candle chart of the stock price of 2024 (Jan-Aug). Just like a bar chart, a daily candlestick shows the market’s open, high, low, and close prices for the day.Traders use candlestick charts to determine possible price movement based on past patterns.Candlestick charts are more visual due to the color coding of the price bars and thicker real bodies. Highlighting prices this way makes it easier for some traders to view the difference between the open and close.

Moving Average Convergence Divergence (MACD)

It measures the momentum of a security’s price and helps traders identify trends and reversals

candleChart(APPL.Co, TA=c(addMACD(),addADX()), subset = '2023-01::')

This is a MACD candle chart. There are three main components of the MACD shown in the chart above: 1.MACD (Grey colour line): The 12-period exponential moving average (EMA) minus the 26-period EMA. 2.MACD Signal Line (Red colour “—”): A 9-period EMA of the MACD. 3.MACD Histogram (Grey colour): The MACD minus the MACD Signal Line. When the shorter-term 12-period exponential moving average (EMA) crosses over the longer-term 26-period EMA a potential buy signal is generated. So, from the chart, it is clearly shown that in the given period, the lines have crossed over each other quite a lot of time, which indicated a potential buy for the investers.

CandleChart MACD

 candleChart(APPL.Co, TA=c(addMACD()), subset = '2023-01::2023-05', theme = 'white')

This is a candle chart MACD for better understanding.

ChartSeries

chartSeries(APPL.Co, 
            type = c("auto", "candlesticks"), 
            subset = '2024-01::',
            show.grid = TRUE,
            major.ticks='auto', minor.ticks=TRUE,
            TA=c(addMACD(),addVo()))

This chart cosists of candle chart, MACD and volumn of the stock.

Adding more indicators

 library (TTR)

chartSeries(APPL.Co, 
            type = c("auto", "candlesticks"), 
            subset = '2023-01::',
            show.grid = TRUE,
            major.ticks='auto', minor.ticks=TRUE,
            multi.col = FALSE,
            TA=c(addMACD(),addVo(),addSMA(n=200,col = 'blue'),addSMA(n=50,col = 'red'),addSMA(n=22,col = 'green'),
            addROC(n=200,col = 'blue'),addROC(n=50,col = 'red'),addROC(n=22,col = 'green'))) # rate of change

This chart is more compact one as it consists of candle chart,MACD,vol, SMA and ROC. SMA (Simple Moving Average) is a technical indicator of the average price of a security over a specific period.If the SMA is moving up, the trend is up. If the SMA is moving down, the trend is down. A 200-bar SMA is common proxy for the long term trend. 50-bar SMAs are typically used to gauge the intermediate trend. Shorter period SMAs can be used to determine shorter term trends. Here, SMA200, SMA50 and SMA22 are used. ROC(Rate of Change) measures the percentage change in price over a specific period.It identifies overbought/oversold conditions,measures momentum and speed of price changes and used in conjunction with other indicators for signals.A high ROC may indicate an overbought condition, while a low ROC may indicate an oversold condition.

Custom indicator

chartSeries(APPL.Co, theme=chartTheme('white'), up.col="black",
 dn.col="black")

chartSeries(APPL.Co, theme=chartTheme('white'),
            type = c("auto", "matchsticks"), 
            subset = '2023-01::',
            show.grid = TRUE,
            major.ticks='auto', minor.ticks=TRUE,
            multi.col = FALSE,
            TA=c(addMACD(),addVo(),addADX(n = 14, maType = "EMA")))

This chart is to show a compact information of the candle chart, MACD, volumns and the sell and buy of the stock data in the market.