Short-run performance analysis using Technical Analysis on Vedanta Ltd. and Nifty 50.

We will be fetching the data from the website yahoo finance

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.4     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ 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
library(magrittr)
## 
## Attaching package: 'magrittr'
## 
## The following object is masked from 'package:purrr':
## 
##     set_names
## 
## The following object is masked from 'package:tidyr':
## 
##     extract

Lets set the start date and the end date to feach the data from yahoo

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

Exploring the Dataset

head(VEDL.NS)
##            VEDL.NS.Open VEDL.NS.High VEDL.NS.Low VEDL.NS.Close VEDL.NS.Volume
## 2023-01-02       309.95        318.0      309.20        316.10       13487019
## 2023-01-03       316.10        321.6      314.25        319.55       10680716
## 2023-01-04       318.00        318.4      306.20        308.30       16035314
## 2023-01-05       310.00        312.0      307.45        311.35        6589413
## 2023-01-06       312.25        314.5      308.60        309.65        4971988
## 2023-01-09       312.20        316.9      312.20        315.50        6356082
##            VEDL.NS.Adjusted
## 2023-01-02         264.8611
## 2023-01-03         267.7519
## 2023-01-04         258.3255
## 2023-01-05         260.8811
## 2023-01-06         259.4566
## 2023-01-09         264.3584
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

Ploting the closing price movement of stock and index

Vedanta Ltd.

plot(VEDL.NS[,"VEDL.NS.Close"], main ="Vedanta Ltd. Closing Price Movement")

There is a large volume of share dumped in the month of august where the the share price has droped significatly from around ₹ 280 per share to around ₹ 240 per share

Vedanta Ltd. is in a falling trend channel, as evidenced by the red 20-day SMA sloping downwards below the blue 50-day SMA.

NIFTY 50

plot(NSEI[,"NSEI.Close"], main = "NIFTY50 Closing Price Movement")

Meanwhile the NIFTY is seen to be showing an upward trend for the observed period.

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

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

NIFTY is in a bullish trend channel, as evidenced by the red 20-day SMA sloping upwards above the blue 50-day SMA. The index has recently broken out of its resistance level at 19500, which is a bullish signal.

Let us make a new data frame consisting of daily closing price of our stock and index

closing <- as.xts(data.frame(VEDL.NS[,"VEDL.NS.Close"],NSEI[,"NSEI.Close"]))
head(closing)
##            VEDL.NS.Close NSEI.Close
## 2023-01-02        316.10   18197.45
## 2023-01-03        319.55   18232.55
## 2023-01-04        308.30   18042.95
## 2023-01-05        311.35   17992.15
## 2023-01-06        309.65   17859.45
## 2023-01-09        315.50   18101.20

Let us calculate the returns

closing_change <- closing %>% log %>% diff
head(closing_change)
##            VEDL.NS.Close   NSEI.Close
## 2023-01-02            NA           NA
## 2023-01-03   0.010855079  0.001927070
## 2023-01-04  -0.035840423 -0.010453518
## 2023-01-05   0.009844406 -0.002819410
## 2023-01-06  -0.005475093 -0.007402837
## 2023-01-09   0.018716074  0.013445455

Now let us plot the return of our stock and index in a single graph to better compare their return.

plot(as.zoo(closing_change),screens = 1, lty = 1:2, xlab ="Data",  ylab= "Price")
legend("topleft",c("VEDL.NS","NSEI"), lty = 1:2, cex = .5)

From the avobe graph we can observe that the return of vedanta ltd. is more in negative and the deviation is comparatively more when compaired to NIFTY50 and also the return from NIFTY 50 is consistently positive.