Showing posts with label stock price data. Show all posts
Showing posts with label stock price data. Show all posts

Tuesday, October 1, 2019

stock price data for AAPL and plots two segments for each day

  How to obtain stock price data for AAPL and plots two segments for each day

stockprice


dat <- as.data.frame(msft)
> dat$date <- index(msft)
> dat <- subset(dat, date >= "2016-01-01")
> names(dat) <- sub("^MSFT\\.", "", names(dat))
>
> plot_ly(dat, x = ~date, xend = ~date, color = ~Close > Open,
+         colors = c("red", "forestgreen"), hoverinfo = "none") %>%
+   
+ add_segments(y = ~Low, yend = ~High, size = I(1)) %>%
+     add_segments(y = ~Open, yend = ~Close, size = I(3)) %>%
+     layout(showlegend = FALSE, yaxis = list(title = "Price")) %>%
+     rangeslider()
> aapl <- getSymbols("AAPL", auto.assign = F)
> dat <- as.data.frame(aapl)
> dat$date <- index(aapl)
> dat <- subset(dat, date >= "2016-01-01")
>
> names(dat) <- sub("^AAPL\\.", "", names(dat))
> plot_ly(dat, x = ~date, xend = ~date, color = ~Close > Open,
+         colors = c("red", "forestgreen"), hoverinfo = "none") %>%
+     add_segments(y = ~Low, yend = ~High, size = I(1)) %>%
+     add_segments(y = ~Open, yend = ~Close, size = I(3)) %>%
+     layout(showlegend = FALSE, yaxis = list(title = "Price")) %>%
+     rangeslider()

> kerns <- c("gaussian", "epanechnikov", "rectangular",
+            "triangular", "biweight", "cosine", "optcosine")

> p <- plot_ly()
> for (k in kerns) {
+     d <- density(economics$pce, kernel = k, na.rm = TRUE)
+     p <- add_lines(p, x = d$x, y = d$y, name = k)
+ }
> p
gaussian", "epanechnikov", "rectangular", "triangular", "biweight", "cosine", "optcosine


Black-Scholes formula-R

 Black-Scholes formula-R > BlackScholes <- function(TypeFlag = c("c", "p"), S, X, Time, r, b, sigma) { TypeFla...