library(tidyverse)
library(BatchGetSymbols)
library(fGarch)
library(profvis)

# set temporary file for results
profiling_file <-  tempfile(pattern = 'profiling_exercise', 
                            fileext = '.out')

# initialize profiling
Rprof(filename = profiling_file)

# run code
profiling <- profvis(expr = {
  ticker <- '^GSPC'
  df_prices <- BatchGetSymbols(tickers = ticker, 
                               first.date = '2000-01-01', do.cache = FALSE)[[2]]

  my_garch <- garchFit(formula = ret.adjusted.prices ~ arma(1,1) + garch(1,1), 
                       data =  na.omit(df_prices) )
})

# create visualization
temp_html <- tempfile(pattern = 'profile',
                      fileext = '.html')

htmlwidgets::saveWidget(profiling, temp_html)

# open in browser from R
browseURL(temp_html)
# none
#my_answers <- make_random_answers(my_sol)
my_answers <- rep(NA, 5)

type_question <- 'string'
ex_name <- 'otimizing 13-01'

Question

Consider the following code:

library(tidyverse)
library(forecast)
library(BatchGetSymbols)

ticker <- '^GSPC'
df_prices <- BatchGetSymbols(tickers = ticker, 
                             first.date = '2010-01-01')[[2]]

my_arima <- auto.arima(df_prices$ret.adjusted.prices)
summary(my_arima)

Use functions Rprof and profvis to identify the bottleneck of the code. Which line number is taking the longest execution time?

Solution


Meta-information

extype: r type_question exsolution: r mchoice2string(c(TRUE, FALSE, FALSE, FALSE, FALSE), single = TRUE) exname: r ex_name exshuffle: TRUE



msperlin/afedR documentation built on Sept. 11, 2022, 9:49 a.m.