Skip to main content

Overview

CryptoView Pro offers three powerful ML models for cryptocurrency predictions:
  • XGBoost: Best for short-term predictions (1-72 hours)
  • Prophet: Optimized for long-term forecasts (1 week - 1 year)
  • Hybrid: Combines both models for optimal accuracy across all timeframes

Quick Start

1. Load and Prepare Data

First, ensure you have sufficient historical data. The system requires at least 500 data points for reliable predictions:
from data.collectors import CryptoDataCollector
from utils.indicators import TechnicalIndicators

# Initialize data collector
collector = CryptoDataCollector('kraken')

# Fetch historical data
df = collector.fetch_ohlcv(
    symbol='BTC/USDT',
    timeframe='1h',
    limit=2000  # Recommended: 2000 points
)

# Add technical indicators
df = TechnicalIndicators.add_all_indicators(df)

2. Choose Your Model

Select the appropriate model based on your prediction horizon:

Short-Term: XGBoost (1-72 hours)

from models.xgboost_model import XGBoostCryptoPredictor, create_prediction_intervals

# Initialize predictor
predictor = XGBoostCryptoPredictor(
    n_estimators=200,
    learning_rate=0.07,
    max_depth=6
)

# Train the model
metrics = predictor.train(df, train_size=0.8)

# Make predictions for next 24 hours
predictions = predictor.predict_future(df, periods=24)
predictions = create_prediction_intervals(predictions, confidence=0.95)

Long-Term: Prophet (1 week - 1 year)

from models.prophet_model import ProphetCryptoPredictor

# Initialize Prophet
predictor = ProphetCryptoPredictor(
    changepoint_prior_scale=0.5,  # Higher = more flexible
    seasonality_prior_scale=10,
    interval_width=0.95
)

# Train
metrics = predictor.train(df)

# Predict next 168 hours (1 week)
predictions = predictor.predict_future(periods=168, freq='H')

Hybrid Model (Best for All Horizons)

from models.hybrid_model import HybridCryptoPredictor

# Initialize hybrid model
predictor = HybridCryptoPredictor()

# Train both models simultaneously
training_info = predictor.train(df)

# Predict with automatic model selection
predictions_dict = predictor.predict_future(df, periods=72)

# Get the recommended prediction
best_prediction = predictor.get_best_prediction(predictions_dict)

Understanding Prediction Horizons

Time HorizonRecommended ModelReasoning
6-72 hoursXGBoostCaptures short-term patterns and momentum
1-3 weeksHybridBalances short-term accuracy with trend
1-3 monthsProphetBetter at long-term trend detection
3+ monthsProphetSeasonality and trend components

Code Example: Dynamic Model Selection

def select_model(forecast_hours: int):
    """Automatically select the best model for the time horizon"""
    if forecast_hours <= 72:
        return 'xgboost'
    elif forecast_hours <= 720:  # 30 days
        return 'hybrid'
    else:
        return 'prophet'

# Usage
forecast_hours = 168  # 1 week
model_type = select_model(forecast_hours)
print(f"Recommended: {model_type}")

Advanced Prediction Features

Multi-Step Predictions

For long-term forecasts, generate predictions iteratively:
# XGBoost iterative prediction (see app.py:226-282)
predictions = []
df_work = df.copy()

for i in range(periods):
    # Create features for last point
    df_features = predictor.create_features(df_work)
    last_row = df_features[predictor.feature_columns].iloc[-1:]
    
    # Scale and predict
    last_row_scaled = predictor.scaler.transform(last_row)
    pred = predictor.model.predict(last_row_scaled)[0]
    predictions.append(pred)
    
    # Add prediction as new data point
    next_datetime = df_work.index[-1] + pd.Timedelta(hours=1)
    new_row = pd.DataFrame({
        'close': [pred],
        'volume': [df_work['volume'].iloc[-1]]
    }, index=[next_datetime])
    
    df_work = pd.concat([df_work, new_row])

Prediction Intervals

Always include confidence intervals to quantify uncertainty:
from models.xgboost_model import create_prediction_intervals

# Add 95% confidence intervals
predictions = create_prediction_intervals(
    predictions,
    confidence=0.95
)

