Sharing a function to compute the return on a loan on poloniex

in #trading7 years ago

Hello everybody!

I want to share with you a little piece of code that I wrote to compute the returns of lending cryptocurrencies in the well known online crypto-currency exchange poloniex.com. Lending is a low risk way of earning good interests on your crypto, but it seems to be often disregarded, sometimes because it is not well understood.

What is lending?

The main misconception is to think that the borrower might not be able to repay his loan. It is not strictly false, but actually that risk is very low, as Poloniex enforces margin calls: the borrower must have enough collateral, ensuring that he can buy his debt back. As soon as the collateral isn't anymore 20% more that what is required to buy back the debt at the current price, the collateral is liquidated (that is a margin call). That's why poloniex only enables margin trading on crypto with decent liquidity. It is possible that the price of a crypto goes up or down so fast that the collateral cannot buy the debt back even though the borrower account must be liquidated: I don't know how poloniex is programmed to react in such a black swan scenario, but it is quite unlikely, and to my knowledge never happened in Poloniex.

This kind of lending enables two kinds of speculative trading with leverage effect:

  • taking a short position on a crypto means that you borrow this crypto, in order to sell it right now, expecting that the price will go down and you can buy it back at a lower price later, therefore generating a profit.
  • taking a long position on a crypto means that you borrow Bitcoins in order to buy more of this crypto right now, expecting that the price will go up, so that you can sell for a profit.

In exchange of getting access to crypto he doesn't own, the borrower must pay interests on the amount he borrowed, expressed in percent per day on poloniex. The lender is motivated by the fact that he earns these interests. If Poloniex works correctly,

It must be kept in mind however that there are risks in lending your crypto: you don't have access to your crypto while they're being lended, so you can't sell it, and Poloniex might get hacked, or could go bust: lenders might suffer more than other users of the exchange in this eventuality.

A second misconception is that loans are unprofitable. The daily rates, by themselves, are small-looking numbers, especially compared to the crazy volatility of crypto markets. For example, a 0.02% daily rate might seem totally irrelevant. However, taking account of the 15% cut on the profits by Poloniex, this 0.02% daily rate translates into a 6.4% yearly rate: not that bad compared to your typical bank account at the moment. Good news is: the rates are typically much higher, and the current daily 0.15% on BTC translates into a 58% return yearly!
And every now and then, loans at very high rates that might be as high as 2% per day (the default maximum value on margin orders) are borrowed (such high rates loans typically don't go to maturity, but there are some great surprises in the lending panel).

R function to compute the return on a loan

So, here is a piece of code to compute the returns on a loan made on poloniex, written in the R language:

polo_loan_return <- function(daily_rate, 
                             loan_duration, 
                             polo_tax = 0.15, 
                             time_interval_in_days = 365.25, 
                             loan_amount=1){

    return(loan_amount*((((1+daily_rate*0.01*loan_duration)) 
        ^ (time_interval_in_days/loan_duration)-1) * (1 - polo_tax)))
}

Let's break up the arguments of this function:

  • daily_rate: in percent per day (as indicated in the poloniex lending panel)
  • loan_duration: duration of a single loan (between 2 and 60 days in poloniex). The shorter the duration, the higher the returns, because profits are reinvested. The computation assumes the best case, which is that matured loans are immediately taken again, including the interests earned.
  • polo_tax: a proportion, not in percent. By default: 0.15, because poloniex takes 15% of the profits on loans.
  • time_interval_in_days: the time period, in days, on which the return is computed. By default: yearly returns.
  • loan_amount: the amount of crypto that is loaned. By default: 1, effectively giving the return in %.

Example: polo_loan_return(daily_rate = 0.19, loan_duration = 2) gives the value 0.849. This means that lending your crypto at 0.19% per day in 2 day loans and reinvesting the interests gives a yearly return of 84.9%.

This code is written in the R language, which can be downloaded at r-project.org or rstudio (RStudio is a better IDE). It should be very easy to adapt to any other programming language.

I use this function a lot, and I hope this little function might help you take your decisions too!

Coin Marketplace

STEEM 0.20
TRX 0.12
JST 0.029
BTC 60946.76
ETH 3395.14
USDT 1.00
SBD 2.57