rm(list=ls())
library(ggplot2)
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)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
Raut <- read.csv("C:/Users/CHOME/OneDrive/Desktop/R/Raut.csv")
View(Raut)
colnames(Raut) <- c("Date", "Price", "Return","Open", "High","low")
Raut$Date <- as.Date(Raut$Date, format="%m/%d/%Y")
Raut$Price <- as.numeric(gsub(",", "", Raut$Price))
Raut$Return <- as.numeric(gsub("%", "", Raut$Return)) / 100
Raut$Open <- as.numeric(gsub(",", "", Raut$Open))
Raut$High <- as.numeric(gsub(",", "", Raut$High))
Raut$low <- as.numeric(gsub(",", "", Raut$low))
str(Raut)
## 'data.frame': 60 obs. of 6 variables:
## $ Date : Date, format: "2020-01-01" "2020-02-01" ...
## $ Price : num 4470 4480 4008 4008 4060 ...
## $ Return: num NA 0.0024 -0.1053 0 0.013 ...
## $ Open : num 4453 4470 4480 4008 4008 ...
## $ High : num 4550 4827 4511 4008 4060 ...
## $ low : num 4010 4375 3593 4008 3998 ...
summary(Raut)
## Date Price Return Open
## Min. :2020-01-01 Min. :3989 Min. :-0.105300 Min. :3989
## 1st Qu.:2021-03-24 1st Qu.:5272 1st Qu.:-0.020500 1st Qu.:5272
## Median :2022-06-16 Median :6180 Median :-0.000900 Median :6196
## Mean :2022-06-16 Mean :5816 Mean : 0.003607 Mean :5808
## 3rd Qu.:2023-09-08 3rd Qu.:6341 3rd Qu.: 0.015500 3rd Qu.:6354
## Max. :2024-12-01 Max. :7329 Max. : 0.157700 Max. :7329
## NA's :1
## High low
## Min. :4008 Min. :3593
## 1st Qu.:5339 1st Qu.:5248
## Median :6214 Median :6177
## Mean :5926 Mean :5723
## 3rd Qu.:6367 3rd Qu.:6322
## Max. :7411 Max. :6869
##
Graph_1
ggplot(Raut, aes(x = Date, y = Price)) +
geom_line(color = "blue", size = 1) +
labs(title = "DSEX Index Price Over Time", x = "Date", y = "Price") +
scale_x_date(date_breaks = "6 month", date_labels = "%Y") +
theme_minimal()
Yearly movement of DSEX from 2020 to 2024 is depicted in the file where we can see how the DSEX goes up after Covid 19 and how 2024 August movement impact the stock market.From 2021 to 2023 the movement was a bit stable but then it decline.
Graph_2
ggplot(Raut, aes(x = Date, y = Return)) +
geom_line(color = "red", size = 1) +
labs(title = " DSEX Index Return Over Time", x = "Date", y = "Return") +
scale_x_date(date_breaks = "6 month", date_labels = "%Y")
The graph above depicts the evolution of average return of DSEX year wise from 2020 to 2024. The return fluctuation appears unpredictable because there are loots of ups and downs. The two highest ups and downs were occurred in 2020 and 2024 which could be due to the COVID 19 and movement happened in 2024 August.
Graph_3
ggplot(Raut, aes(x = Return)) +
geom_density(fill = "pink", alpha = 0.5) +
geom_vline(aes(xintercept = mean(Return, na.rm = TRUE)),
color = "blue", linetype = "dashed", size = 1) +
labs(title = "Bell Curve of Returns", x = "Return", y = "Density") +
theme_minimal()
From the Bell curve of monthly return of DSEX we can say that its a leptokurtic and positively skewed. The blue line represent the mean return in the above graph
Graph_4
ggplot(Raut, aes(x = Return, y = Price)) +
geom_point(color = "blue", size = 2, alpha = 0.6) +
geom_smooth(method = "lm", color = "red", linetype = "solid", se = FALSE) +
labs(title = "Scatter Plot of Price vs Return with Trend Line", x = "Return (%)", y = "Price") +
theme_minimal()
## `geom_smooth()` using formula = 'y ~ x'
From the given above scatter plot of DSEX with return trend line, the relation is not correlated because the behavior of DSEX Index and return looks very fragile or the dots are away from the red line which is showing the average return.
Graph_5
Raut$Price <- as.numeric(gsub(",", "", Raut$Price))
summary(Raut$Price)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 3989 5272 6180 5816 6341 7329
summary(Raut$Open)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 3989 5272 6196 5808 6354 7329
summary(Raut$High)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 4008 5339 6214 5926 6367 7411
summary(Raut$Low)
## Length Class Mode
## 0 NULL NULL
fig <- Raut %>%
plot_ly(x = ~Date, type = "candlestick",
open = ~Open, high = ~High, low = ~low, close = ~Price) %>%
layout(title = "DSEX Candlestick Chart 2020 to 2024",
xaxis = list(title = "Date"),
yaxis = list(title = "Price"))
fig
Figure above shows the candlestick chart of DSEX index and their high low price based on the DSEX index data.
Thank you