{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# AI Trading: BitNet-Transformer Training\n", "This notebook trains a 25M parameter ternary-quantized Transformer on 10 years of market data.\n", "\n", "## 1. Setup Environment" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Clone the repository\n", "!git clone https://github.com/luohoa97/ai-trading.git\n", "%cd ai-trading\n", "\n", "# Install dependencies\n", "!pip install torch safetensors huggingface_hub pandas numpy yfinance scikit-learn" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2. Configuration\n", "Set your Hugging Face credentials to upload the model after training." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "from google.colab import userdata\n", "\n", "# Best practice: Use Colab Secrets (the key icon on the left)\n", "try:\n", " os.environ[\"HF_TOKEN\"] = userdata.get('HF_TOKEN')\n", " os.environ[\"HF_REPO_ID\"] = \"luohoa97/BitFin\"\n", " print(\"✅ HF credentials loaded from Colab Secrets\")\n", "except:\n", " print(\"⚠️ HF_TOKEN not found in Secrets. Please set it manually or train without upload.\")\n", " os.environ[\"HF_TOKEN\"] = \"\"\n", " os.environ[\"HF_REPO_ID\"] = \"luohoa97/BitFin\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3. Data Generation & Training\n", "This will:\n", "1. Fetch 10 years of history for 70 symbols (if not found).\n", "2. Train the 8-layer Transformer using CUDA (GPU).\n", "3. Save performance metrics and the model." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Add root to path so we can import internal scripts\n", "import sys\n", "sys.path.append(os.getcwd())\n", "\n", "from scripts.train_ai_model import train\n", "\n", "# Trigger the training loop\n", "# Note: It will automatically run build_dataset() if data/trading_dataset.pt is missing\n", "train()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 4. Results\n", "Check the generated report and verify model stats." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "if os.path.exists(\"performance_report.txt\"):\n", " with open(\"performance_report.txt\", \"r\") as f:\n", " print(f.read())\n", "else:\n", " print(\"Training failed to produce a report.\")" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 4 }