Getting the CCI30 Index Current Makeup

[This article was first published on Steve's Data Tips and Tricks, 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.

Introduction

The CCI30 Crypto Index is a cryptocurrency index that tracks the performance of the top 30 cryptocurrencies by market capitalization. It was created in 2017 by a team of researchers and analysts from the CryptoCompare and MVIS indices.

The CCI30 Crypto Index is designed to provide a broad-based and representative measure of the cryptocurrency market’s overall performance. It includes a diverse range of cryptocurrencies, such as Bitcoin, Ethereum, Litecoin, Ripple, and many others. The index is weighted by market capitalization, with each cryptocurrency’s weight determined by its market capitalization relative to the total market capitalization of all 30 cryptocurrencies.

The CCI30 Crypto Index has become a popular benchmark for the cryptocurrency market, as it offers a comprehensive view of the market’s performance, rather than just focusing on one particular cryptocurrency. It is often used by investors, traders, and researchers to analyze trends and make investment decisions.

One notable feature of the CCI30 Crypto Index is that it is rebalanced every quarter. This means that the composition of the index is adjusted to reflect changes in the market capitalization of the constituent cryptocurrencies. This helps to ensure that the index remains representative of the overall cryptocurrency market.

Overall, the CCI30 Crypto Index provides a useful tool for tracking the performance of the cryptocurrency market. It is a valuable resource for investors, traders, and researchers who are interested in this exciting and rapidly evolving field.

Code Explanation

Let’s break it down step by step:

  • The first line of the code loads the “dplyr” package, which provides a set of functions for data manipulation.
  • The second line of the code reads the HTML code from the website “https://cci30.com/” using the “read_html” function from the “xml2” package.
  • The next two blocks of code extract two tables from the HTML document using the “html_node” function from the “rvest” package. The tables are located at two different XPaths in the HTML document.
  • The extracted tables are then converted into tibbles using the “as_tibble” function from the “tibble” package. The tibbles are further transformed by selecting only the columns from the second to the fifth column using the “select” function from the “dplyr” package.
  • The column names of the tibbles are then set using the “set_names” function from the “purrr” package.
  • Finally, the two tibbles are combined using the “union” function from the “dplyr” package, and the resulting tibble is printed to the console.

In summary, the code is extracting two tables from a website, transforming them into tibbles, selecting a subset of columns, renaming the columns, and combining them into a single tibble.

Example

cci30 <- xml2::read_html("https://cci30.com/")

tbl1 <- cci30 |>
    rvest::html_node(xpath = "/html/body/div[2]/div/div/div/div[2]/div[1]/table") |>
    rvest::html_table(header = 1) |>
    tibble::as_tibble() |>
    dplyr::select(2:5) |>
    purrr::set_names(
        "Coin","Price","Mkt Cap","Daily Change"
    )

tbl2 <- cci30 |>
    rvest::html_node(xpath = "/html/body/div[2]/div/div/div/div[2]/div[2]/table") |>
    rvest::html_table(header = 1) |>
    tibble::as_tibble() |>
    dplyr::select(2:5) |>
    purrr::set_names(
        "Coin","Price","Mkt Cap","Daily Change"
    )

tbl <- tbl1 |>
  dplyr::union(tbl2) |>
  knitr::kable()

tbl
Coin Price Mkt Cap Daily Change
Bitcoin $27,767.24 $536,553,055,078 0.17%
Ethereum $1,735.32 $212,357,972,798 0.04%
BNB $332.92 $52,565,516,823 0.13%
XRP $0.37 $19,087,613,742 0.13%
Cardano $0.33 $11,547,419,916 0.05%
Polygon $1.10 $9,643,536,324 0.17%
Dogecoin $0.07 $9,484,198,878 0.34%
Solana $22.18 $8,507,167,040 0.12%
Polkadot $6.10 $7,119,808,610 0.08%
Shiba Inu $0.00 $6,169,390,592 0.24%
TRON $0.07 $5,936,468,687 0.14%
Litecoin $78.42 $5,685,409,727 0.40%
Avalanche $16.64 $5,418,625,875 0.06%
Uniswap $6.19 $4,716,487,304 0.19%
Chainlink $7.06 $3,649,558,739 0.06%
Cosmos $11.56 $3,309,216,299 0.03%
UNUS SED LEO $3.35 $3,195,413,769 -0.55%
Toncoin $2.38 $2,907,590,168 -0.62%
Monero $151.58 $2,767,118,876 -0.01%
Ethereum Classic $19.58 $2,741,016,944 -6.84%
OKB $44.34 $2,660,455,327 0.56%
Bitcoin Cash $130.60 $2,526,173,508 -0.48%
Stellar $0.09 $2,293,156,708 -0.04%
Cronos $0.07 $1,787,408,658 1.05%
NEAR Protocol $2.00 $1,728,135,015 0.26%
VeChain $0.02 $1,665,251,562 0.33%
Quant $126.33 $1,525,183,149 0.31%
Internet Computer $5.11 $1,516,076,264 0.19%
Algorand $0.21 $1,498,361,340 0.41%
ApeCoin $4.06 $1,496,070,125 0.12%
To leave a comment for the author, please follow the link and comment on their blog: Steve's Data Tips and Tricks.

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)