print(predictions[['predicted_price', 'lower_bound', 'upper_bound']])
Example output:
                     predicted_price  lower_bound  upper_bound
2026-03-08 01:00:00        42150.23     41580.12     42720.34
2026-03-08 02:00:00        42189.45     41619.34     42759.56

Aggregated Long-Term Predictions

For predictions beyond 1 week, use aggregated views:
from utils.long_term_predictions import (
    aggregate_predictions,
    get_milestone_predictions,
    create_calendar_view
)

# Daily aggregation
daily_forecast = aggregate_predictions(predictions, aggregation='daily')

# Weekly aggregation (for 2+ weeks)
weekly_forecast = aggregate_predictions(predictions, aggregation='weekly')

# Get specific milestones
milestones = get_milestone_predictions(
    predictions,
    milestones=[7, 14, 30, 60, 90]
)

print(f"Price in 30 days: ${milestones['30d']['price']:.2f}")

Best Practices

1. Data Quality

# Validate data before predictions
if len(df) < 500:
    print("⚠️ Warning: Less than 500 data points")
    print("Recommendation: Use at least 500 points for XGBoost")
    print("                Use at least 1000 points for Prophet")

# Check for missing values
if df.isnull().sum().sum() > 0:
    print("⚠️ Warning: Missing values detected")
    df = df.fillna(method='ffill')  # Forward fill

2. Training Frequency

# Retrain models regularly for best accuracy
from datetime import datetime, timedelta

last_train_date = datetime.now()
retrain_interval = timedelta(hours=24)

if datetime.now() - last_train_date > retrain_interval:
    print("🔄 Retraining model with fresh data...")
    predictor.train(df)
    last_train_date = datetime.now()

3. Combine with Technical Analysis

from utils.indicators import TechnicalIndicators

# Get current signals
signals = TechnicalIndicators.get_signals(df)

# Adjust predictions based on signals
if signals['overall'] == 'sell' and predictions['predicted_price'].iloc[0] > df['close'].iloc[-1]:
    print("⚠️ Prediction bullish but technical signals bearish")
    print("Consider: Market uncertainty is high")

4. Handle Extreme Volatility

# Calculate recent volatility
recent_volatility = df['close'].pct_change().tail(24).std()

if recent_volatility > 0.05:  # 5% volatility
    print("⚠️ High volatility detected")
    print("Recommendation: Use wider confidence intervals")
    predictions = create_prediction_intervals(
        predictions,
        confidence=0.90  # Wider interval
    )

Common Patterns

Complete Prediction Workflow

def make_prediction(symbol: str, timeframe: str, forecast_hours: int):
    """
    Complete prediction workflow
    
    Args:
        symbol: Crypto pair (e.g., 'BTC/USDT')
        timeframe: Candlestick interval (e.g., '1h')
        forecast_hours: Hours to forecast
    """
    # 1. Load data
    collector = CryptoDataCollector('kraken')
    df = collector.fetch_ohlcv(symbol, timeframe, limit=2000)
    df = TechnicalIndicators.add_all_indicators(df)
    
    # 2. Select model
    if forecast_hours <= 72:
        predictor = XGBoostCryptoPredictor()
        metrics = predictor.train(df, train_size=0.8)
        predictions = predictor.predict_future(df, periods=forecast_hours)
        predictions = create_prediction_intervals(predictions)
    else:
        predictor = HybridCryptoPredictor()
        metrics = predictor.train(df)
        predictions_dict = predictor.predict_future(df, periods=forecast_hours)
        predictions = predictor.get_best_prediction(predictions_dict)
    
    # 3. Analyze results
    current_price = df['close'].iloc[-1]
    predicted_price = predictions['predicted_price'].iloc[-1]
    change_pct = ((predicted_price - current_price) / current_price) * 100
    
    print(f"Current: ${current_price:.2f}")
    print(f"Predicted ({forecast_hours}h): ${predicted_price:.2f}")
    print(f"Change: {change_pct:+.2f}%")
    
    return predictions, metrics

# Usage
predictions, metrics = make_prediction('BTC/USDT', '1h', 48)

Next Steps

Build docs developers (and LLMs) love