Docsity

R Programming for Finance Practice Exam, Exams of Technology

Toggle sidebar
bg1
R Programming for Finance Practice Exam
**Question 1.** Which tidyverse function is most appropriate for reading a CSV file while
automatically guessing column types?
A) read.csv()
B) read_excel()
C) readr::read_csv()
D) data.table::fread()
Answer: C
Explanation: `readr::read_csv()` is part of the tidyverse, reads CSV files quickly, and parses
column types automatically.
**Question 2.** In base R, which operator tests for element‑wise equality?
A) `=`
B) `==`
C) `===`
D) `is.equal()`
Answer: B
Explanation: `==` compares corresponding elements of two vectors and returns a logical vector
of the same length.
**Question 3.** Which of the following is a valid way to create a numeric vector of length 5
containing the numbers 1 through 5?
A) `c(1:5)`
B) `seq(5)`
C) `vector("numeric",5)`
D) All of the above
Answer: D
Explanation: All three commands generate a numeric vector of length 5 with values 1,2,3,4,5.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59

Partial preview of the text

Download R Programming for Finance Practice Exam and more Exams Technology in PDF only on Docsity!

Question 1. Which tidyverse function is most appropriate for reading a CSV file while automatically guessing column types? A) read.csv() B) read_excel() C) readr::read_csv() D) data.table::fread() Answer: C Explanation: readr::read_csv() is part of the tidyverse, reads CSV files quickly, and parses column types automatically. Question 2. In base R, which operator tests for element‑wise equality? A) = B) == C) === D) is.equal() Answer: B Explanation: == compares corresponding elements of two vectors and returns a logical vector of the same length. Question 3. Which of the following is a valid way to create a numeric vector of length 5 containing the numbers 1 through 5? A) c(1:5) B) seq(5) C) vector("numeric",5) D) All of the above Answer: D Explanation: All three commands generate a numeric vector of length 5 with values 1,2,3,4,5.

Question 4. Which R object type can hold elements of different data types, including other vectors and lists? A) Matrix B) Data frame C) List D) Array Answer: C Explanation: A list is a recursive data structure that can contain objects of any type, including other lists. Question 5. What is the output of ifelse(c(TRUE,FALSE,TRUE), 1, 0)? A) c(1,0,1) B) c(TRUE,FALSE,TRUE) C) c(0,1,0) D) c(1,1,1) Answer: A Explanation: ifelse evaluates the test vector element‑wise, returning 1 where TRUE and 0 where FALSE. Question 6. Which loop construct is best suited for iterating over the elements of a vector when the number of iterations is known in advance? A) while B) repeat C) for D) until Answer: C

D) arrange(df, Date, Close, Volume) Answer: B Explanation: select() chooses specified columns from a data frame. Question 10. Which lubridate function extracts the month (as a number) from a POSIXct date object date_vec? A) month(date_vec) B) get_month(date_vec) C) as.month(date_vec) D) date_month(date_vec) Answer: A Explanation: lubridate::month() returns the month component of a date-time object. Question 11. In the xts package, which function converts a regular data frame with a Date column into an xts object? A) as.xts(df, order.by = df$Date) B) xts(df, order.by = df$Date) C) convert.xts(df) D) Both A and B are correct Answer: D Explanation: Both as.xts() and xts() can create an xts object when supplied with an ordering vector. Question 12. Which of the following correctly computes daily log returns from a price vector P? A) diff(log(P)) B) log(diff(P))

C) diff(P)/P[-length(P)] D) log(P[-1]/P[-length(P)]) Answer: A Explanation: diff(log(P)) computes log(P_t) - log(P_{t-1}), which is the definition of the log return. Question 13. The annualized volatility of a series of daily log returns r can be calculated as: A) sd(r) * sqrt(252) B) sd(r) / sqrt(252) C) var(r) * 252 D) mean(r) * sqrt(252) Answer: A Explanation: Daily standard deviation multiplied by the square root of trading days (≈252) gives annualized volatility. Question 14. Which PerformanceAnalytics function computes the annualized Sharpe Ratio given a return series R and a risk‑free rate rf? A) SharpeRatio(R, Rf = rf) B) SharpeRatio.annualized(R, Rf = rf) C) Sharpe(R, rf) D) AnnualizedSharpe(R, rf) Answer: B Explanation: SharpeRatio.annualized() returns the annualized Sharpe Ratio, adjusting for the risk‑free rate. Question 15. In a CAPM regression R_i = α + β·R_m + ε, which R function is most appropriate to estimate α and β?

