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.
Get the list of all coins available in CoinMarketCap.
Retrieve the current prices and market capitalization data for the top 20 coins (by Market Capitalization.)
Plot a bar graph to see the top 20 coins by market capitalization.
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.”
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.”
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.”
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.
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.