Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

MAT 292 Project: Bitcoin Spread Analysis: Delay Differential Equation Framework

Authors: Nicholas Nguyen [1010900474], Jay Patel [1010960872], Nelson Siu [1010940608]


Table of Contents


Overview

MAT292 Project analyzing Bitcoin price spreads between Bitfinex and Gemini exchanges using a Delay Differential Equation (DDE) framework.

Project Structure

MAT292-Project/
│
├── data/                                    # Data files
│   ├── Bitfinex Week - minute ticker - Sheet1.csv   # Raw Bitfinex data (minute resolution)
│   ├── Gemini Week - minute ticker - Sheet1.csv     # Raw Gemini data (minute resolution)
│   ├── interpolated_second_data.csv         # Interpolated second-resolution data
│   ├── synchronized_spread_data.csv         # Synchronized spread time series
│   └── calibration_results.csv              # Parameter estimates from calibration
│
├── figures/                                 # Generated plots
│   ├── mid_prices.png                       # Price series from both exchanges
│   ├── spread.png                           # Spread time series
│   └── fig_k_and_tau.png                    # k estimates vs lag with critical delays
│
├── Python Scripts                           # Analysis pipeline
│   ├── process_spread.py                    # [1] Synchronize data and compute spread
│   ├── interpolate.py                       # [2] Interpolate minute data to seconds
│   ├── calibrate_k_tau.py                   # [3] Estimate k, τ, and compute τ_c
│   ├── plot_price_series.py                 # Visualize exchange price series
│   ├── plot_spread.py                       # Visualize spread dynamics
│   └── plot_k_tau.py                        # Plot k and critical delay estimates
│
├── LaTeX Files                              # Report generation
│   ├── matproject.tex                       # Main LaTeX document
│   └── *.aux, *.fdb_latexmk, *.fls          # LaTeX auxiliary files
│
├── requirements.txt                         # Python dependencies
├── context.md                               # Project context and rubric
└── README.md                                # This file

Data Description

Source Data:

  • Bitcoin (BTC-USD) price data from Bitfinex and Gemini exchanges
  • Time period: March 9–17, 2022 (one week)
  • Original resolution: 1 minute (OHLC data)
  • Processed resolution: 1 second (via linear interpolation)

Installation

Prerequisites

  • Python 3.7 or higher
  • pip package manager

Setup

  1. Clone or download this repository

  2. Create a virtual environment (recommended):

    python -m venv .venv
  3. Activate the virtual environment:

    • Windows (PowerShell):
      .venv\Scripts\Activate.ps1
    • Windows (Command Prompt):
      .venv\Scripts\activate.bat
    • macOS/Linux:
      source .venv/bin/activate
  4. Install dependencies:

    pip install -r requirements.txt

Usage

Complete Analysis Pipeline

Run the scripts in the following order to reproduce all results:

Step 1: Process and Synchronize Spread Data

python process_spread.py
  • Loads raw Bitfinex and Gemini data
  • Computes mid-prices
  • Synchronizes timestamps
  • Calculates spread (mA - mB)
  • Output: data/synchronized_spread_data.csv

Step 2: Interpolate to Second Resolution

python interpolate.py
  • Performs linear interpolation from minute to second resolution
  • Generates high-frequency approximation
  • Output: data/interpolated_second_data.csv

Step 3: Calibrate DDE Parameters

python calibrate_k_tau.py
  • Estimates empirical delay (τ_emp) via cross-correlation
  • Estimates mean-reversion rate (k̂) using multiple methods
  • Computes critical delay (τ_c = π/(2k̂))
  • Performs sensitivity analysis across different lag assumptions
  • Output: data/calibration_results.csv, console summary

Step 4: Generate Visualizations

python plot_price_series.py   # Price series from both exchanges
python plot_spread.py          # Spread dynamics over time
python plot_k_tau.py           # Parameter estimates vs lag
  • Outputs: Figures saved to figures/ directory

Visualization Scripts (Individual)

# Plot mid-prices from both exchanges
python plot_price_series.py

# Plot the spread time series
python plot_spread.py

# Plot k estimates and critical delays
python plot_k_tau.py

Output Files

Data Files:

  • data/synchronized_spread_data.csv - Aligned mid-prices and spread from both exchanges
  • data/interpolated_second_data.csv - Second-resolution interpolated data
  • data/calibration_results.csv - Estimated parameters (k, τ_emp, τ_c)

Figures:

  • figures/mid_prices.png - Bitfinex and Gemini price series
  • figures/spread.png - Spread time series visualization
  • figures/fig_k_and_tau.png - Parameter sensitivity analysis

Dependencies

All dependencies are listed in requirements.txt:

requests
pandas
matplotlib
numpy
scipy

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages