<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/investigating-cryptocurrencies-part-ii/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.r-chart.com/2017/07/investigating-cryptocurrencies-part-ii.html"> R-Chart</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div><a rel="nofollow" href="https://i0.wp.com/2.bp.blogspot.com/-0XS1P2dD0-0/WWqX6R2OK_I/AAAAAAAAA4Q/Bmjjx9DztA8ktZZbryCB_zF8L3ekD5tJgCPcBGAYYCw/s1600/crypto_currencies.png?ssl=1" target="_blank"><img border="0" data-original-height="88" src="https://i0.wp.com/2.bp.blogspot.com/-0XS1P2dD0-0/WWqX6R2OK_I/AAAAAAAAA4Q/Bmjjx9DztA8ktZZbryCB_zF8L3ekD5tJgCPcBGAYYCw/s1600/crypto_currencies.png?resize=258%2C88&ssl=1" data-recalc-dims="1" data-original-width="258"></a></div>
<p>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.</p>
<p>Bitcoin has garnered enough attention that it is available through <a rel="nofollow" href="https://finance.yahoo.com/chart/BTCUSD%3DX" target="_blank">Yahoo’s finance data</a> under the symbol <b>BTCUSD=X</b>.  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.</p>
<p><span><b>library(quantmod)</b></span><br><span><b>loadSymbols(c(‘BTCUSD=X’,’AMD’))</b></span><br><span><b><br></b></span><span>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 <b>AMD</b> and <b>BTCUSD=X</b>.</span><br><span><b><br></b></span><span><b>ls()</b></span><br><span><b>[1] “AMD”      “BTCUSD=X”</b></span><br><span><b><br></b></span><span>You can plot AMD by simply passing it to the plot function.</span><br><span><br></span><span><b>plot(AMD)</b></span><br><span><b><br></b></span>
<div><a rel="nofollow" href="https://i0.wp.com/2.bp.blogspot.com/-CI1SRjeUy9M/WW1OMBghU2I/AAAAAAAAA4s/Z-Rijsn7ckAYxB6b_X5IVQcwgQrVtEWDwCLcBGAs/s1600/AMD.png?ssl=1" target="_blank"><img border="0" data-original-height="341" src="https://i0.wp.com/2.bp.blogspot.com/-CI1SRjeUy9M/WW1OMBghU2I/AAAAAAAAA4s/Z-Rijsn7ckAYxB6b_X5IVQcwgQrVtEWDwCLcBGAs/s400/AMD.png?resize=411%2C341&ssl=1" data-recalc-dims="1" data-original-width="411"></a></div>
<p><span>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.</span><br><span><br></span><span><b>plot(`BTCUSD=X`)</b></span></p>
<div><a rel="nofollow" href="https://i0.wp.com/1.bp.blogspot.com/-SQqQGE6As5I/WW1PCodBezI/AAAAAAAAA4w/K7_7oLi4TVoS-DlycJMAfEDI8hcBJyifQCLcBGAs/s1600/BTC.png?ssl=1" target="_blank"><img border="0" data-original-height="341" src="https://i0.wp.com/1.bp.blogspot.com/-SQqQGE6As5I/WW1PCodBezI/AAAAAAAAA4w/K7_7oLi4TVoS-DlycJMAfEDI8hcBJyifQCLcBGAs/s400/BTC.png?resize=411%2C341&ssl=1" data-recalc-dims="1" data-original-width="411"></a></div>
<p>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.</p>
<p><span><b>chartSeries(`BTCUSD=X`, subset=’last 4 weeks’)</b></span></p>
<div><a rel="nofollow" href="https://i1.wp.com/2.bp.blogspot.com/-WTkxR3ws_XM/WW1WGWXQlpI/AAAAAAAAA5U/0WyOyifW9TQgrakaQeMBAfRtunVPzIdHwCLcBGAs/s1600/BTCUSD_Candle.png?ssl=1" target="_blank"><img border="0" data-original-height="400" src="https://i1.wp.com/2.bp.blogspot.com/-WTkxR3ws_XM/WW1WGWXQlpI/AAAAAAAAA5U/0WyOyifW9TQgrakaQeMBAfRtunVPzIdHwCLcBGAs/s320/BTCUSD_Candle.png?resize=450%2C400&ssl=1" data-recalc-dims="1" data-original-width="450"></a></div>
<p>This chart can then be modified to include technical analysis – for instance Bollinger Bands.</p>
<p><span><b>addBBands()</b></span><br><span><b><br></b></span>
<div><a rel="nofollow" href="https://i1.wp.com/3.bp.blogspot.com/-brJuv_EUEAc/WW1Wss5MYhI/AAAAAAAAA5Y/JGF-yNUVjVgRINa0DOMn5OewnfB29AVdwCLcBGAs/s1600/BTCUSD_CandleBB.png?ssl=1" target="_blank"><img border="0" data-original-height="400" src="https://i1.wp.com/3.bp.blogspot.com/-brJuv_EUEAc/WW1Wss5MYhI/AAAAAAAAA5Y/JGF-yNUVjVgRINa0DOMn5OewnfB29AVdwCLcBGAs/s320/BTCUSD_CandleBB.png?resize=450%2C400&ssl=1" data-recalc-dims="1" data-original-width="450"></a></div>
<p><span><b><br></b></span><span>The </span>capabilities<span> of the quantmod package in an earlier post (see </span><a rel="nofollow" href="http://www.r-chart.com/2010/06/stock-analysis-using-r.html" target="_blank">http://www.r-chart.com/2010/06/stock-analysis-using-r.html</a><span>) where a listing of other functions that can be applied is included.</span><br><span><br></span><span>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.  </span><b> </b><br><span><b><br></b></span><span><b><br></b></span></p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://www.r-chart.com/2017/07/investigating-cryptocurrencies-part-ii.html"> R-Chart</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/2NQB5iWs554" height="1"></a></div>