Analyzing Crypto-currency Data With R – Part 1: Exercises

[This article was first published on R-exercises, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

R provides a lot of interesting packages to analyze cryptocurrency markets. The goal of this exercise is to introduce you to one of the packages (crypto) to retrieve cryptocurrency data in R, as well as building some basic plots to understand how these markets have behaved in recent times.

Cryptocurrencies are digital assets that facilitates exchange of value between two parties. They are intended to be secure and safe. Encryption systems are used to regulate the generation of coins and verify the exchange of value between the parties involved. Cryptocurrencies have recently taken the world by storm, grabbing attention from investors, academia, financial institutions, governments and individuals.

The crypto package uses data provided by ‘Cryptocurrency Market Capitalizations’ (here) to retrieve data on cryptocurrencies. CoinMarketCap is a website that provides present and historical data on numerous cryptocurrencies through web scraping tables.

Answers to these exercises are available here.

Please install and load the crypto package, along with all its dependencies. You will also need to be connected to the internet to retrieve data from the website. This exercise also assumes basic knowledge of ggplot2 for graph plotting and will require you to load the package.

Exercise 1
Get the list of all coins available in CoinMarketCap.

Exercise 2
Retrieve the current prices and market capitalization data for the top 20 coins (by Market Capitalization.)

Exercise 3
Plot a bar graph to see the top 20 coins by market capitalization.

Exercise 4
Which coin (name) among the top 20 has been most profitable in the last 7 days? Store the name in a variable called “most_profitable.”

Exercise 5
Retrieve data on historical prices from May 1st, 2017 to May 1st, 2018 for the most_profitable coin. Store data in a variable called “historical_data.”

Exercise 6
Plot the closing price in a line graph to see how the cryptocurrency price has fluctuated in recent times from “historical_data.” Save the plot as a variable named “p.”

Exercise 7
Cryptocurrency prices fluctuate a lot within a day. Let’s add the absolute price spread (maximum.price – minimum.price) from “historical_data” in the graph plotted above. In case the plot doesn’t come out well due to bad data (like in the figure in solutions page), try the same graph for “Bitcoin.” Replace “most_profitable” with “Bitcoin” in the solutions for Ex. 5,6 and 7.

Exercise 8

Now, let’s retrieve historical data for a few more coins. Use the function getCoins() to retrieve data from May 1st,  2017 to May 1st, 2018 for the top 20 coins (hint: use the “coins_data” variable.)

We will use the above data for exploring Cryptocurrency markets further in coming exercises.

To leave a comment for the author, please follow the link and comment on their blog: R-exercises.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)