Can't plot a DCC model in Ubuntu (fine on Windows)


#1

I’m trying to plot in R (v. 3.4.3) the Conditional Sigma calculated on two time series using the package rmgarch. I run the script on Windows and it’s working fine, returning correctly the plot I need

while on Linux (Ubuntu 16.04) I get the error:

Error in mtext(paste("rmgarch  : DCC model fit"), side = 4, adj = 0, padj = 0,  : 
plot.new has not been called yet

This is the script I used:

library(PerformanceAnalytics)
library(quantmod)
library(rmgarch)

# download data   
symbol.vec = c("MSFT", "^GSPC")
getSymbols(symbol.vec, from ="2005-01-01", to = "2018-01-01")

# extract adjusted closing prices
MSFT = MSFT[, "MSFT.Adjusted", drop=F]
GSPC = GSPC[, "GSPC.Adjusted", drop=F]

# calculate log-returns
MSFT.ret = CalculateReturns(MSFT, method="log")
GSPC.ret = CalculateReturns(GSPC, method="log")

# remove first NA observation
MSFT.ret = MSFT.ret[-1,]
GSPC.ret = GSPC.ret[-1,]
colnames(MSFT.ret) ="MSFT"
colnames(GSPC.ret) = "GSPC"

# create combined data series
MSFT.GSPC.ret = merge(MSFT.ret,GSPC.ret)

# DCC estimation

# univariate normal GARCH(1,1) for each series
garch11.spec = ugarchspec(mean.model = list(armaOrder = c(0,0)), 
                          variance.model = list(garchOrder = c(1,1), 
                                                model = "sGARCH"), 
                          distribution.model = "norm")

# dcc specification - GARCH(1,1) for conditional correlations
dcc.garch11.spec = dccspec(uspec = multispec( replicate(2, garch11.spec) ), 
                           dccOrder = c(1,1), 
                           distribution = "mvnorm")

# fit DCC model
dcc.fit = dccfit(dcc.garch11.spec, data = MSFT.GSPC.ret)

# plot Conditional Sigma
plot(dcc.fit, which=2)

I’m not a linux expert so maybe is there some library I miss?


#2

Your code example should be in the form of a reproducible example which can easily be reproduced using the reprex package.

Here’s a tutorial on reprex’s https://www.tidyverse.org/help/

As is your code is not runable because it doesn’t load the rugarch package. It’s probably working on your Windows machine because it was already loaded into the session you ran your code. If instead you had used reprex to run it you would have spotted the missing package because a reprex always runs your code in a brand new session.

The main reason we would like code in reprex helps us help you by making it possible to run your code in the same environment as you. That way we spend less time working on issues unrelated to problem you are running into. Most everyone here who is answering questions is doing it in their spare time so you should do what you can to minimize the time they spend working out an answer. A reprex is the best way to do that.

Once I added the missing package to your code I got the same error as you… running on macOS.

Below is your code with plot.new() added. plot.new() cleans up the plot area so a new plot can be written into it. Now it plots but the plot are empty and one is missing.

My guess, and this is just a guess, there is something in the session you are running in on your Windows machine that is different than the session in your Ubuntu system.

Even outside of asking questions here reprex is a great development tool to catch errors like this.

If you have any issues getting a reprex to work please post a new topic with your questions about reprex. You will get all kinds of help to get it going.

suppressPackageStartupMessages(  library(PerformanceAnalytics))
suppressPackageStartupMessages(  library(quantmod))
suppressPackageStartupMessages(  library(rugarch))
suppressPackageStartupMessages(  library(rmgarch))

# download data
symbol.vec = c("MSFT", "^GSPC")
getSymbols(symbol.vec, from ="2005-01-01", to = "2018-01-01")
#> 'getSymbols' currently uses auto.assign=TRUE by default, but will
#> use auto.assign=FALSE in 0.5-0. You will still be able to use
#> 'loadSymbols' to automatically load data. getOption("getSymbols.env")
#> and getOption("getSymbols.auto.assign") will still be checked for
#> alternate defaults.
#> 
#> This message is shown once per session and may be disabled by setting 
#> options("getSymbols.warning4.0"=FALSE). See ?getSymbols for details.
#> 
#> WARNING: There have been significant changes to Yahoo Finance data.
#> Please see the Warning section of '?getSymbols.yahoo' for details.
#> 
#> This message is shown once per session and may be disabled by setting
#> options("getSymbols.yahoo.warning"=FALSE).
#> [1] "MSFT" "GSPC"

# extract adjusted closing prices
MSFT = MSFT[, "MSFT.Adjusted", drop=F]
GSPC = GSPC[, "GSPC.Adjusted", drop=F]

# calculate log-returns
MSFT.ret = CalculateReturns(MSFT, method="log")
GSPC.ret = CalculateReturns(GSPC, method="log")

# remove first NA observation
MSFT.ret = MSFT.ret[-1,]
GSPC.ret = GSPC.ret[-1,]
colnames(MSFT.ret) ="MSFT"
colnames(GSPC.ret) = "GSPC"

# create combined data series
MSFT.GSPC.ret = merge(MSFT.ret,GSPC.ret)

# DCC estimation

# univariate normal GARCH(1,1) for each series
garch11.spec = ugarchspec(mean.model = list(armaOrder = c(0,0)),
                                                    variance.model = list(garchOrder = c(1,1),
                                                                                                model = "sGARCH"),
                                                    distribution.model = "norm")

# dcc specification - GARCH(1,1) for conditional correlations
dcc.garch11.spec = dccspec(uspec = multispec( replicate(2, garch11.spec) ),
                                                     dccOrder = c(1,1),
                                                     distribution = "mvnorm")

# fit DCC model
dcc.fit = dccfit(dcc.garch11.spec, data = MSFT.GSPC.ret)

# plot Conditional Sigma
plot.new()
plot(dcc.fit, which=2)


#3

You’re right, I forgot to mention packages sources :sweat_smile:. However using plot.new() it appears just only an empty plot (exactly the one you posted). I don’t know if it helps,but I’ve just updated “blotter”, “zoo”, “xts” and “quantstrat” on my Windows machine and now I’m getting the same result: an empty plot. So maybe rmgarch plot method works just only with a deprecated function inside one of the 4 packages I updated? Do you have any other suggestions?


#4

I’m not familiar with the details of the graphics package so someone else will have to comment on that.

The key thing is please use reprex’s in your questions.