[datatable-help] Having a problem with plotting: Error in plot.window(...) : infinite axis extents [GEPretty(-inf, inf, 5)]

porcupine_racer jason.fukunaga at gmail.com
Sun Mar 25 08:57:06 CEST 2018


I'm having some issue with generating the plots for this code, I'm not sure
why. Also, the dates are applying 1970, instead of the correct 2015 year,
can anyone help please? I'm an uber noob when it comes to all this coding :(

I keep getting this code for part of my code, and the solution may be
nonunique for almost all, even though plots are produced.

Error in plot.window(...) : infinite axis extents [GEPretty(-inf,inf,5)]
In addition: Warning messages:
1: In rq.fit.br(x, y, tau = tau, ci = TRUE, ...) :
  Solution may be nonunique
2: In rq.fit.br(x, y, tau = tau, ci = TRUE, ...) :
  Solution may be nonunique
3: In rq.fit.br(x, y, tau = tau, ci = TRUE, ...) :
  Solution may be nonunique
4: In rq.fit.br(x, y, tau = tau, ci = TRUE, ...) :
  Solution may be nonunique



Here's my code:

---
  title: "Final_Project"
output: 
  flexdashboard::flex_dashboard:
  orientation: columns
vertical_layout: fill
runtime: shiny

---
  
  ```{r setup, include=FALSE}

library(ggplot2)
library(flexdashboard)
library(shiny)
library(QRM)
library(qrmdata)
library(xts)
library(zoo)
library(psych)
library(quadprog)
library(matrixStats)
library(quantreg)
library(moments)
library(plotly)
library(quantmod)
library(TTS)

rm(list = ls())

start <- as.Date("2015-01-01")
end <- as.Date("2017-12-31")
tickers <- c("GOOG","AMZN","AAPL","MSFT","GOVT")
asset.price <- NULL
#download stock prices of four stocks through for loop
for(ticker in tickers)
  asset.price <- cbind(asset.price,getSymbols(ticker, from = start, to =
end,auto.assign = F))

cls.price <- asset.price[,c(4,10,16,22)]#this will select only the closing
price
head(cls.price)
RF <- asset.price[,28]
rf.rate <- RF/365
rf.mean <- mean(rf.rate)
plot(cls.price)
colnames(cls.price) <- tickers[-5]
class(cls.price)

#method 1 of calculating return
asset.ret <- ROC(cls.price,type="discrete")*100
class(asset.ret)
head(asset.ret)
asset.ret.df <- data.frame(na.omit(asset.ret))

class(asset.ret.df)
ccf.values <- ccf(asset.ret.df[,1],asset.ret.df[,2])
plot(ccf.values)


```


Sensitivity Analysis
=======================================================================
  
  Row {.tabset .tabset-fade}
-----------------------------------------------------------------------
  
  ### GOOG-AMZN {data-height=650}
  
  ```{r}

data.r <- diff(log(as.matrix(cls.price)))*100
# Create size and direction
size <- na.omit(abs(data.r)) # size is indicator of volatility
colnames(size) <- paste(colnames(size),
                        ".size", sep = "") # Teetor
direction <- ifelse(data.r > 0, 1, ifelse(data.r <
                                            0, -1, 0)) # another indicator
of volatility
colnames(direction) <- paste(colnames(direction),
                             ".dir", sep = "")


dates <- as.Date(index(data.r))
dates.chr <- as.character(index(data.r))
# str(dates.chr)

values <- cbind(data.r, size, direction)
data.df <- data.frame(dates = dates,
                      returns = data.r, size = size, direction = direction)

data.xts <- na.omit(as.xts(values, dates)) #order.by=as.Date(dates,
'%d/%m/%Y')))
# str(data.xts)

returns <- data.xts

corr.rolling <- function(x) {
  dim <- ncol(x)
  corr.r <- cor(x)[lower.tri(diag(dim),
                             diag = FALSE)]
  return(corr.r)
}
ALL.r <- data.xts[, 1:4] # Only four series here
window <- 90 #reactive({input$window})
corr.returns <- rollapply(ALL.r, width = window,
                          corr.rolling, align = "right", by.column = FALSE)
colnames(corr.returns) <- c('Google & Amazon', 'Google & Apple', 'Google &
Microsoft', 'Amazon & Apple', 'Amazon & Microsoft', 'Apple & Microsoft')
corr.returns.df <- data.frame(Date = index(corr.returns),
                              GOOG.AMZN = corr.returns[, 1],
                              GOOG.AAPL = corr.returns[, 2], 
                              GOOG.MSFT = corr.returns[, 3],
                              AMZN.AAPL = corr.returns[, 4],
                              AMZN.MSFT = corr.returns[, 5],
                              AAPL.MSFT = corr.returns[, 6])
# Market dependencies

R.corr <- apply.monthly(as.xts(ALL.r),
                        FUN = cor)
R.vols <- apply.monthly(ALL.r, FUN = colSds) # from MatrixStats\t

# Form correlation matrix for one month
R.corr.1 <- matrix(R.corr[20, ], nrow = 4,
                   ncol = 4, byrow = FALSE)
rownames(R.corr.1) <- colnames(ALL.r[,
                                     1:4])
colnames(R.corr.1) <- rownames(R.corr.1)

# Correlation data
R.corr <- R.corr[, c(2, 3, 4, 7, 8, 12)]
colnames(R.corr) <- colnames(corr.returns)
colnames(R.vols) <- c("GOOG.vols", "AMZN.vols", "AAPL.vols", "MSFT.vols")
R.corr.vols <- na.omit(merge(R.corr,
                             R.vols))
GOOG.vols <- as.numeric(R.corr.vols[,"GOOG.vols"])
AMZN.vols <- as.numeric(R.corr.vols[,"AMZN.vols"])
AAPL.vols <- as.numeric(R.corr.vols[,"AAPL.vols"])
MSFT.vols <- as.numeric(R.corr.vols[,"MSFT.vols"])


GOOG.AMZN.corrs <- R.corr.vols[, 1]
taus <- seq(0.05, 0.95, 0.05) 
fit.rq.GOOG.AMZN <- rq(GOOG.AMZN.corrs ~
                         AMZN.vols, tau = taus)
fit.lm.GOOG.AMZN <- lm(GOOG.AMZN.corrs ~
                         AMZN.vols)
plot(summary(fit.rq.GOOG.AMZN), parm = "AMZN.vols",
     main = "Google-Amazon Correlation Sensitivity to Amazon Volatility")

```

