r – Problem with the xts object required for the Srates function in the YieldCurve package

I can extract the relevant coefficients for the Svensson model (from the Svennson function). However, I can not generate predicted values ​​with the Srates function. I do not understand the mistake of needing an xts object.

I have some real treasury data (returns and then maturities – in months, not years). I want to adjust a yield curve. Of course, I could put the Svennson function coefficients into the Svensson function, but I want to be able to use the Srates function for convenience / accuracy.

I've tried to format runtimes as ts and xts objects, but still get the error: "Error in xts (ts (runtimes), order.by = index):
order.by requires a corresponding time-based object "

Library (YieldCurve)

# Setting up data -------------------------------------------- -------

Yields <-c (0.01, 0.09, 0.13, 0.39, 0.76, 1.72, 2.41, 3, 3.68, 3.92)
Running times <- c (1,6,12,24, 36, 60, 84, 120, 240, 360)

# Assembly by Svensson ------------------------------------------- -

Svcoefs <- Svensson (Yields, Maturities)

Srates (Svcoefs, seq (1, 360, by = 1)) #previously a predicted value for each runtime

Type Conversion – How do I convert a list of xts objects in R to weekly averages with period.apply?

I try to create weekly averages based on the xts objects that I split into a list, but I keep getting the error:

Error in isOrdered (INDEX):
(List) object can not be of type & # 39; double & # 39; are forced

I tried to use the period.apply function.

rate_data_xts <- xts (rate_data, rate_data[ ,-2], order.by = rate_data[ ,2])

lanes_xts <- split (rate_data_xts, rate_data_xts $ laneid)

tx_ca_reefer <- lanes_xts[["TX_CA_Reefer"]]

head(tx_ca_reefer)

> Head (tx_ca_reefer)
PONumber LoadDate PracticalMiles laneid TruckPayPerMile
2018-01-28 9819414 2018-01-28 1543 TX_CA_Reefer 1.6850
2018-01-28 9848220 2018-01-28 1552 TX_CA_Reefer 2.5128
2018-01-29 9826639 2018-01-29 1246 TX_CA_Reefer 2.4077
2018-01-29 9827379 2018-01-29 1396 TX_CA_Reefer 1.3610
2018-01-29 9828055 2018-01-29 1535 TX_CA_Reefer 1.8241
2018-01-29 9828701 2018-01-29 1604 TX_CA_Reefer 1.8703
warning:
In the zoo (rval, index (x)[i]):
Some methods for Zoo objects do not work if the index entries in
"Order.by" is not unique

end_points <- map (lanes_xts, endpoints, an = & # 39; weeks & # 39;

lanes_weekly_xts <- period.apply (lanes_xts, INDEX = endpoints, FUN = mean)

Error in isOrdered (INDEX):
(List) object can not be of type & # 39; double & # 39; are forced

What I want is a weekly average for every xts object in the list. Any help would be appreciated.

xts – with lapply over an environment in R

I have an environment that contains time series data of 50 stocks pulled from Yahoo money. What I am looking for is to perform the volatility function of the TTR package for each of the variables. I always get an error "Data must be a vector type, it was" NULL ".

    getSymbols (ETFS, auto.assign = T, env = hub)
Lapply (Hub, FUN = volatility (OHLC (x), n = 20))

I tried too

    Lapply (Hub, FUN = function (x) volatility (OHLC (x), n = 20))

I get the error:
Errors in runCov (x, x, n, use = "all.obs", sample = sample, cumulative):
Series do not contain leading NAs