Short-run performance analysis using technical on this selected stock.

We will be fetching the data(Historic data) from the website(yahoo) on selected stock.

Selected stock- Asian Paints Limited

List of 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
library(xts)
library(rvest)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.4     ✔ tibble    3.2.1
## ✔ lubridate 1.9.3     ✔ tidyr     1.3.0
## ✔ purrr     1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter()         masks stats::filter()
## ✖ dplyr::first()          masks xts::first()
## ✖ readr::guess_encoding() masks rvest::guess_encoding()
## ✖ dplyr::lag()            masks stats::lag()
## ✖ dplyr::last()           masks xts::last()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(stringr)
library(forcats)
library(lubridate)
library(plotly)
## 
## Attaching package: 'plotly'
## 
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## 
## The following object is masked from 'package:stats':
## 
##     filter
## 
## The following object is masked from 'package:graphics':
## 
##     layout
library(dplyr)
library(PerformanceAnalytics)
## 
## Attaching package: 'PerformanceAnalytics'
## 
## The following object is masked from 'package:graphics':
## 
##     legend

Let us set start date and end date to fetch the data from yahoo

start <- as.Date("2023-01-01")
end <- as.Date("2023-11-24")
getSymbols("ASIANPAINT.NS", src = "yahoo", from =start, to=end)
## [1] "ASIANPAINT.NS"

Exploring the Dataset

head(ASIANPAINT.NS)
##            ASIANPAINT.NS.Open ASIANPAINT.NS.High ASIANPAINT.NS.Low
## 2023-01-02            3087.90            3087.90           3021.00
## 2023-01-03            3047.00            3059.95           3025.00
## 2023-01-04            3035.00            3050.00           3001.55
## 2023-01-05            3039.55            3046.60           2995.40
## 2023-01-06            3010.00            3023.50           2952.00
## 2023-01-09            2993.30            3017.65           2951.00
##            ASIANPAINT.NS.Close ASIANPAINT.NS.Volume ASIANPAINT.NS.Adjusted
## 2023-01-02             3047.25              1015990               3021.817
## 2023-01-03             3028.25               860367               3002.975
## 2023-01-04             3016.85               836382               2991.670
## 2023-01-05             3004.35              1113920               2979.275
## 2023-01-06             2978.40              1045526               2953.541
## 2023-01-09             2984.15               808263               2959.243
tail(ASIANPAINT.NS)
##            ASIANPAINT.NS.Open ASIANPAINT.NS.High ASIANPAINT.NS.Low
## 2023-11-16             3119.0            3140.90           3097.60
## 2023-11-17             3150.0            3228.25           3145.65
## 2023-11-20             3168.9            3171.90           3132.00
## 2023-11-21             3156.9            3156.90           3127.00
## 2023-11-22             3140.0            3157.00           3121.20
## 2023-11-23             3148.0            3171.40           3115.15
##            ASIANPAINT.NS.Close ASIANPAINT.NS.Volume ASIANPAINT.NS.Adjusted
## 2023-11-16             3130.30               675454                3130.30
## 2023-11-17             3168.90              1430175                3168.90
## 2023-11-20             3140.35               406431                3140.35
## 2023-11-21             3133.25               409069                3133.25
## 2023-11-22             3133.00               489889                3133.00
## 2023-11-23             3122.95               792460                3122.95
plot(ASIANPAINT.NS[,"ASIANPAINT.NS.Close"], main = "ASIANPAINT.NS")

2nd way to fetch required data
plot(ASIANPAINT.NS$ASIANPAINT.NS.Close)

Candle chart

candleChart(ASIANPAINT.NS, up.col="green", dn.col="red", theme = "white")

Let us get Nifty index adding the ASIANPAINT.NS.

start <- as.Date("2023-01-01")
end <- as.Date("2023-11-24")
getSymbols("^NSEI", src = "yahoo", from =start, to=end)
## [1] "NSEI"

Exploring the Dataset

