2
votes

I am very new to R so I apologize in advance if this is a trivial questions. I have a large set of data consisting of mortgage loan information icluding date of origination. I need to calculate a moving weighted (by loan amount) average of FICO scores over 3 month windows. The problem that I'm running into, is that I don't know how to account for the fact that there are multiple loans originated in the same month/year, and I know that an average of 3 months of averages is inaccurate.

SO how might I go about doing this if I have the following fields:

funded$loan_amount
funded$fico_score
funded$date
1
To clarify, do you want one average per quarter? Or are you looking for twelve averages each year, using data from each month as well as the previous two?Wilduck

1 Answers

0
votes

To do moving average it is best to use the package TTR.

library(SMA)
data<-ts(data=cbind(rnorm(10),rexp(10,2)),names=c("value","weight"))
result<-WMA(data[,"value"],wts=data[,"weight"],n=3)

You might need to install the library "SMA" first, if you have never used it before on your R installation.

Instead of moving average, consider exponential smoothing. It has known stochastic properties, which allow compute confidence intervals. See the package forecast.