Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

This is the second in a series of posts designed to show how the R programming language can be used with cryptocurrency related data sets.  A number of R packages are great for analyzing stocks and bonds and similar financial instruments.  These can also be applied to working with cryptocurrencies.  In this post we will focus on Bitcoin.

Bitcoin has garnered enough attention that it is available through Yahoo’s finance data under the symbol BTCUSD=X.  The quantmod package is comprised of a set of packages and utilities geared towards time series analysis traditionally associated with stocks.  You can load Bitcoin along with other Stock symbols using the loadSymbols function.  In this example we will also load AMD, which makes graphics cards used by cryptocurrency miners.

library(quantmod)

If you have any issue downloading the data, make sure you update to the latest version of quantmod.  If all goes well, you will have two objects in your global environment named AMD and BTCUSD=X.

ls()
[1] “AMD”      “BTCUSD=X”

You can plot AMD by simply passing it to the plot function.

plot(AMD)

Bitcoin is slightly different simply because the symbol in use includes an equal sign.  To ensure that R evaluates the code properly, the symbol must be surrounded in back ticks.

plot(BTCUSD=X)

There is data missing for certain days.  There are other sources for cryptocurrency data which can be substituted if needed.  We will ignore this anomaly for the remainder of this post.  There is data for the last 4 weeks. We can construct a candle chart that focuses on this subset of data.

chartSeries(BTCUSD=X, subset=’last 4 weeks’)

This chart can then be modified to include technical analysis – for instance Bollinger Bands.

The capabilities of the quantmod package in an earlier post (see http://www.r-chart.com/2010/06/stock-analysis-using-r.html) where a listing of other functions that can be applied is included.

Inasmuch as cryptocurrencies behave like traditional equities, they lend themselves to similar types of analysis.  The quantmod package is a great place to start when analyzing cryptocurrencies.