Some posts are complaining about the YTM provided by foliofn. I found that the YTM is usually wrong when a note is less than 1 year or has a discount rate. If your strategy is to find a decent YTM with bigger discount rate and less remaining payments, their YTM is meaningless and you have to calculate by yourself. I would like to share my algorithm. Any feedback and comments are welcome.
The basic idea is to resolve r, monthly interest rate, from this formula:
a=p*(r*(1+r)^n/((1+r)^n-1))
Where a is monthly payment, p is askPrice (assume that you buy it with askPrice) and n is the remaining payments. p and n are provided in the CSV file.
a is not provided so we have to calculate it. We still use the same formula, but for this time p is outstanding principal and r is the original monthly interest rate . Monthly interest rate is not directly provided, but you get it by dividing annual interest rate by 12. Some people would argue that r is a geometrical mean instead of a arithmetic mean. Well, I had the same point until I found that it is more common to use arithmetic mean. If we want to take into account the monthly 1% service fee, adjust a by multiplying it with 0.99. Once we get a, we can start resolving the equation with a single unknown variable r. It is a nonlinear equation and there is no analytical solution for r. So we have to use numerical method to get an approximation of r. There are many ways to do numerical calculation. The easiest way is probably Newton method.
finally YTM=12*r*100%
Here is the R code to calculate Yield. You have to add the column of MonthlyPayment to the original dataframe before you pass it to this function.
getYield <- function(a,tol=1E-12,x0=1,N=20) {
m<-as.numeric(a["MonthlyPayment"])
n<-as.numeric(a["Remaining.Payments"])
pr<-as.numeric(a["AskPrice"])
h <- 0.001
i <- 1; x1 <- x0
p <- numeric(N)
while (i<=N) {
df.dx <- (f(x0+h,m,pr,n)-f(x0,m,pr,n))/h
x1 <- (x0 - (f(x0,m,pr,n)/df.dx))
p
<- x1
i <- i + 1
if (abs(x1-x0) < tol) break
x0 <- x1
}
return(p[i-1]*12*100)
}
f<-function(r,a,p, n)
{
y<-a-p*(r*(1+r)^n/((1+r)^n-1))
return(y)
}
A real example
https://www.lendingclub.com/foliofn/browseNotesLoanPerf.action?showfoliofn=true&loan_id=31317108&order_id=130405930¬e_id=60503781
Asking Price $9.34
Interest rate 15.61%
Outstanding Principal $9.66
Remaining Payments 12
r=0.1561/12= 0.01300833
a=p*(r*(1+r)^n/((1+r)^n-1))=9.66*(0.01300833*(1+0.01300833)^12/((1+0.01300833)^12-1))=0.8746782, which matches the monthly payment provided by Foliofn
finally, let's resolve the equation with Newton's Method
0.8746782 = 9.34*(r*(1+r)^12/((1+r)^12-1))
r= 0.018425
YTM=r*12*100%=22.1%