head(NSEI)
##            NSEI.Open NSEI.High NSEI.Low NSEI.Close NSEI.Volume NSEI.Adjusted
## 2023-01-02  18131.70  18215.15 18086.50   18197.45      256100      18197.45
## 2023-01-03  18163.20  18251.95 18149.80   18232.55      208700      18232.55
## 2023-01-04  18230.65  18243.00 18020.60   18042.95      235200      18042.95
## 2023-01-05  18101.95  18120.30 17892.60   17992.15      269900      17992.15
## 2023-01-06  18008.05  18047.40 17795.55   17859.45      238200      17859.45
## 2023-01-09  17952.55  18141.40 17936.15   18101.20      257200      18101.20
tail(NSEI)
##            NSEI.Open NSEI.High NSEI.Low NSEI.Close NSEI.Volume NSEI.Adjusted
## 2023-11-16  19674.70  19875.25 19627.00   19765.20      282700      19765.20
## 2023-11-17  19674.75  19806.00 19667.45   19731.80      236800      19731.80
## 2023-11-20  19731.15  19756.45 19670.50   19694.00      173800      19694.00
## 2023-11-21  19770.90  19829.10 19754.05   19783.40      195000      19783.40
## 2023-11-22  19784.00  19825.55 19703.85   19811.85      184500      19811.85
## 2023-11-23  19828.45  19875.15 19786.75   19802.00      170000      19802.00
plot(NSEI[,"NSEI.Close"], main = "NSEI")

plot(NSEI$NSEI.Close)

Candle chart

candleChart(NSEI, up.col="green", dn.col="red", theme = "white")

To check top 10 and bottom stock prices.

