Study of a BTC strategy combining DCA with the Fear and Greed

Analysis of an investment strategy for the purchase of bitcoin where the DCA (Dollar Cost Average) and the market sentiment, Fear and Greed index, are combined.

The strategy will consist of the moment that would correspond to the periodic purchase (DCA) the Fear and Greed (F&G) metric will be evaluated and if it has a value greater than 50, which is equivalent to a positive market sentiment, in the end, a comparison will be made of this blended strategy against a standard DCA during the period in which Fear and Greed Index data is available, which is February 2018 to the present.

Dollar Cost Averaging (DCA) is a type of strategy that consists of investing the same amount of money from time to time, it is independent of what happens in the market since you will invest the same, even if the price of BTC goes up or down.
This reduces the impact that a market entry at the wrong time can have and minimizes the consequences of high BTC volatility.
Initially it is intended to buy and hold (hodl) but it is not mandatory.
It is a practically neglected option. You invest an amount of money at a certain time and leave it there for a while with the idea that bitcoin will tend to rise in the long term.
It does not require a large initial investment and allows you to plan your risk.

The Fear and Greed Index is a metric published by  that attempts to predict market sentiment based on these 5 indicators:

  • Volatility (25%)
  • Market Volume / Momentum (25%)
  • Social Networks (15%)
  • Dominance (10%)
  • Trends (10%)


This article is not investment advice, act according to your own criteria.

The Python libraries that will be used in the study are the following.

import pandas as pd
import requests
import matplotlib.pyplot as plt
import yfinance as yf
from pylab import rcParams
import as px
import warnings

rcParams['figure.figsize'] = 10, 5

Download Bitcoin price data from Yahoo Finance.

df ='BTC-USD', interval = '1d')[['Close']]
df.rename(columns = {'Close':'close'}, inplace=True) = 'timestamp'
df['timestamp'] = df.index
df.reset_index(drop=True, inplace=True)
df.timestamp = pd.to_datetime(df.timestamp, unit='s').dt.tz_localize(None)
df.set_index(df.timestamp, inplace=True)
df.drop(['timestamp'], axis=1, inplace=True)

Download F&G data from alternative

r = requests.get('')

# Show fear and greed index from February 2018.
# Values range from 0 to 100, with low values indicating fear and high values indicating euphoria.
df1 = pd.DataFrame(r.json()['data'])
df1.value = df1.value.astype(int)
df1.timestamp = pd.to_datetime(df1.timestamp, unit='s')
df1.set_index(df1.timestamp, inplace=True)
df1.rename(columns = {'value':'fear_greed', 'timestamp':'date'}, inplace=True)
df1.drop(['time_until_update'], axis=1, inplace=True)

Fear and Greed Index Data Joins Bitcoin Dollar Price Data.

data = df.merge(df1, on='timestamp')
data = data.sort_index()

BTC price chart colored based on market sentiment as marked by the Fear and Greed index.

The bluer colors correspond to the feeling of fear and the more yellowish to euphoria.

It can be seen in the graph that yellowish colors predominate in periods of price increase and in periods of decrease, blue and violet are the most recurrent colors.

fig = px.scatter(data, x="date", y="close", color="fear_greed",
                 title="BTC price with fear and greed index in continuous color")
    "plot_bgcolor": "rgba(0, 0, 0, 0)",
    "paper_bgcolor": "rgba(0, 0, 0, 0)",

A DCA strategy is implemented where BTC is bought once a week and only when the F&G is greater than 50.

limit_fear_greed = 50
buy_dates = pd.date_range(data.index[0], data.index[-1], freq='1W')
data_buy = data[(data.index.isin(buy_dates) & (data.fear_greed > limit_fear_greed))]

# The amount of dollars available weekly to buy is $100.
buy_dca = 100
data_buy['btc_amt'] = buy_dca / data_buy.close
data_buy['btc_amt_sum'] = data_buy.btc_amt.cumsum()

The period for which F&G index data is available is from February 1, 2018 to the present.


2018-02-18 00:00:00
2021-11-14 00:00:00

Calculation of the expenses and benefits of the mixed strategy (DCA and F&G) without taking into account the commissions for the purchase of BTC.

spent = buy_dca * len(data_buy)
amount = data_buy.iloc[-1].btc_amt_sum * data.iloc[-1].close
print("Nº of purchases: \t " + str(len(data_buy)))
print("Spent: \t\t\t $" + str(spent))
print("Gross profit: \t\t $" + str(amount))
print("Net profit: \t\t $" + str(amount - spent))

