How to get crypto data

How to get crypto data

 Snehasish CHINARA

In this article, Snehasish CHINARA (ESSEC Business School, Grande Ecole Program – Master in Management, 2022-2024) explains how to get crypto data.

Types of data

Number of coins

The information on the number of coins in circulation for a given currency is important to compute its market capitalization. Market capitalization is calculated by multiplying the current price of the cryptocurrency by its circulating number of coins (supply). This metric gives a rough estimate of the cryptocurrency’s total value within the market and its relative size compared to other cryptocurrencies. A lower circulating supply often implies a greater level of scarcity and rarity.

For cryptocurrencies (unlike fiat money), the number of coins in circulation is given by a mathematical formula. The number of coins may be limited (like the Bitcoin) or unlimited (like Ethereum and Dogecoin) over time.

Cryptocurrencies with limited supplies, such as Bitcoin’s maximum supply of 21 million coins, can be perceived as more valuable due to their finite nature. Scarcity can contribute to investor interest and potential price appreciation over time. A lower circulating supply might indicate the potential for future adoption and value appreciation, as the limited supply can create scarcity-driven demand, especially if the cryptocurrency gains more utility and usage.

Bitcoin’s blockchain also relies on a key equation to steadily allow new BTC to be introduced. The equation below gives the total supply of bitcoins:

Total supply of bitcoins

Figure 1 below represents the evolution of the supply of Bitcoins.

Figure 1. Evolution of the supply of Bitcoins

Source: computation by the author.

Market price of a coin

The market price of a cryptocurrency in the market holds crucial insights into how well the cryptocurrency is faring. Although not the sole factor, the market price significantly contributes to evaluating the cryptocurrency’s performance and its prospects. The market price of a cryptocurrency is a dynamic and intricate element that reflects a multitude of factors, both intrinsic and extrinsic. The gradual rise in market value over time indicates a willingness among investors and traders to offer higher prices for the cryptocurrency. This signifies a rising interest and strong belief in the project’s potential for the future. The market price reflects the collective sentiment of investors and traders. Comparing the market price of a cryptocurrency to other similar cryptocurrencies or benchmark assets like Bitcoin can provide insights into its relative strength and performance within the market. A rising market price can indicate increasing adoption of the cryptocurrency for various use cases. Successful projects tend to attract more users and real-world applications, which can drive up the price.

The value of cryptocurrencies in the market is influenced by a variety of elements, with each factor contributing uniquely to their pricing. One of the most significant influences is market sentiment and investor psychology. These factors can cause prices to shift based on positive news, regulatory changes, or reactive selling due to fear. Furthermore, the real-world implementation and usage of a cryptocurrency are crucial for its prosperity. Concrete use cases such as Decentralized Finance (DeFi), Non-Fungible Tokens (NFTs), and international transactions play a vital role in creating demand and propelling price appreciation. Meanwhile, adherence to basic economic principles is evident in the supply-demand dynamics, where scarcity due to limited issuance, halving events, and token burns interact with the balance between supply and demand.

With the number of coins in circulation, the information on the price of coins for a given currency is also important to compute its market capitalization.

Figure 2 below represents the evolution of the price of Bitcoin in US dollar over the period October 2014 – August 2023. The price corresponds to the “closing” price (observed at 10:00 PM CET at the end of the month).

Figure 2. Evolution of the Bitcoin price
Evolution of the Bitcoin price
Source: computation by the author (data source: Yahoo! Finance).

Trading volume

Trading volume is crucial when assessing the health, reliability, and potential price movements of a cryptocurrency. Trading volume refers to the total amount of a cryptocurrency that is bought and sold within a specific time frame, typically measured in units of the cryptocurrency (e.g., BTC) or in terms of its equivalent value in another currency (e.g., USD).

Trading volume directly mirrors market liquidity, with higher volumes indicative of more liquid markets. This liquidity safeguards against drastic price fluctuations when trading, contrasting with low-volume scenarios that can breed volatility, where even a single substantial trade may disproportionately shift prices. Price alterations are most reliable and meaningful when accompanied by substantial trading volume. Price movements upheld by heightened volume often hold greater validity, potentially pointing to more pronounced market sentiment. When price surges parallel rising trading volume, it suggests a sustainable upward trajectory. Conversely, low trading volume amid rising prices may hint at a forthcoming correction or reversal. Scrutinizing the correlation between price oscillations and trading volume can uncover potential divergences. For instance, ascending prices coupled with dwindling trading volume may suggest a weakening trend.

