A production-ready Bitcoin price forecasting system built with Kedro for ML pipeline orchestration, Prophet for time series forecasting, FastAPI for serving predictions, and MLflow for experiment tracking and model versioning.
- Automated Data Ingestion: Fetches historical Bitcoin data from Binance API
- Prophet Forecasting: Uses Facebook Prophet for time series predictions with seasonality modeling
- Kedro Pipelines: Well-organized, reproducible ML pipelines with data lineage
- MLflow Integration: Comprehensive experiment tracking, model versioning, and MLOps best practices
- REST API: FastAPI-based API with automatic documentation and validation
- Configurable Predictions: Forecasts up to 365 days ahead with confidence intervals
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Binance API │─ ──▶│ Kedro Pipeline │───▶│ Prophet Model │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│ │
▼ ▼
┌─────────────────┐ ┌─────────────────┐
│ MLflow Server │────▶│ Model Registry │
└─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Client/App │◀────│ FastAPI │◀────│ Predictions │
└─────────────────┘ └─────────────────┘ └─────────────────┘
# Clone the repository
git clone <your-repo-url>
cd crypto-ts-forecast
# Create virtual environment
python -m venv .venv
# Activate virtual environment
# Windows:
.venv\Scripts\activate
# Linux/Mac:
source .venv/bin/activate
# Install dependencies
pip install -e .You can also build and run the application using Docker (with uv for fast builds):
# Build the image
docker build -t crypto-ts-forecast .
# Run the container
docker run --rm -p 8000:8000 --name crypto-api crypto-ts-forecastThe API will be available at http://localhost:8000/docs
Execute the complete ML pipeline to train the model with historical Bitcoin data:
kedro runPipeline stages:
- Data ingestion from Binance API (2 years of daily OHLCV data)
- Data processing and transformation for Prophet format
- Model training with seasonality components
- Forecast generation for configurable time horizon
Start the FastAPI server:
# Direct module execution
python -m crypto_ts_forecast.api.main
# Entry point command
crypto-forecast-apiThe API will be available at http://localhost:8000
Open your browser and go to:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
GET /healthGET /api/v1/price/current?symbol=BTCUSDTGET /api/v1/forecast?days_ahead=30POST /api/v1/forecast
Content-Type: application/json
{
"days_ahead": 30,
"retrain": false
}POST /api/v1/pipelines/run
Content-Type: application/json
{
"pipeline_name": "__default__"
}GET /api/v1/model/infoimport requests
# Get forecast
response = requests.get("http://localhost:8000/api/v1/forecast?days_ahead=7")
forecast = response.json()
for prediction in forecast["predictions"]:
print(f"{prediction['date']}: ${prediction['predicted_price']:,.2f}")# Get 7-day forecast
curl "http://localhost:8000/api/v1/forecast?days_ahead=7"
# Retrain model and get forecast
curl -X POST "http://localhost:8000/api/v1/forecast" \
-H "Content-Type: application/json" \
-d '{"days_ahead": 30, "retrain": true}'| Pipeline | Description |
|---|---|
data_ingestion |
Fetches Bitcoin data from Binance API |
data_processing |
Transforms data to Prophet format |
model_training |
Trains and evaluates Prophet model |
inference |
Generates future predictions |
__default__ |
Runs all pipelines in sequence |
kedro run --pipeline data_ingestion
kedro run --pipeline model_trainingkedro vizConfigurable via conf/base/parameters.yml:
binance:
symbol: "BTCUSDT"
interval: "1d"
years_of_data: 2
prophet:
price_column: "close"
seasonality_mode: "multiplicative"
yearly_seasonality: true
weekly_seasonality: true
changepoint_prior_scale: 0.5
seasonality_prior_scale: 10.0
changepoint_range: 0.9
test_size_days: 30
forecast:
days_ahead: 30
mlops:
model:
name: "crypto_ts_forecast_prophet"
description: "Prophet time series model for Bitcoin price forecasting"
versioning:
register_model: true
default_stage: "Staging"
deployment_thresholds:
min_r2: 0.7
max_mape: 15.0Data catalog configured in conf/base/catalog.yml. Datasets are stored as Parquet files with gzip compression. Trained models are tracked in MLflow and persisted in the Model Registry with versioning support.
This project implements MLOps best practices using kedro-mlflow:
- ✅ Automatic parameter logging for all pipeline runs
- ✅ Metrics tracking (MAE, MAPE, RMSE, R²)
- ✅ Artifact management (models, reports, plots)
- ✅ Run comparison and visualization
- ✅ Model Registry integration
- ✅ Stage-based lifecycle (None → Staging → Production)
- ✅ Version tagging and metadata
- ✅ Model lineage and reproducibility
- ✅ Deployment thresholds for quality gates
- ✅ Automated model validation
- ✅ Performance monitoring setup
- ✅ Model metadata and documentation
# Initialize MLflow
python scripts/init_mlflow.py
# View experiments
kedro mlflow ui
# Run pipeline with tracking
kedro run --pipeline=model_training
# Compare runs in notebook
jupyter notebook notebooks/06_mlflow_demo.ipynb📚 Complete guide: docs/MLFLOW_GUIDE.md
crypto-ts-forecast/
├── conf/ # Configuration files
│ ├── base/
│ │ ├── catalog.yml # Data catalog
│ │ └── parameters.yml # Parameters
│ └── local/
│ └── credentials.yml # Credentials (gitignored)
├── data/ # Data storage
│ ├── 01_raw/ # Raw data from Binance
│ ├── 02_intermediate/ # Validated data
│ ├── 03_primary/ # Prophet base dataset
│ ├── 04_feature/ # Feature-enhanced dataset
│ ├── 05_model_input/ # Train/test splits
│ ├── 06_models/ # Trained Prophet model
│ ├── 07_model_output/ # Predictions
│ └── 08_reporting/ # Reports and metrics
├── src/crypto_ts_forecast/
│ ├── api/ # FastAPI application
│ │ ├── app.py # App factory and routes
│ │ ├── schemas.py # Pydantic models
│ │ ├── services.py # Business logic
│ │ └── main.py # Entry point
│ └── pipelines/
│ ├── data_ingestion/ # Binance data fetching
│ ├── data_processing/ # Data transformation
│ ├── model_training/ # Prophet training
│ └── inference/ # Forecast generation
└── tests/ # Unit tests
# Run all tests
uv run pytest
# Verbose output (lists each test with PASSED/FAILED)
uv run pytest tests/ -v
# Run a specific pipeline's tests
uv run pytest tests/pipelines/inference -v
# Show print() output (disable capture)
uv run pytest -vsruff check .ruff format .- Python 3.10+
- Kedro 1.1.1
- Prophet 1.2.1
- FastAPI 0.104+
- See
requirements.txtfor full list
This project is licensed under the MIT License - see the LICENSE file for details.
This is not financial advice. The predictions generated by this system are for educational and informational purposes only. Cryptocurrency markets are highly volatile and past performance does not guarantee future results. Users should conduct their own research before making investment decisions.