This project provides a simple FastAPI server that performs stock price prediction using a Transformer-based model. It is designed to run within a Jupyter Notebook environment and allows external API access through ngrok.
- Loads a 4-bit quantized stock prediction model (
finma-7b) - Runs a REST API server using FastAPI
- Generates an external access URL via ngrok
The following libraries should be installed within the notebook:
pip install fastapi uvicorn nest-asyncio pyngrok
pip install transformers accelerate torch pandas yfinance finance-datareader
pip install bitsandbytes peft shap matplotlib- Open the
API_server.ipynbfile and run each cell sequentially. - Load the model → Start the server → Display the ngrok URL
- Use the displayed ngrok URL to make API calls from outside the notebook.
GET /predict?ticker=005930.KS&horizon_days=7ticker: Stock symbol (e.g., AAPL, 005930.KS)horizon_days: Prediction period (choose from 1, 7, or 30 days)
- Requires at least 6GB of GPU RAM. Not compatible with EC2 free tier; assumed to run on Google Colab.
- For production deployment, consider converting to a standalone Python script or Docker container.
- Registration of Hugging Face and ngrok tokens is necessary.