### GOOG-AAPL

```{r}

GOOG.AAPL.corrs <- R.corr.vols[, 2]
taus <- seq(0.05, 0.95, 0.05) 
fit.rq.GOOG.AAPL <- rq(GOOG.AAPL.corrs ~
                         AAPL.vols, tau = taus)
fit.lm.GOOG.AAPL <- lm(GOOG.AAPL.corrs ~
                         AAPL.vols)
plot(summary(fit.rq.GOOG.AAPL), parm = "AAPL.vols",
     main = "Google-Apple Correlation Sensitivity to Apple Volatility")

```

### GOOG-MSFT

```{r}

GOOG.MSFT.corrs <- R.corr.vols[, 3]
taus <- seq(0.05, 0.95, 0.05) 
fit.rq.GOOG.MSFT <- rq(GOOG.MSFT.corrs ~
                         MSFT.vols, tau = taus)
fit.lm.GOOG.MSFT <- lm(GOOG.MSFT.corrs ~
                         MSFT.vols)
plot(summary(fit.rq.GOOG.MSFT), parm = "MSFT.vols",
     main = "Google-Microsoft Correlation Sensitivity to Microsoft
Volatility")

```

### AMZN-AAPL

```{r}

AMZN.AAPL.corrs <- R.corr.vols[, 4]
taus <- seq(0.05, 0.95, 0.05) 
fit.rq.AMZN.AAPL <- rq(AMZN.AAPL.corrs ~
                         AAPL.vols, tau = taus)
fit.lm.AMZN.AAPL <- lm(AMZN.AAPL.corrs ~
                         AAPL.vols)
plot(summary(fit.rq.AMZN.AAPL), parm = "AAPL.vols",
     main = "Amazon-Apple Correlation Sensitivity to Apple Volatility")

```

### AMZN-MSFT

```{r}

AMZN.MSFT.corrs <- R.corr.vols[, 5]
taus <- seq(0.05, 0.95, 0.05) 
fit.rq.AMZN.MSFT <- rq(AMZN.MSFT.corrs ~
                         MSFT.vols, tau = taus)
fit.lm.AMZN.MSFT <- lm(AMZN.MSFT.corrs ~
                         MSFT.vols)
plot(summary(fit.rq.AMZN.MSFT), parm = "MSFT.vols",
     main = "Amazon-Microsoft Correlation Sensitivity to Microsoft
Volatility")

```

### AAPL-MSFT

```{r}

AAPL.MSFT.corrs <- R.corr.vols[, 5]
taus <- seq(0.05, 0.95, 0.05) 
fit.rq.AAPL.MSFT <- rq(AAPL.MSFT.corrs ~
                         MSFT.vols, tau = taus)
fit.lm.AAPL.MSFT <- lm(AAPL.MSFT.corrs ~
                         MSFT.vols)
plot(summary(fit.rq.AAPL.MSFT), parm = "MSFT.vols",
     main = "Apple-Microsoft Correlation Sensitivity to Microsoft
Volatility")

```

Column {data-height=150}
-----------------------------------------------------------------------
  
  ### Explanation of Sensitivity Charts
  
Explain here


Thank you so much for any help you can give.
I'm sorry if this isn't the right way to post a message.

Jason



--
Sent from: http://r.789695.n4.nabble.com/datatable-help-f2315188.html


More information about the datatable-help mailing list