ibm<- read.csv("ibm_price-history-03-27-2019.csv", header = TRUE, stringsAsFactors = FALSE)
ibm<- ibm[-253,]
seq<- c(1:252)
ibm<-ibm[252:1,]
ibm$seq<- seq
ibm$Open<-as.numeric(ibm$Open)
ibm$Time<- as.Date(ibm$Time,format = "%m/%d/%y")
Here is a graph of one years worth of price data from IBM. I decided arbitrarily to use the opening price as the comparison.
ggplot(data = ibm, aes(x= Time,y= Open))+
geom_line()+
xlab("")+
labs(
x='time',
y='Price at Open',
title= 'IBM Stock Price'
)
ibm<- ibm%>%mutate(thirty.ma= rollmean(Open, k=30, fill= NA))
ibm<- ibm%>%mutate(ninty.ma= rollmean(Open, k=90, fill= NA))
ibm.final<- na.omit(ibm)
ggplot(data = ibm.final, aes(x= Time,y= Open))+
geom_line(aes(y= thirty.ma), col= 'blue')+
geom_line(aes(y= ninty.ma), col= 'red')+
geom_line(aes(y=Open), col= 'purple')+
xlab("")+
labs(
x='time',
y='Price at Open',
title= 'IBM Stock Price with 30 day ma and 90ma')
Here is the chart of the moving averages. I was unable to figure out how to make a nice legend so here is what each line represents.The open price of the day is represented by the purple line.The red line represents the ninty day moving average. Finally, the thirty day moving average is represented by the blue line. The comparison plot cuts out about 90 days worth of data due to the 90 day average needing 90 days of price information to start the plot. The graph also ends on January 22, 2019 which is a 64 day time difference from the original. I am not entirly sure as to the reason why it ends here but I think it may be due the package. Techniqually the simple moving average should include up to the current date.
As for an interpretation, I belive when the 30 day moving average crosses below the 90 day moving average would be considered a sell signal. Currently, it looks like the 30 day ma close to crossing the 90ma whuch would indicate a buy signal.