Nº of purchases: 81
Spent: $8100
Gross profit: $11779.893404192857
Net profit: $3679.893404192857

Weekly chart of the price of bitcoin when the Fear and Greed index is greater than 50.

The circles that appear in the graph indicate the moments of purchase according to this strategy. There are 3 areas of accumulation of them that coincide with the bullish periods of the price.

  • A first area from February to August of the year 2019 where the rise is moderate and the euphoria is less.
  • A second from August 2020 to May 2021 where one of the great bitcoin bull runs occurs and the euphoria is maximum, reaching values of 95 points.
  • And a last one from August 2021 to November 2021 where the euphoria is less but where the ATH (the highest value of all time) is reached on November 9, 2021, since then the fear and greed index has not exceeded the 50 for which no purchase order would have been executed.
fig = px.scatter(data_buy, x="date", y="close", color="fear_greed",
                 title="BTC weekly price with fear and greed index only when F&G > 50")
    "plot_bgcolor": "rgba(0, 0, 0, 0)",
    "paper_bgcolor": "rgba(0, 0, 0, 0)",

Calculation of the performance of a pure DCA strategy where BTC is bought every week.

buy_dates = pd.date_range(data.index[0], data.index[-1], freq='1W')
data_buy_dca_week = data[(data.index.isin(buy_dates))]

# The weekly purchase is calculated in dollars so that the value spent during the period is similar in both cases. 
buy_dca_week = buy_dca * len(data_buy) / len(data_buy_dca_week)
data_buy_dca_week['btc_amt'] = buy_dca_week / data_buy_dca_week.close
data_buy_dca_week['btc_amt_sum'] = data_buy_dca_week.btc_amt.cumsum()


When calculating the benefits of the DCA strategy, the commissions for the purchase of bitcoin are not taken into account either.

spent_dca_week = buy_dca_week * len(data_buy_dca_week)
amount_dca_week = data_buy_dca_week.iloc[-1].btc_amt_sum * data.iloc[-1].close

print("Nº of purchases: \t " + str(len(data_buy_dca_week)))
print("Spent: \t\t\t $" + str(spent_dca_week))
print("Gross profit: \t\t $" + str(amount_dca_week))
print("Net profit: \t\t $" + str(amount_dca_week - spent_dca_week))

Comparative graph showing how the BTC acquired in the mixed strategy of DCA and F&G are accumulated.

In the case of the DCA and F&G line, no data has appeared since November 2021 because since then the Fear and Greed index has not exceeded 50 points.

data_buy['btc_amt_sum'].plot(label='DCA and F&G')

Comparison in numbers of the two investment strategies. 

print("#####\t DCA and F&G Strategy \t#####")
print("Spent: \t\t\t $" + str(spent))
print("Net profit: \t\t $" + str(amount - spent))
print("Accumulated BTC: \t " + str(data_buy.iloc[-1].btc_amt_sum))
print("\n#####\t DCA Strategy \t\t#####")
print("Spent: \t\t\t $" + str(spent_dca_week))
print("Net profit: \t\t $" + str(amount_dca_week - spent_dca_week))
print("Accumulated BTC: \t " + str(data_buy_dca_week.iloc[-1].btc_amt_sum))

DCA and F&G Strategy
Spent: $8100
Net profit: $3679.893404192857
Accumulated BTC: 0.627840393893085

DCA Strategy
Spent: $8100.000000000001
Net profit: $6283.419267711178
Accumulated BTC: 0.7666021506913571

In view of the numbers, the mixed investment strategy in DCA bitcoin and the Fear and Greed index in the period studied is worse than a recurring purchase strategy of sam amount os money.

In this period we would have an expense of 8100 dollars and 0.62 BTC in our account, in the case of the combined strategy that is equivalent to $4527 discounting the purchase expenses and we would have 0.76 BTC if we had opted for a DCA that at today’s price minus the expenses It’s about $7,300.

Link to notebook at kaggle Study Bitcoin strategy DCA with Fear and Greed

Link to Python code on github Study Bitcoin strategy combining DCA with Fear Greed index

Categories: Bitcoin, BTC, Code, Hodl, Notebook, Price, Python, Script, Trader, Trading

Leave a Reply

%d bloggers like this: