File size: 2,003 Bytes
57ed0db 109468c 55b441c db54e1c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | ---
license: mit
datasets:
- helloadhavan/Stock-pile
language:
- en
pipeline_tag: time-series-forecasting
library_name: pytorch
tags:
- lstm
- time-series
- stock-prediction
---
# LSTM Stock Next-Day Predictor
This model was trained on the [Stock-Pile dataset](https://huggingface.co/datasets/helloadhavan/Stock-pile). It is a custom LSTM architecture with a learned ticker embedding, trained on about 5 million rows of daily stock data covering hundreds of companies across US, European and Asian markets. Given the previous 30 trading days, it predicts the next day's Open, High, Low, Close and log-Volume. It is a learning and experimentation project, not financial advice.
## Files
| File | Purpose |
|---|---|
| `loader.py` | `Model`, `Normalizer` and `load_model` |
| `config.json` | Ticker ids, per-ticker normalization statistics and training logs |
| `stock_predictor/model.pth` | Trained weights |
| `MODEL_CARD.md` | Architecture, data, evaluation and limitations |
## Usage
Download the repo by running:
```bash
huggingface-cli download helloadhavan/stock-LSTM
```
```python
import torch
from .stock-LSTM.loader import load_model, Normalizer
model = load_model("stock_predictor/model.pth", "config.json")
normalizer = Normalizer("config.json")
window = {
"Open": open_t,
"High": high_t,
"Low": low_t,
"Close": close_t,
"Volume": torch.log1p(volume_t),
}
x = normalizer(window, "AAPL")
ticker_id = normalizer.ticker_ids["AAPL"]
ids = torch.full((x.shape[0], 1), float(ticker_id))
inputs = torch.cat([x, ids], dim=-1).unsqueeze(0)
with torch.no_grad():
prediction = model(inputs)
result = normalizer.denormalize(prediction[0], "AAPL")
result["Volume"] = torch.expm1(result["Volume"])
```
Each tensor in `window` has shape `(30,)`. `denormalize` returns a dict of prices and log-Volume, so apply `torch.expm1` to get raw volume.
## Notes
- Volume must be `log1p`-transformed before normalizing.
- Only tickers listed in `config.json` are supported. |