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.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
start <- as.Date("2021-04-01")
end <- as.Date("2023-03-31")
getSymbols("RELIANCE.NS", src = "yahoo", from =start,to=end)
## [1] "RELIANCE.NS"
head(RELIANCE.NS)
## RELIANCE.NS.Open RELIANCE.NS.High RELIANCE.NS.Low RELIANCE.NS.Close
## 2021-04-01 2018.00 2030.00 2003.15 2021.85
## 2021-04-05 2024.95 2025.00 1962.10 1992.60
## 2021-04-06 2004.00 2004.95 1969.00 1984.30
## 2021-04-07 2000.00 2046.90 1993.30 2002.85
## 2021-04-08 2011.00 2022.00 1993.00 2005.35
## 2021-04-09 1998.45 2006.35 1980.00 1982.05
## RELIANCE.NS.Volume RELIANCE.NS.Adjusted
## 2021-04-01 5410307 2002.244
## 2021-04-05 6864856 1973.278
## 2021-04-06 6465241 1965.059
## 2021-04-07 11198918 1983.429
## 2021-04-08 7092878 1985.904
## 2021-04-09 6478482 1962.830
tail(RELIANCE.NS)
## RELIANCE.NS.Open RELIANCE.NS.High RELIANCE.NS.Low RELIANCE.NS.Close
## 2023-03-22 2285.00 2291.45 2270.00 2276.60
## 2023-03-23 2268.00 2269.90 2243.05 2247.80
## 2023-03-24 2245.25 2250.00 2198.00 2203.30
## 2023-03-27 2217.50 2254.00 2200.20 2237.55
## 2023-03-28 2245.00 2256.50 2237.00 2248.00
## 2023-03-29 2239.00 2244.80 2211.10 2234.70
## RELIANCE.NS.Volume RELIANCE.NS.Adjusted
## 2023-03-22 5039622 2268.586
## 2023-03-23 7499082 2239.888
## 2023-03-24 5711497 2195.544
## 2023-03-27 6486068 2229.674
## 2023-03-28 5804018 2240.087
## 2023-03-29 8678073 2226.834
plot(RELIANCE.NS[,"RELIANCE.NS.Close"],main = "RELIANCE.NS")
candleChart(RELIANCE.NS, up.col = "green",dn.col = "red",theme = "white")
start <- as.Date("2021-04-01")
end <- as.Date("2023-03-31")
getSymbols(c("RELIANCE.NS","^NSEI"), src = "yahoo", from =start,to=end)
## [1] "RELIANCE.NS" "NSEI"
head(list(RELIANCE.NS,NSEI))
## [[1]]
## RELIANCE.NS.Open RELIANCE.NS.High RELIANCE.NS.Low RELIANCE.NS.Close
## 2021-04-01 2018.00 2030.00 2003.15 2021.85
## 2021-04-05 2024.95 2025.00 1962.10 1992.60
## 2021-04-06 2004.00 2004.95 1969.00 1984.30
## 2021-04-07 2000.00 2046.90 1993.30 2002.85
## 2021-04-08 2011.00 2022.00 1993.00 2005.35
## 2021-04-09 1998.45 2006.35 1980.00 1982.05
## 2021-04-12 1959.00 1961.40 1900.25 1911.15
## 2021-04-13 1924.00 1940.60 1917.85 1931.80
## 2021-04-15 1926.30 1961.00 1913.00 1944.30
## 2021-04-16 1936.60 1949.90 1926.45 1932.10
## ...
## 2023-03-16 2243.00 2254.00 2202.20 2225.90
## 2023-03-17 2244.75 2251.95 2212.70 2223.10
## 2023-03-20 2215.00 2220.00 2180.00 2201.25
## 2023-03-21 2218.95 2274.00 2217.00 2269.70
## 2023-03-22 2285.00 2291.45 2270.00 2276.60
## 2023-03-23 2268.00 2269.90 2243.05 2247.80
## 2023-03-24 2245.25 2250.00 2198.00 2203.30
## 2023-03-27 2217.50 2254.00 2200.20 2237.55
## 2023-03-28 2245.00 2256.50 2237.00 2248.00
## 2023-03-29 2239.00 2244.80 2211.10 2234.70
## RELIANCE.NS.Volume RELIANCE.NS.Adjusted
## 2021-04-01 5410307 2002.244
## 2021-04-05 6864856 1973.278
## 2021-04-06 6465241 1965.059
## 2021-04-07 11198918 1983.429
## 2021-04-08 7092878 1985.904
## 2021-04-09 6478482 1962.830
## 2021-04-12 9646031 1892.618
## 2021-04-13 8958261 1913.068
## 2021-04-15 9102492 1925.446
## 2021-04-16 7225679 1913.365
## ...
## 2023-03-16 8474595 2218.065
## 2023-03-17 15697554 2215.275
## 2023-03-20 9010595 2193.501
## 2023-03-21 9876263 2261.711
## 2023-03-22 5039622 2268.586
## 2023-03-23 7499082 2239.888
## 2023-03-24 5711497 2195.544
## 2023-03-27 6486068 2229.674
## 2023-03-28 5804018 2240.087
## 2023-03-29 8678073 2226.834
##
## [[2]]
## NSEI.Open NSEI.High NSEI.Low NSEI.Close NSEI.Volume NSEI.Adjusted
## 2021-04-01 14798.40 14883.20 14692.45 14867.35 445000 14867.35
## 2021-04-05 14837.70 14849.85 14459.50 14637.80 509700 14637.80
## 2021-04-06 14737.00 14779.10 14573.90 14683.50 475300 14683.50
## 2021-04-07 14716.45 14879.80 14649.85 14819.05 0 14819.05
## 2021-04-08 14875.65 14984.15 14821.10 14873.80 514800 14873.80
## 2021-04-09 14882.65 14918.45 14785.65 14834.85 504100 14834.85
## 2021-04-12 14644.65 14652.50 14248.70 14310.80 650200 14310.80
## 2021-04-13 14364.90 14528.90 14274.90 14504.80 605100 14504.80
## 2021-04-15 14522.40 14597.55 14353.20 14581.45 568000 14581.45
## 2021-04-16 14599.60 14697.70 14559.00 14617.85 577200 14617.85
## ...
## 2023-03-16 16994.65 17062.45 16850.15 16985.60 349800 16985.60
## 2023-03-17 17111.80 17145.80 16958.15 17100.05 408100 17100.05
## 2023-03-20 17066.60 17066.60 16828.35 16988.40 241800 16988.40
## 2023-03-21 17060.40 17127.70 17016.00 17107.50 246700 17107.50
## 2023-03-22 17177.45 17207.25 17107.85 17151.90 0 17151.90
## 2023-03-23 17097.40 17205.40 17045.30 17076.90 219200 17076.90
## 2023-03-24 17076.20 17109.45 16917.35 16945.05 228000 16945.05
## 2023-03-27 16984.30 17091.00 16918.55 16985.70 218400 16985.70
## 2023-03-28 17031.75 17061.75 16913.75 16951.70 238800 16951.70
## 2023-03-29 16977.30 17126.15 16940.60 17080.70 345900 17080.70
stocks <- as.xts(data.frame(RELIANCE.NS=RELIANCE.NS[,"RELIANCE.NS.Close"],NSEI= NSEI[,"NSEI.Close"]))
stocks
## RELIANCE.NS.Close NSEI.Close
## 2021-04-01 2021.85 14867.35
## 2021-04-05 1992.60 14637.80
## 2021-04-06 1984.30 14683.50
## 2021-04-07 2002.85 14819.05
## 2021-04-08 2005.35 14873.80
## 2021-04-09 1982.05 14834.85
## 2021-04-12 1911.15 14310.80
## 2021-04-13 1931.80 14504.80
## 2021-04-15 1944.30 14581.45
## 2021-04-16 1932.10 14617.85
## ...
## 2023-03-16 2225.90 16985.60
## 2023-03-17 2223.10 17100.05
## 2023-03-20 2201.25 16988.40
## 2023-03-21 2269.70 17107.50
## 2023-03-22 2276.60 17151.90
## 2023-03-23 2247.80 17076.90
## 2023-03-24 2203.30 16945.05
## 2023-03-27 2237.55 16985.70
## 2023-03-28 2248.00 16951.70
## 2023-03-29 2234.70 17080.70
head(stocks)
## RELIANCE.NS.Close NSEI.Close
## 2021-04-01 2021.85 14867.35
## 2021-04-05 1992.60 14637.80
## 2021-04-06 1984.30 14683.50
## 2021-04-07 2002.85 14819.05
## 2021-04-08 2005.35 14873.80
## 2021-04-09 1982.05 14834.85
plot(as.zoo(stocks),screens = 1, lty = 1:2 ,xlab = "Date", ylab = "price")
legend("topleft",c("RELIANCE.NS","NSEI"), lty = 1:2 ,cex = 0.5)
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(stocks, 1, function(x) {x / stocks[1,]}) %>% t %>% as.xts
head(stock_return)
## RELIANCE.NS.Close NSEI.Close
## 2021-04-01 1.0000000 1.0000000
## 2021-04-05 0.9855331 0.9845601
## 2021-04-06 0.9814279 0.9876340
## 2021-04-07 0.9906027 0.9967513
## 2021-04-08 0.9918392 1.0004338
## 2021-04-09 0.9803151 0.9978140
plot(as.zoo(stocks),screens = 2, lty = 1:2 ,xlab = "Date", ylab = "price")
legend("topleft",c("RELIANCE.NS","NSEI"), lty = 1:2 , cex = 0.5)
stock_change <- stocks %>% log%>% diff
head(stock_change)
## RELIANCE.NS.Close NSEI.Close
## 2021-04-01 NA NA
## 2021-04-05 -0.014572615 -0.015560296
## 2021-04-06 -0.004174075 0.003117204
## 2021-04-07 0.009304922 0.009189088
## 2021-04-08 0.001247443 0.003687761
## 2021-04-09 -0.011686910 -0.002622147
plot(as.zoo(stock_change),screens = 3, lty = 1:2 , xlab = "Date", ylab = "price")
legend("topleft",c("RELIANCE.NS","NSEI"), lty = 1:3 ,cex = 0.5)
candleChart(RELIANCE.NS, up.col = "green",dn.col = "red",theme = "white")
addSMA(n=20)
addSMA(n=c(20,50,200), col = c("green","red","blue"))
Overview: The chart of Reliance Industries (RELIANCE.NS) shows a strong
uptrend over the past two years. The stock has broken out of several
resistance levels and is currently trading at an all-time high. The
volume has also been increasing throughout the uptrend, which is a
bullish sign.
The 50- and 200-day moving averages are both sloping upwards, which
indicates that the uptrend is likely to continue. The stock is currently
trading above both moving averages, which is another bullish sign.
The nearest support level for Reliance Industries is at 2200. This level
has previously acted as support and resistance on multiple occasions.
The nearest resistance level is at 2800. This level is the all-time high
for the stock.
The technical analysis of Reliance Industries is bullish. The stock is
in a strong uptrend and is trading above its moving averages and support
levels.