Lending Rates for Bitcoin and USD on Cryptoexchanges

We are going to take a look at the current interest rates in bitcoin lending.  Why is this important?  In addition to being a way to make extra income from your fiat (“real” currency) or bitcoin holdings without selling them, these interest rates indicate traders sentiment about the relative values of these currencies in the future.  We will look at bitcoin in this post, because it is the largest cryptocurrency, both in terms of market cap and trading volume.  As of the date of this writing here are the top 4 cryptocurrencies by total market cap.  Information from http://coinmarketmap.com.

Crypto-Currency Market Cap ($USD, billion) 24 Hr Trading volume ($USD, billion)
Bitcoin (BTC) 45 1.0
Ethereum (ETH) 32 0.78
Ripple 11 0.18
Litecoin (LTC) 2.5 0.37

The Bitfinex Exchange is one of the exchanges that allows margin trading, and also customer lending of fiat and crytpocurrencies.  They call the lending exchange funding and it works with an order book just like a regular trading exchange.  Customers submit funding offers and requests, and the exchange matches the orders.  So, for example, I could offer $USD800 for 4 days at .0329% per day (12% annually).  This get placed on the order book.  Someone else could accept that offer, and then the loan happens.  As the lender, I get paid interest daily at the contract rate, paid by the borrower.  Now, what does the borrower do with the proceeds?  They can’t withdraw the money from Bitfinex, this is not a general personal loan.  They could use this money to buy bitcoins on margin.  There are specific rules on how much they can borrow at purchase, and how much margin they must maintain in the future.  We won’t go into the specifics of those rules in this post, but just be aware that the exchange can liquidate, or sell, a position to maintain margin requirements.  In fact, this is what caused the recent meltdown in the Ethereum market at one exchange (GDAX) Ethereum Flash Crash, as traders had their positions liquidated automatically for margin calls.

So, show me the data!

interest rate chart

In this chart, fUSD is the funding rate as an APR for $USD, and fBTC is the funding rate for bitcoin (BTC). These are based on a small sample of 2 day loans actually traded on that day. The first thing to note is that the rates are quite volatile, reaching highs of over 100% (USD) and 50% (BTC) during the last year. The current rates (June 2017) are around 40% (USD) and 4% (BTC).

One more thing we might want to look at.  We might wonder about the difference between the two rates and what that means.  In economics, there is something called uncovered interest rate parity, which normally looks at the difference in interest rates between 2 currencies, say the USD and the Euro (EUR).  This difference is related to the relative inflation expected between the 2 currencies in the future.  In fact, futures contracts for the currencies should have a price related to this difference in such a way as to make arbitrage not possible.  Here is the difference graph.

Interest rate difference graph

Note that it switches around both sides of zero.  Between approximately 15 Mar 2017 and 1 May 2017, it was negative, meaning people were demanding higher rates to lend BTC than to lend USD.  Perhaps this is an indication that people wanted to short BTC at that time – although we don’t know which fiat currency they were shorting it against.

Another thing that we can pull from the data is the yield curve.  In the bond market, this indicates the interest rates for bonds at different maturities, for example, a 30 day, 60 day, 1 year, etc.  In the case of Bitfinex, the loans can only be made for 2-30 days, so we have a more limited set of possibilities.

You can see the curves are relatively flat, but they only go out to 30 days, so we can’t say much about 1 year rates. Note that most of the volume is at the extremes, that is 2 days or 30 days, so the numbers in between are not that meaningful.

In post to come, we will look at Bitcoin futures, to see how their pricing might be related to the uncovered interest rate parity. Stay tuned.

PrimeGrid GPU Task Analysis

If you have a multi-GPU computer running on Primegrid.com, you might be wondering how to see how tasks are running across your GPUs.  It turns out that the stderr log files can sometimes provide the GPU ID that was used to produce those results.  I wrote a simple script that analyzes the run times by GPU; the script is located here:

This is a snippet from the stderr output that it scans looking for gpu_device_num:

Unrecognized XML in parse_init_data_file: gpu_device_num
Skipping: 2
Skipping: /gpu_device_num
Unrecognized XML in parse_init_data_file: gpu_opencl_dev_index
Skipping: 2
Skipping: /gpu_opencl_dev_index
Unrecognized XML in parse_init_data_file: gpu_usage
Skipping: 1.000000

Sample output:

Processing tasks for hostid 820440

                              run-avg  run-std  run-count  credit-avg  credit-cnt  credit_per_s
date       gpu  task                                                                           
2017-05-01 0    pps_sr2sieve    404.7     2.21         91      3371.0          43         8.330
           1    pps_sr2sieve    424.8     3.42         86      3371.0          39         7.936
           2    pps_sr2sieve    387.1     2.51         93      3371.0          38         8.709
           none llrPPS         1768.6   184.86         16       119.9          10         0.068
                llrSGS          652.5    14.17        103        39.9          46         0.061

                   run-avg  run-std  run-count  credit-avg  credit-cnt  credit_per_s
gpu  task                                                                           
0    pps_sr2sieve    404.7     2.21         91      3371.0          43         8.330
1    pps_sr2sieve    424.8     3.42         86      3371.0          39         7.936
2    pps_sr2sieve    387.1     2.51         93      3371.0          38         8.709
none llrPPS         1768.6   184.86         16       119.9          10         0.068
     llrSGS          652.5    14.17        103        39.9          46         0.061

Tasks: Processed:400, Completed:389 New files requested:37 Total time: 20.41 sec


