Learn R Programming

schwartz97 (version 0.0.6)

fitted-futures: Extract Model Fitted Values

Description

Function to extract fitted values from schwartz2f.fit-objects.

Usage

"fitted"(object, data, ttm)

Arguments

object
A schwartz2f.fit-object returned from schwartz2f.fit.
data
A matrix with futures prices.
ttm
A matrix with the corresponding times to maturity (see Details).

Value

A matrix containing the fitted values of the same dimension as data.

Details

The elements of data and ttm have the following interpretation: data[i,j] denotes the futures price whose time to maturity was ttm[i,j] when it was observed. The unit of ttm was defined by the argument deltat of fit.schwartz2f.

See Also

fit.schwartz2f, schwartz2f.fit-class, resid.

Examples

Run this code

# data(futures)
# 
# ## Estimate parameters for lumber data. Fit only 'mu', 'sigmaS',
# ## 'sigmaE', and 'rho' (and stop after 100 iterations).
# fit.obj <- fit.schwartz2f(futures$lumber$price, futures$lumber$ttm / 260,
#                           opt.pars = c(s0 = FALSE, delta0 = FALSE, mu = TRUE, 
#                                        sigmaS = TRUE, kappa = FALSE, alpha = FALSE, 
#                                        sigmaE = TRUE, rho = TRUE, lambda = FALSE),
#                           alpha = 0, kappa = 1.2, lambda = 0,
#                           deltat = 1 / 260, control = list(maxit = 100))
# fit.obj
# 
# ## Get the fitted values
# fitted.futures <- fitted(fit.obj, futures$lumber$price, futures$lumber$ttm / 260)
# 
# par(mfrow = c(1, 3))
# ## Plot futures prices
# plot(as.ts(futures$lumber$price), plot.type = "single", ylab = "Futures prices",
#      col = gray(seq(0.1, 0.9, length = 4)))
# ## Plot fitted values
# plot(as.ts(fitted.futures), plot.type = "single", ylab = "Fitted values",
#      col = gray(seq(0.1, 0.9, length = 4)))
# ## Plot relative difference
# plot(as.ts((fitted.futures - futures$lumber$price) / fitted.futures), plot.type = "single",
#      ylab = "Relative difference", col = gray(seq(0.1, 0.9, length = 4)))

Run the code above in your browser using DataLab