Skip to content
Bitcoin performance against other assets
0
  • AI Chat
  • Code
  • Report
  • As a hobbyist, should you invest in Bitcoin?

    📖 Background

    You work as an analyst at an investment fund in New York. Your CFO wants to explore if it is a good idea to invest some of the fund's assets in Bitcoin. You have to prepare a report on this asset and how it compares to the stock market in general.

    # import modules and install pyfolio
    import pandas as pd
    import numpy as np
    import matplotlib.pyplot as plt
    import seaborn as sns
    import plotly.graph_objects as go
    
    !pip install pyfolio
    import pyfolio as pf
    from pypfopt import risk_models
    from pypfopt import expected_returns
    from pypfopt.efficient_frontier import EfficientFrontier
    bitcoin = pd.read_csv('./data/bitcoin-usd.csv', parse_dates=['date'])
    bitcoin.head(2)
    sp500 = pd.read_csv('./data/sp500.csv', parse_dates=['date'])
    sp500.head(2)
    monthly_data = pd.read_csv('./data/monthly_data.csv', parse_dates=['date'])
    monthly_data.head(2)

    1. Introduction

    Anno 2023, with the benefit of hindsight, we know that the high volatility associated with Bitcoin can make it skyrocket high and let it tumble down the other day. Today, for the worse in some cases. Yet, for this study case we would like to remain objective to the data were given.

    In the framework of this study case, we seek to find an answer on whether investing in Bitcoin will be beneficial for our fund and lies in the same philosophy of the fund's investment strategy.

    We will keep this report within the boundaries of the study case and formulate an answer only with the given data.

    We do want to state that the report in itself is not sufficient enough to be considered as an actual strategy but rather as a part of a larger whole that could determine an investment strategy.

    In this report we focus on the behaviour shown in historical data and we try to answer the following questions:

    1. How does the performance of Bitcoin compare to the S&P 500 and the price of Gold?
    2. What volatility profile does Bitcoin have and how does it compare to the other assets?
    3. Is Bitcoin a suitable hedge to fight inflation?
    4. Can Bitcoin improve the performance of the portfolio whilst the fund is seeking to lower its volatility in the portfolio.

    2. Data Exploration and cleaning

    2.1 Available data

    Three data sets were provided: one for Bitcoin, one for Standard's & Poor 500 and one for Gold price & Consumer Price Index. The sets contained the following data points:

    Bitcoin and S&P 500 daily data
    • "date" - date from September 17, 2014 to November 17, 2021
    • "open" - the price at the beginning of the trading day
    • "high" - the highest price reached that day
    • "low" - the lowest price reached that day
    • "close" - the price at the closing of the trading day
    • "volume" - how many Bitcoin were traded that day
    Gold and CPI as monthly data
    • "date" - date from September, 2014 to November, 2021
    • "gold_usd" - price in usd of gold for that month
    • "cpi_us" - the inflation index for the US for that month (cpi = consumer price index)
    Data integrity

    All the data is in the expected datatypes. It is worth noting that Bitcoin data goes from Monday to Sunday, where S&P 500 is from Monday to Friday. In order to start comparing, we will reshape the data. Four faulty rows from the Bitcoin data set were removed. All the data spans a period of roughly seven years.

    Offset Gold & CPI by minus one day

    The published CPI always refers to the previous month, i.e. 2014-10-01 refers to September. The Gold price is published on the first of the month. To be able to compare the performances of both assets compared to Bitcoin and S&P 500, the date column in the data set has been offset by minus one day so the datapoints match the month to which the datapoints apply.

    Resample Bitcoin and S&P 500 to Monthly sets

    For the first chapter we will be focussing on returns of the assets and there resample to the least accurate time scale, i.e. per Month. The Bitcoin and S&P 500 data set will be resampled on aggregated mean to create new, monthly sets. Starting from section 3.2, we will again use daily prices because the aggregated mean discards volatility of assets. If any other manipulation is present, it will be explicitly mentioned.

    Merging into one set

    Finally, the three data sets were merged in one data set for easier visualisation later on.

    data set info
    bitcoin.info()
    sp500.info()
    monthly_data.info()
    Check NaN's

    What are the four NaN's? Sufficient data present to discard four rows.

    # Filter rows with NaN values
    display(bitcoin[bitcoin.isna().any(axis=1)])
    bitcoin.dropna(inplace=True)
    bitcoin.info()
    Check first/last date and data entries
    Hidden code