Lending Club is a marketplacelending site. Marketplace lending crowd-funds loans by matching borrowers with willing investors. This LendingClub library makes it easy for you to see your investor account data such as the amount of free cash or the details on which loans you own. This package is a convenience wrapper for the Lending Club API so that you get get the data into R. You can learn more about the API by reading Lending Club’s documentation. Lending Club does not offer an API for borrower data.
To get started, you’ll need to supply the investor’s account number and API key. You can find the account number from the Account Summary page. The API key is located at the bottom of the Account Settings page. In the example below, the account number and API key are loaded from an .Renviron file but you can use whatever process you are comfortable to pass them to the lc_MakeCredential function. If you are going to share your code, then I recommend doing something similar to this method rather than put it directly in your code.
The lc_MakeCredential() function uses the investorID and APIkey inputs to create an S3 object. If you save this object as
LC_CRED, then the other functions in this package will find it in the global environment and you will not have to pass it as an argument to the other functions.
library(LendingClub) investorID<- Sys.getenv("id") APIkey <- Sys.getenv("key") LC_CRED<- lc_MakeCredential(investorID, APIkey)
If you plan to share your code or publish to Github, you may want to save your investorID and APIkey separately so you don’t have to share them. In the example above, the variables were saved as environment variables. Alternatively, you can save them in a text file and read them in with
LC_CRED<- lc_MakeCredential(investorID = readLines("path_to_creds.txt"), APIkey = readLines("path_to_creds.txt"))
Here are a few examples of other functions in the package. As mentioned above, all other functions in this package will look for the
LC_CRED object before processing the respective API calls. You can see a data.frame of the currently listed loans using the
Another useful function to start with is lc_AccountSummary(). This returns key statistics such as the available cash, total number of notes owned, and all time total interest received. You don’t pass any inputs to the function but it will search the global environment for the
This package is most useful for investors applying advanced filtering or algorithms to determine which loans to buy. The algorithms aren’t in scope for this package but it does enable the automation. The code below is an example of how you go about using the package. You should use care when deciding how to choose investments. A best practice is to establish a limit on how many loans you put in the order. The max is determined by the amount of available funds in your account but you could do less if you wanted.
LC_CRED<- lc_MakeCredential(investorID, APIkey) # Establish a limt on how many loans are in the order # by determing the max amount of $25 notes you can purchase. notequantity<- as.numeric(lc_AvailableCash()$content[2, 2]) %/% 25 loans<- lc_ListedLoans()$content$loans # Filter, sort, or apply your model to determine where to invest. order<- loans %>% filter(grade %in% c("A", "B")) %>% sort(desc(intRate)) %>% select(id) %>% head(notequantity) lc_SubmitOrder(loanId= order, amount= rep(25, notequantity), LC_CRED= LC_CRED)