Figure 3 below represents the evolution of the monthly trading volume of Bitcoin over the period October 2014 – July 2023.

Figure 3. Evolution of the trading volume of Bitcoin
Evolution of the trading volume of Bitcoin
Source: computation by the author (data source: Yahoo! Finance).

Bitcoin data

You can download the Excel file with Bitcoin data used in this post as an illsutration.

Download the Excel file with Bitcoin data

Python code

You can download the Python code used to download the data from Yahoo! Finance.

Python script to download Bitcoin historical data and save it to an Excel sheet:

import yfinance as yf
import pandas as pd

# Define the ticker symbol and date range
ticker_symbol = “BTC-USD”
start_date = “2020-01-01”
end_date = “2023-01-01”

# Download historical data using yfinance
data = yf.download(ticker_symbol, start=start_date, end=end_date)

# Create a Pandas DataFrame
df = pd.DataFrame(data)

# Create a Pandas Excel writer object
excel_writer = pd.ExcelWriter(‘bitcoin_historical_data.xlsx’, engine=’openpyxl’)

# Write the DataFrame to an Excel sheet
df.to_excel(excel_writer, sheet_name=’Bitcoin Historical Data’)

# Save the Excel file
excel_writer.save()

print(“Data has been saved to bitcoin_historical_data.xlsx”)

# Make sure you have the required libraries installed and adjust the “start_date” and “end_date” variables to the desired date range for the historical data you want to download.

APIs

Calculating the total number of Bitcoins in circulation over time
Access – Bitcoin Blockchain data
By running a Bitcoin node or by using blockchain data providers like Blockchain.info, Blockchair, or a similar service.

Extract Block Data: Once you have access to the blockchain data, you would need to extract information from each block. Each block contains a record of the transactions that have occurred, including the creation (mining) of new Bitcoins in the form of a “Coinbase” transaction.

Calculate Cumulative Supply: You can calculate the cumulative supply of Bitcoins by adding up the rewards from each block’s Coinbase transaction. Initially, the block reward was 50 Bitcoins, but it halves approximately every four years due to the Bitcoin halving events. So, you’ll need to account for these halving in your calculations.

Code – python

import requests

# Replace ‘YOUR_API_KEY’ with your CoinMarketCap API key
api_key = ‘YOUR_API_KEY’

# Define the endpoint URL for CoinMarketCap’s API
url = ‘https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest’

# Define the parameters for the request
params = {
‘symbol’: ‘BTC’,
‘convert’: ‘USD’,
‘CMC_PRO_API_KEY’: api_key
}

# Send the request to CoinMarketCap
response = requests.get(url, params=params)

# Parse the response JSON
data = response.json()

# Extract the circulating supply from the response
circulating_supply = data[‘data’][‘BTC’][‘circulating_supply’]

print(f”Current circulating supply of Bitcoin: {circulating_supply} BTC”)

## Replace ‘YOUR_API_KEY’ with your actual CoinMarketCap API key.

Why should I be interested in this post?

Cryptocurrency data is becoming increasingly relevant in these fields, offering opportunities for research, data analysis skill development, and even career prospects. Whether you’re aiming to conduct research, stay informed about the evolving financial landscape, or simply enhance your data analysis abilities, understanding how to access and work with crypto data is an asset. Plus, as the cryptocurrency industry continues to grow, this knowledge can open new career paths and improve your personal finance decision-making. In a rapidly changing world, diversifying your knowledge with cryptocurrency data acquisition skills can be a wise investment in your future.

Related posts on the SimTrade blog

▶ Alexandre VERLET Cryptocurrencies

▶ Youssef EL QAMCAOUI Decentralised Financing

▶ Hugo MEYER The regulation of cryptocurrencies: what are we talking about?

Useful resources

APIs

CoinMarketCap Source of API keys and program

CoinGecko Source of API keys and Programs

CryptoNews Source of API keys and Programs

Data sources

Yahoo! Finance Historical data for Bitcoin

Coinmarketcap Historical data for Bitcoin

Blockchain.com Market Data and charts on Bitcoin history

About the author

