Back to Openbb

Ethereum Crypto Trend Analysis with OpenBB

examples/EthereumTrendAnalysis.ipynb

4.7.03.9 KB
Original Source

Ethereum Crypto Trend Analysis with OpenBB

Description

This notebook showcases the application of technical analysis techniques to explore Ethereum price trends and volatility. It utilizes OpenBB's historical data to calculate and visualize moving averages, analyze trading volume, and assess price volatility. The notebook demonstrates how these tools can be employed to gain insights into market dynamics and potentially inform investment decisions.

Author

MacBobby Chibuzor

The dependencies for running this includes openbb, pandas, and matplotlib.

python
!pip install openbb -q
python
from openbb import obb
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np

# Download historical Ethereum (ETH) to USD price data
eth_data = obb.crypto.price.historical(symbol='ETH-USD', interval='1d', start_date='2024-02-01', end_date='2024-06-01')

# Convert to DataFrame
df = eth_data.to_df()

# Calculate moving averages
df['MA50'] = df['close'].rolling(window=50).mean()
df['MA200'] = df['close'].rolling(window=200).mean()

# Calculate daily returns and volatility
df['Daily_Return'] = df['close'].pct_change()
df['Volatility'] = df['Daily_Return'].rolling(window=30).std() * np.sqrt(252)

# Visualize the Ethereum price trend with moving averages
plt.figure(figsize=(12, 6))
plt.plot(df.index, df['close'], label='Price')
plt.plot(df.index, df['MA50'], label='50-day MA')
plt.plot(df.index, df['MA200'], label='200-day MA')
plt.title('Ethereum Price with Moving Averages (Feb 1 - Jun 1, 2024)')
plt.xlabel('Date')
plt.ylabel('Price (USD)')
plt.legend()
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()

# Analyze daily trading volume for Ethereum
plt.figure(figsize=(12, 6))
plt.bar(df.index, df['volume'])
plt.title('Ethereum Trading Volume (Feb 1 - Jun 1, 2024)')
plt.xlabel('Date')
plt.ylabel('Volume')
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()

# Plot the 30-day rolling volatility of Ethereum prices
plt.figure(figsize=(12, 6))
plt.plot(df.index[30:], df['Volatility'].iloc[30:])
plt.title('Ethereum 30-Day Rolling Volatility (Mar 2 - Jun 1, 2024)')
plt.xlabel('Date')
plt.ylabel('Volatility')
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()

# Additional quantitative analysis
print("\nQuantitative Analysis:")
print(f"Current Price: ${df['close'].iloc[-1]:.2f}")
print(f"Price Change (Start to End): {((df['close'].iloc[-1] / df['close'].iloc[0]) - 1) * 100:.2f}%")
print(f"Highest Price: ${df['high'].max():.2f}")
print(f"Lowest Price: ${df['low'].min():.2f}")
print(f"Average Daily Return: {df['Daily_Return'].mean() * 100:.2f}%")
print(f"Average Daily Volume: {df['volume'].mean():.0f}")
print(f"Current Volatility: {df['Volatility'].iloc[-1] * 100:.2f}%")

# Identify potential buy/sell signals based on moving average crossovers
df['Signal'] = np.where(df['MA50'] > df['MA200'], 1, 0)
df['Position'] = df['Signal'].diff()

print("\nTrading Signals based on MA Crossover:")
print(df[df['Position'] == 1][['close', 'MA50', 'MA200']].to_string())  # Buy signals
print(df[df['Position'] == -1][['close', 'MA50', 'MA200']].to_string())  # Sell signals

# Calculate Relative Strength Index (RSI)
def calculate_rsi(data, window=14):
    delta = data.diff()
    gain = (delta.where(delta > 0, 0)).rolling(window=window).mean()
    loss = (-delta.where(delta < 0, 0)).rolling(window=window).mean()
    rs = gain / loss
    return 100 - (100 / (1 + rs))

df['RSI'] = calculate_rsi(df['close'])

print("\nRSI Analysis:")
print(f"Current RSI: {df['RSI'].iloc[-1]:.2f}")
print("Overbought periods (RSI > 70):")
print(df[df['RSI'] > 70][['close', 'RSI']].to_string())
print("\nOversold periods (RSI < 30):")
print(df[df['RSI'] < 30][['close', 'RSI']].to_string())

print("\nEthereum price and volume analysis completed!")