Question 18. In a mean‑variance optimization, the efficient frontier is obtained by varying which parameter? A) Expected return target B) Risk‑free rate C) Number of assets D) Sharpe Ratio Answer: A Explanation: By changing the target expected return, the optimizer computes the minimum variance portfolio for each target, tracing the efficient frontier. Question 19. Which PortfolioAnalytics function adds a constraint that portfolio weights must sum to 1? A) add.constraint(portfolio, type = "full_investment") B) add.constraint(portfolio, type = "weight_sum", min_sum = 1, max_sum = 1) C) add.constraint(portfolio, type = "budget", budget = 1) D) Both A and B are correct Answer: D Explanation: Both "full_investment" and "weight_sum" with min and max set to 1 enforce the weight‑sum‑to‑one constraint. Question 20. Which of the following statements about Value‑at‑Risk (VaR) is true? A) Historical VaR assumes returns follow a normal distribution. B) Parametric VaR can be computed using the quantile function of a Student‑t distribution. C) Monte Carlo VaR does not require simulation of price paths. D) All VaR methods produce identical results for the same confidence level. Answer: B

Explanation: Parametric VaR can be based on any assumed distribution, including Student‑t, by applying its quantile function. Question 21. The rugarch function ugarchspec() is used to: A) Fit a GARCH model to data. B) Simulate GARCH paths. C) Specify the GARCH model order and distribution. D) Perform diagnostic tests on residuals. Answer: C Explanation: ugarchspec() creates a specification object that defines the GARCH order, mean model, and error distribution. Question 22. Which statistical test is commonly employed to assess the presence of a unit root in a time series? A) Ljung‑Box test B) Augmented Dickey‑Fuller (ADF) test C) Jarque‑Bera test D) Breusch‑Pagan test Answer: B Explanation: The ADF test checks for stationarity by testing the null hypothesis of a unit root. Question 23. In the forecast package, which function automatically selects the best ARIMA model based on AICc? A) auto.arima(ts_data) B) Arima(ts_data, order = c(p,d,q)) C) ets(ts_data) D) forecast(ts_data)

C) Daily dividend yield D) Risk‑free rate Answer: B Explanation: dt is the time interval between successive nodes; the up factor reflects volatility over that interval. Question 27. Which R function generates a geometric Brownian motion path for a stock price? A) rnorm() B) gbm() from the fOptions package C) simulate.GBM() from Sim.DiffProc D) Both B and C are correct Answer: D Explanation: Both fOptions::gbm() and Sim.DiffProc::simulate.GBM() simulate GBM paths. Question 28. The Macaulay duration of a bond measures: A) The weighted average time until cash flows are received. B) The bond’s price volatility relative to yield changes. C) The convexity of the bond. D) The yield to maturity. Answer: A Explanation: Macaulay duration is the time‑weighted average of present‑value‑weighted cash flows. Question 29. Which tidyquant verb adds a column of daily returns to a tibble containing a price column named close? A) mutate(return = dailyReturn(close))

B) mutate(return = periodReturn(close, period = "daily")) C) mutate(return = ROC(close, type = "discrete")) D) All of the above produce daily returns. Answer: D Explanation: All three functions (dailyReturn, periodReturn, ROC) compute daily returns; they differ slightly in implementation but yield equivalent results. Question 30. When using PerformanceAnalytics::chart.CumReturns(), what does the default wealth.index = TRUE argument do? A) Plots cumulative returns on a log scale. B) Shows the growth of $1 invested. C) Displays returns as percentages. D) Adds a risk‑free rate line. Answer: B Explanation: Setting wealth.index = TRUE converts cumulative returns into a wealth index that starts at 1 (i.e., $1 invested). Question 31. Which dplyr verb would you use to compute the average monthly return for each ticker in a data frame prices? A) group_by(ticker, month) %>% summarise(avg_ret = mean(return)) B) filter(ticker) %>% mutate(month = month(date)) %>% summarise(avg_ret = mean(return)) C) arrange(ticker, month) %>% mutate(avg_ret = mean(return)) D) select(ticker, month, return) %>% summarise(avg_ret = mean(return)) Answer: A Explanation: group_by() creates groups by ticker and month; summarise() then computes the mean return per group.

Explanation: bptest() from the lmtest package implements the Breusch‑Pagan test for heteroscedasticity. Question 35. In the context of risk‑adjusted performance, the Sortino Ratio differs from the Sharpe Ratio by: A) Using downside deviation instead of total standard deviation. B) Excluding the risk‑free rate. C) Using the geometric mean return. D) Applying a different confidence level. Answer: A Explanation: The Sortino Ratio replaces total volatility with downside deviation, focusing only on negative returns. Question 36. Which tidyquant function retrieves the FRED series “DGS10” (10‑Year Treasury Constant Maturity Rate) as a tibble? A) tq_get("DGS10", get = "fred") B) tq_get("DGS10", from = "fred") C) fredr::fred_series(series_id = "DGS10") D) Both A and C are valid approaches. Answer: D Explanation: tq_get() can pull FRED data, and fredr provides a direct API; both return the series. Question 37. When fitting a GARCH(1,1) model with rugarch::ugarchfit(), which parameter captures the persistence of volatility? A) omega B) alpha1 C) beta1