The article was written in October 2023 by Snehasish CHINARA (ESSEC Business School, Grande Ecole Program – Master in Management, (2022-2024).

Programming Languages for Quants

Programming Languages for Quants

Jayati WALIA

In this article, Jayati WALIA (ESSEC Business School, Grande Ecole Program – Master in Management, 2019-2022) presents an overview of popular programming languages used in quantitative finance.

Introduction

Finance as an industry has always been very responsive to new technologies. The past decades have witnessed the inclusion of innovative technologies, platforms, mathematical models and sophisticated algorithms solve to finance problems. With tremendous data and money involved and low risk-tolerance, finance is becoming more and more technological and data science, blockchain and artificial intelligence are taking over major decision-making strategies by the power of high processing computer algorithms that enable us to analyze enormous data and run model simulations within nanoseconds with high precision.

This is exactly why programming is a skill which is increasingly in demand. Programming is needed to analyze financial data, compute financial prices (like options or structured products), estimate financial risk measures (like VaR) and test investment strategies, etc. Now we will see an overview of popular programming languages used in modelling and solving problems in the quantitative finance domain.

Python

Python is general purpose dynamic high level programming language (HLL). It’s effortless readability and straightforward syntax allows not just the concept to be expressed in relatively fewer lines of code but also makes it’s learning curve less steep.

Python possesses some excellent libraries for mathematical applications like statistics and quantitative functions such as numpy, scipy and scikit-learn along with the plethora of accessible open source libraries that add to its overall appeal. It supports multiple programming approaches such as object-oriented, functional, and procedural styles.

Python is most popular for data science, machine learning and AI applications. With data science becoming crucial in the financial services industry, it has consequently created an immense demand for Python, making it a programming language of top choice.

C++

The finance world has been dominated by C++ for valid reasons. C++ is one of the essential programming languages in the fintech industry owing to its execution speed. Developers can leverage C++ when they need to programme with advanced computations with low latency in order to process multiple functions fasters such as in High Frequency Trading (HFT) systems. This language offers code reusability (which is crucial in multiple complex quantitative finance projects) to programmers with a diverse library comprising of various tools to execute.

Java

Java is known for its reliability, security and logical architecture with its object-oriented programming to solve complicated problems in the finance domain. Java is heavily used in the sell-side operations of finance involving projects with complex infrastructures and exceptionally robust security demands to run on native as well as cross-platform tools. This language can help manage enormous sets of real-time data with the impeccable security in bookkeeping activity. Financial institutions, particularly investment banks, use Java and C# extensively for their entire trading architecture, including front-end trading interfaces, live data feeds and at times derivatives’ pricing.

R

R is an open source scripting language mostly used for statistical computing, data analytics and visualization along with scientific research and data science. R the most popular language among mathematical data miners, researchers, and statisticians. R runs and compiles on multiple platforms such as Unix, Windows and MacOS. However, it is not the easiest of languages to learn and uses command line scripting which may be complex to code for some.

Scala

Scala is a widely used programming language in banks with Morgan Stanley, Deutsche Bank, JP Morgan and HSBC are among many. Scala is particularly appropriate for banks’ front office engineering needs requiring functional programming (programs using only pure functions that are functions that always return an immutable result). Scala provides support for both object-oriented and functional programming. It is a powerful language with an elegant syntax.

Haskell and Julia

Haskell is a functional and general-purpose programming language with user-friendly syntax, and a wide collection of real-world libraries for user to develop the quant solving application using this language. The major advantage of Haskell is that it has high performance, is robust and is useful for modelling mathematical problems and programming language research.

Julia, on the other hand, is a dynamic language for technical computing. It is suitable for numerical computing, dynamic modelling, algorithmic trading, and risk analysis. It has a sophisticated compiler, numerical accuracy with precision along with a functional mathematical library. It also has a multiple dispatch functionality which can help define function behavior across various argument combinations. Julia communities also provide a powerful browser-based graphical notebook interface to code.

Related posts on the SimTrade blog

   ▶ Jayati WALIA Quantitative Finance

   ▶ Jayati WALIA Quantitative Risk Management

   ▶ Jayati WALIA Value at Risk

   ▶ Akshit GUPTA The Black-Scholes-Merton model

Useful Resources

Websites

QuantInsti Python for Trading

Bankers by Day Programming languages in FinTech

Julia Computing Julia for Finance

R Examples R Basics

About the author

The article was written in October 2021 by Jayati WALIA (ESSEC Business School, Grande Ecole Program – Master in Management, 2019-2022).