Installing BOINC on Multi GPU Computer

Computer GPUs lit up

Already built a multi-GPU computer?  No?  See How to Build a Multi-GPU Computer here.

OK, we have our multiple GPU system wired up and it seems to boot OK into the BIOS.  The BIOS shows our 3 GPUs installed in the proper slots and we like the speeds (Gen 3) of PCIe that are chosen.

Let’s install Linux.  I choose Debian – I am familiar with it, and more importantly, I got it to work with BOINC.  Here is that procedure:

  1. Create a netinst DVD or CD for Debian Stretch.  I found that the latest stable version (Jessie) did not have the correct packages to get BOINC running.  I used RC2, but RC3 is available now, and should work as well.  Ddownload the .iso file you need (probably the amd64 package) to your computer, then use an ISO writing program to write that to a DVD/CD.  On a Windows machine, I used ImgBurn, but you can use any program you like.
  2. Boot the multi-GPU computer with this DVD.   If it does not boot from the DVD drive, you will need to go into the BIOS and set up the boot order so that the DVD is first or at least tried after the HDD fails.
  3. Follow the prompts to install Debian.  There are plenty of guides on the Internet to help you, but it is pretty straightforward.  You can take defaults for just about everything.  I did NOT install the desktop environment because I only plan on ssh’ing into the computer and did not want to have X software installed/running.  Do choose ssh server and standard system utilities.  NOTE: you will need an Internet connection, preferably hardwired, to install Debian, so plug in an Ethernet cable to your Internet connection before you start.
  4. Install sudo so you can become root as needed – first log in as root, then
    apt-get install sudo
    usermod -aG sudo <your-user-name>
  5. Add contrib and non-free to your /etc/apt/sources.lst file as some of the nvidia driver files are in those categories.  You should have a line in the sources.lst file that looks like:
    deb http://ftp.us.debian.org/debian/ stretch main non-free contrib
  6. Update your database:
    sudo apt-get update
  7. To be able to ssh into this machine without a password, add your public key which you have copied to this machine already, to the list of authorized keys.  Note that you could transfer the key with a USB key if you don’t want to copy over the network:
    sudo mount /dev/sdb1 /media/usb    # your devices may differ
    cat /media/usb/id_rsa.pub >> ~/.ssh/authorized_keys
  8. Now install the BOINC software and related drivers.  You might want to install them sequentially to make debugging simpler in case something goes wrong.  I got nvidia-driver version 375.26-2.
    sudo apt-get install nvidia-driver boinc-client-opencl boinc-client-nvidia-cuda boinc
  9. Make sure the BOINC client autostarts on boot up – check your /etc/init.d/ directory for a boinc-client script.  Now, a small adjustment is necessary to make sure the GPUs are detected at startup – there is a race condition with drivers, so edit the boinc-client script (as root) and add a sleep 2.0 line so that the start() function in the file looks like:
     log_begin_msg "Starting $DESC: $NAME me"
     sleep 2.0    #<== ADD THIS LINE
     if is_running; then
       log_progress_msg "already running"
  10. Now, you should be able to reboot the computer and see something like the following from ps -ef:
    #ps -ef |grep boinc
    dan      614 24444 0 17:17 pts/0 00:00:00 grep boinc
    boinc    623 1     0 Mar30 ?     00:00:00 /bin/sh -c /usr/bin/boinc --dir /var/lib/boinc-client >/var/log/boinc.log 2>/var/log/boincerr.log
    boinc    641 623   0 Mar30 ?     00:30:05 /usr/bin/boinc --dir /var/lib/boinc-client

    If you can’t see boinc, running you will need to do some debugging.  Check out /var/log/boinc.log and you can see the startup messages.  If everything is going well, you will see the GPUs being detected and indicating how many are usable (hopefully the number you installed, in this case 3).  Some debug steps are:  (i) try nvidia-smi to see if the Nvidia drivers can see your GPUs, and (ii) set the BOINC logging flags – possibly <coproc_debug> in BOINC Configuration.

  11. A couple more things and we are almost done.  To enable remote management of the BOINC server software, add/edit the following files in /var/lib/boinc_client:
    echo <remote-access-password> > gui_rpc_auth.cfg
    echo <your-remote-access-IP-address> > remote_hosts.cfg
  12. Now you should be able to connect to the server through the boincmgr program, using the password you set above.  You can install BOINC on a windows or linux machine fairly easily, which will give you access to the manager program.  Of course, if you want to keep your GPU machine in a place where you can access it via keyboard and monitor, you could just run the boincmgr locally.  Note that it will not run unless you install a Desktop environment, since it needs X-client running.
  13. From the manager program, you can select a project from the available ones on BOINC such as SETI, primegrid, etc.  You will have to provided credentials to get you started, which you get by creating an account on the appropriate projects website (e.g. primegrid.com).  For Primegrid, you can control which tasks your computer works on through configuring things on the primegrid website.  Note that only certain tasks can take advantage of the Nvidia-cuda GPUs, so make sure you select at least 1 subproject that does that.  Other tasks can be run on the CPU directly, but make sure not to fully load your CPU with tasks, as that will tend to slow down the servicing of the GPUs.
  14. If your computer will have any exposure to the outside world (including your home WiFi), you should be careful to secure it properly.  At a minimum, you will want to disable root logins, all unnecessary processes and open ports.
  15. Join the SolverWorld team on PrimeGrid and add your computing power to the team.  I will announce your contributions (if you want) on separate page in the future.
  16. Happy computing!