D) shape Answer: C Explanation: In a GARCH(1,1) model, beta1 multiplies the previous conditional variance, representing volatility persistence. Question 38. The Ljung‑Box test applied to standardized residuals of a GARCH model checks for: A) Normality of residuals. B) Autocorrelation in residuals. C) Heteroscedasticity. D) Unit root presence. Answer: B Explanation: The Ljung‑Box test assesses whether a series of residuals is independently distributed (i.e., no autocorrelation). Question 39. Which quantmod function adds a technical indicator (e.g., SMA) directly onto a chart of a price series? A) addSMA(n = 20) B) addTA(SMA(Cl(price), n=20)) C) addIndicator(SMA, n = 20) D) Both A and B work inside chartSeries(). Answer: D Explanation: Inside chartSeries(), addSMA() is a shortcut; alternatively addTA() can plot any custom indicator. Question 40. In a multi‑factor regression, the lm() call lm(R ~ MKT + SMB + HML, data = df) corresponds to which model? A) CAPM

Question 43. Which R function calculates the Jarque‑Bera test for normality on a numeric vector x? A) shapiro.test(x) B) jarque.bera.test(x) from the tseries package C) norm.test(x) D) ks.test(x, "pnorm") Answer: B Explanation: jarque.bera.test() implements the JB statistic to test for skewness and kurtosis deviations from normality. Question 44. In the context of bond pricing, the bond.yield() function from which package returns the yield to maturity? A) QuantLib B) fOptions C) YieldCurve D) RQuantLib Answer: D Explanation: RQuantLib::bond.yield() computes YTM given cash flows and price. Question 45. Which dplyr verb would you use to keep only rows where the return column is greater than zero? A) filter(return > 0) B) select(return > 0) C) mutate(return > 0) D) arrange(return > 0) Answer: A Explanation: filter() subsets rows based on a logical condition.

Question 46. When using quantmod::getSymbols() with the argument auto.assign = FALSE, what is returned? A) The data is written to the global environment. B) A list containing the downloaded data. C) Nothing; the function only prints a message. D) A data frame saved to disk. Answer: B Explanation: Setting auto.assign = FALSE prevents automatic assignment and instead returns the data as an object. Question 47. Which PerformanceAnalytics function creates a heatmap of the correlation matrix of a return series? A) chart.Correlation() B) corrplot() from corrplot package C) chart.CorrelationHeatmap() D) heatmap() Answer: A Explanation: chart.Correlation() from PerformanceAnalytics produces a scatterplot matrix with correlation coefficients, often visualized as a heatmap. Question 48. In a Monte‑Carlo VaR simulation, the number of simulated price paths is typically denoted by: A) n B) Nsim C) M D) Any of the above, but commonly n.sim in PerformanceAnalytics.

C) mutate(cum_ret = cumprod(1 + ROC(close))) D) All of the above are valid. Answer: D Explanation: Each expression computes cumulative returns using a different helper function; they all produce the same result. Question 52. In the Black‑Scholes formula, the parameter d2 is used to compute: A) Call option price only. B) Put option price only. C) Both call and put prices via the cumulative normal distribution. D) The option’s delta. Answer: C Explanation: d2 appears in the cumulative normal terms for both call and put prices; it reflects the probability of finishing in‑the‑money. Question 53. Which R function from the tseries package performs the Augmented Dickey‑Fuller test? A) adf.test() B) kpss.test() C) pp.test() D) ur.df() Answer: A Explanation: adf.test() implements the Augmented Dickey‑Fuller test for unit roots. Question 54. When constructing a portfolio of three assets, the weight vector must satisfy which of the following constraints for a "long‑only" portfolio? A) Each weight ≥ 0 and sum = 1

B) Each weight ≤ 0 and sum = - 1 C) Weights can be any real numbers as long as sum = 0 D) No constraints are required. Answer: A Explanation: A long‑only portfolio restricts weights to be non‑negative and to sum to unity. Question 55. Which ggplot2 theme removes all background grid lines? A) theme_minimal() B) theme_bw() C) theme_void() D) theme_classic() Answer: C Explanation: theme_void() produces a completely empty background with no axes, grid, or panel lines. Question 56. In a GARCH(1,1) model, the unconditional variance is given by: A) omega / (1 - alpha1 - beta1) B) omega * (1 - alpha1 - beta1) C) omega / (alpha1 + beta1) D) omega + alpha1 + beta1 Answer: A Explanation: The unconditional variance formula for GARCH(1,1) is ω / (1 - α₁ - β₁) provided the denominator is positive (stationarity). Question 57. The PerformanceAnalytics::chart.Drawdown() function plots: A) Cumulative returns. B) Rolling volatility.