Yes, determining if a cryptocurrency's price is ascending or descending purely based on the comparison of today's price with the price 5 days later is a simplistic approach. This method doesn't take into account the volatility or the day-to-day fluctuations that occur within those 5 days. For a more nuanced understanding, several alternative approaches can be used:
-
Moving Averages: Calculate moving averages for the time window (like a simple moving average or an exponential moving average) and compare the current price to the moving average. If the current price is above the moving average, it can be considered as an ascending trend and vice versa.
-
Trendlines: Construct trendlines by connecting significant lows/highs over a period to assess the direction of the price. The slope of the trendline can indicate the trend.
-
Directional Movement Index (DMI) and Average Directional Index (ADX): Use these technical indicators to determine the strength of the price movements. The ADX value can indicate whether the trend is strong or weak while DMI can show whether the trend is up or down.
-
Price Rate of Change (ROC): ROC measures the percentage change in price between the current price and the price a certain number of periods ago. A positive ROC indicates an upward trend, while a negative ROC indicates a downward trend.
-
Higher Highs and Lower Lows: During an uptrend, the asset typically makes higher highs and higher lows. Conversely, during a downtrend, it typically makes lower highs and lower lows. You can assess the sequence of highs and lows.
You can also employ machine learning approaches like time series analysis or sequence modeling (using RNNs, LSTMs, or Transformer-based models) that take into account the temporal order and can potentially capture more complex patterns in price movements.
Here's an example using moving averages, which is a commonly used method to assess trends:
import pandas as pd
# Load your historical data
df = pd.read_csv('your_cryptocurrency_data.csv')
# Calculate the 5-day Simple Moving Average (SMA)
df['5_day_SMA'] = df['close'].rolling(window=5).mean()
# Shift the SMA by one day to avoid lookahead bias
df['5_day_SMA'] = df['5_day_SMA'].shift(1)
# Define your labels based on the trend direction derived from comparing today's close price and today's SMA
df['trend_label'] = df.apply(lambda row: 2 if row['close'] > (1.05 * row['5_day_SMA']) else
1 if row['close'] > (1.02 * row['5_day_SMA']) else
0 if row['close'] > (0.98 * row['5_day_SMA']) and row['close'] < (1.02 * row['5_day_SMA']) else
-1 if row['close'] < (0.98 * row['5_day_SMA']) and row['close'] > (0.95 * row['5_day_SMA']) else
-2, axis=1)
# Drop rows that have NaN values after applying rolling mean
df = df.dropna()
# Save the labeled data
df.to_csv('your_labeled_data.csv', index=False)
This script uses close prices to calculate a 5-day simple moving average, then compares the close price with the SMA to determine the trend and assigns labels according to the policy you've described. Adjustments may still be needed to fit your exact requirements.