Okay, so recently I’ve been moving into using my Python knowledge to look at and analyze financial data. We know that the FED is next scheduled to meet on December 17-18 of this year. Many are predicting that we will see a decrease in interest rates.

So, if you have your money in a High-Yield Savings Account (HYSA)—which you obviously should—would it make more sense to move it elsewhere … say, into Crypto? Thus, I set the task of answering this question and wanting to see if I could do it with all my new programming skills. Well—off we go, let’s write some code!

What you’ll need ahead of time is an API Key from FRED—you can get this simply by creating a (free) account—, which will allow us to grab the current FED interest rate. Other than that, we should be good to go!


import yfinance as yf
import pandas as pd
from datetime import datetime, timedelta
import matplotlib.pyplot as plt
import requests
import json

# Function to load configuration from a JSON file
def load_config(file_path):
    with open(file_path, 'r') as file:
        config = json.load(file)
    return config

# Load configuration
config = load_config('config/config.json')

# Extract the FRED API key from the configuration
fred_api_key = config['fred_API_KEY']

# Function to fetch the current Federal Reserve interest rate
def fetch_fed_interest_rate(api_key):
    url = f"https://api.stlouisfed.org/fred/series/observations?series_id=FEDFUNDS&api_key={api_key}&file_type=json"
    response = requests.get(url)
    data = response.json()
    if 'observations' not in data:
        print("Error: 'observations' key not found in the response data")
        print(data)
        return None
    latest_observation = data['observations'][-1]
    return float(latest_observation['value']) / 100  # Convert to decimal

# Fetch the current Federal Reserve interest rate
current_fed_rate = fetch_fed_interest_rate(fred_api_key)
if current_fed_rate is None:
    raise ValueError("Failed to fetch the current Federal Reserve interest rate")

# Define potential reductions in the interest rate
rate_reductions = [0.25, 0.5, 0.75, 1.0]  # Reductions in percentage points

# Define the investment period (e.g., 1 year)
investment_period_days = 365

# Define the amount of money to invest
initial_investment = 9017.58  # $10,000

# Define the end date as today and the start date as one year ago
end_date = datetime.today().strftime('%Y-%m-%d')
start_date = (datetime.today() - timedelta(days=investment_period_days)).strftime('%Y-%m-%d')

# Fetch historical Bitcoin price data
btc_data = yf.download('BTC-USD', start=start_date, end=end_date)

# Calculate the returns from Bitcoin
btc_start_price = btc_data['Close'].iloc[0]
btc_end_price = btc_data['Close'].iloc[-1]
btc_return = (btc_end_price - btc_start_price) / btc_start_price

# Calculate the returns from the HYSA for different interest rate scenarios
hysa_returns = [current_fed_rate - reduction for reduction in rate_reductions]

# Calculate the final amounts for Bitcoin and HYSA
final_amount_btc = initial_investment * (1 + btc_return)
final_amount_hysa = initial_investment * (1 + current_fed_rate)
final_amounts_hysa_reductions = [initial_investment * (1 + hysa_return) for hysa_return in hysa_returns]

# Print the results
print(f"Initial Investment: ${initial_investment}")
print(f"Bitcoin Return: {btc_return * 100:.2f}%")
print(f"Final Amount if Invested in Bitcoin: ${final_amount_btc:.2f}")
print(f"Final Amount if Kept in HYSA: ${final_amount_hysa:.2f}")
for reduction, final_amount_hysa_reduction in zip(rate_reductions, final_amounts_hysa_reductions):
    print(f"HYSA Return with {reduction}% reduction: ${final_amount_hysa_reduction:.2f}")

# Plot the results
# Plot 1: Comparison with different interest rate reductions
labels_reductions = ['Bitcoin'] + [f'HYSA -{reduction}%' for reduction in rate_reductions]
final_amounts_reductions = [final_amount_btc] + final_amounts_hysa_reductions

plt.figure(figsize=(12, 8))
plt.bar(labels_reductions, final_amounts_reductions, color=['orange'] + ['blue'] * len(rate_reductions))
plt.xlabel('Investment Option')
plt.ylabel('Final Amount ($)')
plt.title('Comparison of Investment in Bitcoin vs. HYSA with Different Interest Rate Reductions')
plt.xticks(rotation=45)
plt.grid(True)
plt.show()

# Plot 2: Comparison without interest rate reductions
labels = ['Bitcoin', 'HYSA']
final_amounts = [final_amount_btc, final_amount_hysa]

plt.figure(figsize=(12, 8))
plt.bar(labels, final_amounts, color=['orange', 'blue'])
plt.xlabel('Investment Option')
plt.ylabel('Final Amount ($)')
plt.title('Comparison of Investment in Bitcoin vs. HYSA')
plt.xticks(rotation=45)
plt.grid(True)
plt.show()

So, this code produces the following plot:

bitcoin_vs_hysa

The output to the console is as follows:

bitcoin_vs_hysa_console_output

Now, as everyone likes to note, crypto can be extremely volatile, so let’s see if we can incorporate that into our calculations, using the “Sharpe Ratio”, which is often utilized to measure volatility. If we add this we get the following console output:

bitcoin_vs_hysa_including_sharpe

Finally, we could have a look at things based on different potential reductions by the FED of the interest rate:

different_FED_interest_rate_reductions

Obviously, there is much to consider here:

  1. Volatility: Bitcoin is clearly quite volatile—as the Sharpe Ratio is high.
  2. Risk: If we have a high risk tolerance, then Bitcoin is fine; if we are more conservative, then HYSAs are probably the way to go.
  3. If we want to go long-term and are okay with the short-term volatility, then we move our monies to Bitcoin; if we want more stable and predictable outcomes, then we keep everything in our HYSA.

Anyways—we’ll watch the markets, obviously, and much more to come, as promised, as always.

P.S. For those that want a bit more data—how about a plot of the value of a dollar over time compared to some popular cryptocurrencies? Kind of an eye-opening plot, for some:

value_of_a_dollar

Code for this plot is available in this repo.

P.P.S. All this research on crypto recently got me thinking of one of my most favorite songs by salem ilese, “Crypto Boy,”, lol.