head(list(ASIANPAINT.NS,NSEI))
## [[1]]
##            ASIANPAINT.NS.Open ASIANPAINT.NS.High ASIANPAINT.NS.Low
## 2023-01-02            3087.90            3087.90           3021.00
## 2023-01-03            3047.00            3059.95           3025.00
## 2023-01-04            3035.00            3050.00           3001.55
## 2023-01-05            3039.55            3046.60           2995.40
## 2023-01-06            3010.00            3023.50           2952.00
## 2023-01-09            2993.30            3017.65           2951.00
## 2023-01-10            2984.15            2985.00           2952.20
## 2023-01-11            2974.90            2974.90           2935.00
## 2023-01-12            2939.00            2939.85           2896.00
## 2023-01-13            2925.00            2925.00           2871.75
##        ...                                                        
## 2023-11-09            3100.00            3111.40           3074.05
## 2023-11-10            3070.00            3085.00           3040.10
## 2023-11-13            3098.00            3098.00           3065.00
## 2023-11-15            3085.70            3118.85           3078.70
## 2023-11-16            3119.00            3140.90           3097.60
## 2023-11-17            3150.00            3228.25           3145.65
## 2023-11-20            3168.90            3171.90           3132.00
## 2023-11-21            3156.90            3156.90           3127.00
## 2023-11-22            3140.00            3157.00           3121.20
## 2023-11-23            3148.00            3171.40           3115.15
##            ASIANPAINT.NS.Close ASIANPAINT.NS.Volume ASIANPAINT.NS.Adjusted
## 2023-01-02             3047.25              1015990               3021.817
## 2023-01-03             3028.25               860367               3002.975
## 2023-01-04             3016.85               836382               2991.670
## 2023-01-05             3004.35              1113920               2979.275
## 2023-01-06             2978.40              1045526               2953.541
## 2023-01-09             2984.15               808263               2959.243
## 2023-01-10             2960.35               864325               2935.642
## 2023-01-11             2940.40               890426               2915.858
## 2023-01-12             2915.95              1558620               2891.613
## 2023-01-13             2909.15              1507864               2884.869
##        ...                                                                
## 2023-11-09             3080.20               849702               3080.200
## 2023-11-10             3076.45               364232               3076.450
## 2023-11-13             3085.60               405941               3085.600
## 2023-11-15             3116.20               700017               3116.200
## 2023-11-16             3130.30               675454               3130.300
## 2023-11-17             3168.90              1430175               3168.900
## 2023-11-20             3140.35               406431               3140.350
## 2023-11-21             3133.25               409069               3133.250
## 2023-11-22             3133.00               489889               3133.000
## 2023-11-23             3122.95               792460               3122.950
## 
## [[2]]
##            NSEI.Open NSEI.High NSEI.Low NSEI.Close NSEI.Volume NSEI.Adjusted
## 2023-01-02  18131.70  18215.15 18086.50   18197.45      256100      18197.45
## 2023-01-03  18163.20  18251.95 18149.80   18232.55      208700      18232.55
## 2023-01-04  18230.65  18243.00 18020.60   18042.95      235200      18042.95
## 2023-01-05  18101.95  18120.30 17892.60   17992.15      269900      17992.15
## 2023-01-06  18008.05  18047.40 17795.55   17859.45      238200      17859.45
## 2023-01-09  17952.55  18141.40 17936.15   18101.20      257200      18101.20
## 2023-01-10  18121.30  18127.60 17856.00   17914.15      283300      17914.15
## 2023-01-11  17924.25  17976.35 17824.35   17895.70      259900      17895.70
## 2023-01-12  17920.85  17945.80 17761.65   17858.20      227800      17858.20
## 2023-01-13  17867.50  17999.35 17774.25   17956.60      256700      17956.60
##        ...                                                                  
## 2023-11-09  19457.40  19463.90 19378.35   19395.30      208400      19395.30
## 2023-11-10  19351.85  19451.30 19329.45   19425.35      152200      19425.35
## 2023-11-13  19486.75  19494.40 19414.75   19443.55      189300      19443.55
## 2023-11-15  19651.40  19693.20 19579.65   19675.45      291500      19675.45
## 2023-11-16  19674.70  19875.25 19627.00   19765.20      282700      19765.20
## 2023-11-17  19674.75  19806.00 19667.45   19731.80      236800      19731.80
## 2023-11-20  19731.15  19756.45 19670.50   19694.00      173800      19694.00
## 2023-11-21  19770.90  19829.10 19754.05   19783.40      195000      19783.40
## 2023-11-22  19784.00  19825.55 19703.85   19811.85      184500      19811.85
## 2023-11-23  19828.45  19875.15 19786.75   19802.00      170000      19802.00
tail(list(ASIANPAINT.NS,NSEI))
## [[1]]
##            ASIANPAINT.NS.Open ASIANPAINT.NS.High ASIANPAINT.NS.Low
## 2023-01-02            3087.90            3087.90           3021.00
## 2023-01-03            3047.00            3059.95           3025.00
## 2023-01-04            3035.00            3050.00           3001.55
## 2023-01-05            3039.55            3046.60           2995.40
## 2023-01-06            3010.00            3023.50           2952.00
## 2023-01-09            2993.30            3017.65           2951.00
## 2023-01-10            2984.15            2985.00           2952.20
## 2023-01-11            2974.90            2974.90           2935.00
## 2023-01-12            2939.00            2939.85           2896.00
## 2023-01-13            2925.00            2925.00           2871.75
##        ...                                                        
## 2023-11-09            3100.00            3111.40           3074.05
## 2023-11-10            3070.00            3085.00           3040.10
## 2023-11-13            3098.00            3098.00           3065.00
## 2023-11-15            3085.70            3118.85           3078.70
## 2023-11-16            3119.00            3140.90           3097.60
## 2023-11-17            3150.00            3228.25           3145.65
## 2023-11-20            3168.90            3171.90           3132.00
## 2023-11-21            3156.90            3156.90           3127.00
## 2023-11-22            3140.00            3157.00           3121.20
## 2023-11-23            3148.00            3171.40           3115.15
##            ASIANPAINT.NS.Close ASIANPAINT.NS.Volume ASIANPAINT.NS.Adjusted
## 2023-01-02             3047.25              1015990               3021.817
## 2023-01-03             3028.25               860367               3002.975
## 2023-01-04             3016.85               836382               2991.670
## 2023-01-05             3004.35              1113920               2979.275
## 2023-01-06             2978.40              1045526               2953.541
## 2023-01-09             2984.15               808263               2959.243
## 2023-01-10             2960.35               864325               2935.642
## 2023-01-11             2940.40               890426               2915.858
## 2023-01-12             2915.95              1558620               2891.613
## 2023-01-13             2909.15              1507864               2884.869
##        ...                                                                
## 2023-11-09             3080.20               849702               3080.200
## 2023-11-10             3076.45               364232               3076.450
## 2023-11-13             3085.60               405941               3085.600
## 2023-11-15             3116.20               700017               3116.200
## 2023-11-16             3130.30               675454               3130.300
## 2023-11-17             3168.90              1430175               3168.900
## 2023-11-20             3140.35               406431               3140.350
## 2023-11-21             3133.25               409069               3133.250
## 2023-11-22             3133.00               489889               3133.000
## 2023-11-23             3122.95               792460               3122.950
## 
## [[2]]
##            NSEI.Open NSEI.High NSEI.Low NSEI.Close NSEI.Volume NSEI.Adjusted
## 2023-01-02  18131.70  18215.15 18086.50   18197.45      256100      18197.45
## 2023-01-03  18163.20  18251.95 18149.80   18232.55      208700      18232.55
## 2023-01-04  18230.65  18243.00 18020.60   18042.95      235200      18042.95
## 2023-01-05  18101.95  18120.30 17892.60   17992.15      269900      17992.15
## 2023-01-06  18008.05  18047.40 17795.55   17859.45      238200      17859.45
## 2023-01-09  17952.55  18141.40 17936.15   18101.20      257200      18101.20
## 2023-01-10  18121.30  18127.60 17856.00   17914.15      283300      17914.15
## 2023-01-11  17924.25  17976.35 17824.35   17895.70      259900      17895.70
## 2023-01-12  17920.85  17945.80 17761.65   17858.20      227800      17858.20
## 2023-01-13  17867.50  17999.35 17774.25   17956.60      256700      17956.60
##        ...                                                                  
## 2023-11-09  19457.40  19463.90 19378.35   19395.30      208400      19395.30
## 2023-11-10  19351.85  19451.30 19329.45   19425.35      152200      19425.35
## 2023-11-13  19486.75  19494.40 19414.75   19443.55      189300      19443.55
## 2023-11-15  19651.40  19693.20 19579.65   19675.45      291500      19675.45
## 2023-11-16  19674.70  19875.25 19627.00   19765.20      282700      19765.20
## 2023-11-17  19674.75  19806.00 19667.45   19731.80      236800      19731.80
## 2023-11-20  19731.15  19756.45 19670.50   19694.00      173800      19694.00
## 2023-11-21  19770.90  19829.10 19754.05   19783.40      195000      19783.40
## 2023-11-22  19784.00  19825.55 19703.85   19811.85      184500      19811.85
## 2023-11-23  19828.45  19875.15 19786.75   19802.00      170000      19802.00

Let us get the multiple stocks into our study

getSymbols(c("ASIANPAINT.NS","^NSEI"), src = "yahoo", from =start,to=end)
## [1] "ASIANPAINT.NS" "NSEI"
stock <- as.xts(data.frame(NSEI=NSEI[,"NSEI.Close"], ASIANPAINT.NS=ASIANPAINT.NS[,"ASIANPAINT.NS.Close"]))

stock
##            NSEI.Close ASIANPAINT.NS.Close
## 2023-01-02   18197.45             3047.25
## 2023-01-03   18232.55             3028.25
## 2023-01-04   18042.95             3016.85
## 2023-01-05   17992.15             3004.35
## 2023-01-06   17859.45             2978.40
## 2023-01-09   18101.20             2984.15
## 2023-01-10   17914.15             2960.35
## 2023-01-11   17895.70             2940.40
## 2023-01-12   17858.20             2915.95
## 2023-01-13   17956.60             2909.15
##        ...                               
## 2023-11-09   19395.30             3080.20
## 2023-11-10   19425.35             3076.45
## 2023-11-13   19443.55             3085.60
## 2023-11-15   19675.45             3116.20
## 2023-11-16   19765.20             3130.30
## 2023-11-17   19731.80             3168.90
## 2023-11-20   19694.00             3140.35
## 2023-11-21   19783.40             3133.25
## 2023-11-22   19811.85             3133.00
## 2023-11-23   19802.00             3122.95
plot(as.zoo(stock), screens = 2, lty = 1:2, xlab = "Date", ylab = "Price")

legend("topleft", c("TATASTEEL.NS","JINDALSTEEL.NS","JSWSTEEL.NS"), LTY=1:3, cex = 0.5)

Let us calculate the returns

library(magrittr)
## 
## Attaching package: 'magrittr'
## The following object is masked from 'package:purrr':
## 
##     set_names
## The following object is masked from 'package:tidyr':
## 
##     extract
stock_return <- apply(stock, 1, function(x) {x / stock[1,]}) %>% t %>% as.xts

stock_return
##            NSEI.Close ASIANPAINT.NS.Close
## 2023-01-02  1.0000000           1.0000000
## 2023-01-03  1.0019289           0.9937649
## 2023-01-04  0.9915098           0.9900238
## 2023-01-05  0.9887183           0.9859218
## 2023-01-06  0.9814260           0.9774058
## 2023-01-09  0.9947108           0.9792928
## 2023-01-10  0.9844319           0.9714825
## 2023-01-11  0.9834180           0.9649356
## 2023-01-12  0.9813573           0.9569120
## 2023-01-13  0.9867647           0.9546804
##        ...                               
## 2023-11-09  1.0658252           1.0108130
## 2023-11-10  1.0674765           1.0095824
## 2023-11-13  1.0684767           1.0125851
## 2023-11-15  1.0812202           1.0226269
## 2023-11-16  1.0861522           1.0272541
## 2023-11-17  1.0843168           1.0399212
## 2023-11-20  1.0822396           1.0305522
## 2023-11-21  1.0871524           1.0282222
## 2023-11-22  1.0887158           1.0281401
## 2023-11-23  1.0881745           1.0248421
plot(as.zoo(stock_return), screens = 2, lty = 1:3, xlab = "Date", ylab = "Price")

legend("topleft", c("ASIANPAINTS.NS","NESI"), lyt = 1:3, cex = 0.5)

making our returns more accurate and insightful perspective on investment

stock_change <- stock %>% log%>% diff
head(stock_change)
##              NSEI.Close ASIANPAINT.NS.Close
## 2023-01-02           NA                  NA
## 2023-01-03  0.001927070        -0.006254650
## 2023-01-04 -0.010453518        -0.003771622
## 2023-01-05 -0.002819410        -0.004152002
## 2023-01-06 -0.007402837        -0.008675060
## 2023-01-09  0.013445455         0.001928706
plot(as.zoo(stock_change), screens = 2, lty = 1:3, xlab = "Date", ylab = "Price")
legend("topleft", c("ASIANPAINTS.NS","NESI"), lyt = 1:3, cex = 0.5)

Simple Moving Averages

candleChart(ASIANPAINT.NS, up.col="green", dn.col="red", theme = "white")

addSMA(n=20)

addSMA(n=c(20,50,200), col = c("green","red","blue"))

CONCLUSION

The 50-day moving average is above the 200-day moving average, which is a bullish sign. This indicates that the stock is in an uptrend.

The technical analysis suggests that Asian Paints Ltd. is in a good position for continued growth. However, investors should be aware of the overbought RSI and the possibility of a pullback.