/ Модель

Характеристики

Лицензия
MIT
Библиотека
keras

stock-lstm-forecast

Прогноз временных рядовTime_series → time_series3 профессии

Небольшая LSTM-модель прогнозирует дневную цену закрытия AAPL по последним 60 логарифмическим доходностям.

47скачиваний за 30 дней0лайковвеса обновлены25 сен 2026

Бенчмарки

Как модель справилась с задачами пользователей ailist и что о ней публикуют открытые лидерборды

Публичные оценки

Из открытых лидербордов. Сравнивайте результаты одного теста при одинаковых условиях — отсутствие оценки не значит, что модель хуже.

В подключённых источниках результатов для этой модели пока нет.

Что умеет модель

Описание составлено по карточке модели и метаданным Hugging Face

Небольшая модель LSTM, опубликованная shalev396 как учебный проект для прогноза дневной цены закрытия акций Apple (AAPL). Архитектура состоит из LSTM-слоя с 64 блоками, Dropout и полносвязного выходного слоя; всего 16 961 параметр. Модель принимает последние 60 дневных логарифмических доходностей и предсказывает следующую доходность. Для прогноза на несколько дней результат каждого шага рекурсивно подаётся на вход следующего. Реализация сохранена в формате Keras 3 и использует TensorFlow.

Репозиторий включает историю цен AAPL с 2015-01-02 по 2026-07-31, поэтому для расчёта не нужен API рыночных данных. Модель предназначена для демонстрации и изучения прогнозирования временных рядов, а не для принятия торговых решений. На отложенном тестовом периоде её ошибка прогноза на следующий день практически совпала с простым прогнозом «завтра как сегодня» и немного хуже него. Лицензия — MIT.

Сценарии применения

  • экспериментальный прогноз цены закрытия AAPL на следующий торговый день
  • построение рекурсивного прогноза AAPL на срок до 60 торговых дней
  • изучение применения LSTM к финансовым временным рядам
  • сравнение нейросетевого прогноза цены акций с наивным прогнозом сохранения последней цены

Ограничения

На тестовом периоде модель не превзошла наивный прогноз «завтра как сегодня»; автор прямо не рекомендует использовать её для торговли. Она обучена только на AAPL и исторических данных до 2026-07-31, не учитывает новости и режимы волатильности и не выдаёт интервалы неопределённости.

Для каких профессий подходит3

Разделы каталога профессий, в задачах которых используется эта модель

Все профессии

Карточка модели

README от автора на Hugging Face, как он его опубликовал

Открыть на Hugging Face

Stock Price LSTM

Forecasts Apple's (AAPL) daily closing price after a chosen cutoff date. A small LSTM reads the last 60 daily log-returns and predicts the next one. Each prediction is fed back in to forecast up to 60 business days. The repo ships a frozen copy of the price history (prices.csv), so forecasts need no market-data API.

The honest result: on the held-out test period (2024-11-04 to 2026-07-31), the model's next-day RMSE is $4.48. The naive forecast "tomorrow = today" scores $4.47, so the model does not beat it. Daily prices are close to a random walk, and this model has learned little more than the average daily drift (numbers from the run of 2026-09-25, metrics.json).

Model

  • Architecture (model.build_lstm): Input(60, 1) -> LSTM(64) -> Dropout(0.2) -> Dense(1), 16,961 parameters, float32. It is saved as model.keras (Keras 3).
  • Input: the last 60 daily log-returns r_t = ln(C_t / C_(t-1)) up to the cutoff, standardized with the training split's mean (0.000827) and standard deviation (0.018858). Both are stored in config.json.
  • Output: the next standardized log-return. Prices are rebuilt as C_cutoff × exp(cumulative returns). For a horizon of h days, the model runs h times, and each prediction becomes the newest input.
  • prices.csv: 2,911 daily closes from 2015-01-02 to 2026-07-31 (yfinance Close, split-adjusted, not dividend-adjusted). Valid cutoffs run from 2015-03-31 (the first day with a full 60-return window) to 2026-07-31. Other dates are clamped to that range and snapped to the previous trading day.

predict(cutoff, horizon) returns the portfolio's timeseries format:

{"model": "LSTM(64) on log-returns",
 "history": [{"date": "2025-01-06", "price": 245.0}, ..., {"date": "2025-06-30", "price": 205.17}],
 "forecast": [...], "actual": [...], "naive": [...],
 "mae": 5.7788, "naiveMae": 7.8303}
  • history: up to 120 trading days, ending at the effective cutoff.
  • forecast / naive: one point per forecast day. naive repeats the cutoff close.
  • actual: the real closes after the cutoff that exist in prices.csv. It is empty for the last date.
  • mae / naiveMae: mean absolute error in $ over the days that have an actual price, or null.

Usage

from huggingface_hub import snapshot_download
import sys
path = snapshot_download("shalev396/stock-lstm-forecast")
sys.path.insert(0, path)
import model
predictor = model.load(path, device="cpu")
result = predictor.predict("2025-06-30", 30)   # cutoff "YYYY-MM-DD", horizon in business days (1-60)
print(result["forecast"][-1], result["mae"], result["naiveMae"])
  • Space API: POST /gradio_api/call/predict with {"data": ["2025-06-30", 30]}. See the Space.
  • Inference Endpoint: handler.py accepts {"inputs": {"cutoff": "2025-06-30", "horizon": 30}}, or {"inputs": "2025-06-30", "parameters": {"horizon": 30}}.

Training

  • Data: AAPL daily OHLCV from yfinance, downloaded on 2026-08-01 (2015-01-02 to 2026-07-31). The first 14 days are dropped as RSI warm-up, which leaves 2,897 days.
  • Split: chronological 70 / 15 / 15. Each 60-day window belongs to the split of the day it predicts, so no window crosses a boundary. Train has 1,966 windows (2015-04-22 to 2023-02-09), validation 435 (2023-02-10 to 2024-11-01) and test 435 (2024-11-04 to 2026-07-31). Every scaler is fit on the train rows only.
  • Recipe: Adam 1e-3, MSE on the scaled target, batch 32, up to 40 epochs. Early stopping (patience 6) and learning-rate halving watch validation loss, and the best epoch's weights are restored.
  • Selection: among the univariate models the Space can run recursively, the one with the lowest validation RMSE is deployed. Test metrics are computed once.
  • Hardware / time: CPU. Training all four networks took 575.3 s in this run, but the CPU was shared with several other training jobs. An earlier uncontended run of the same recipe took 71.8 s (the legacy results.json).
  • Full code: training/ · Colab

Experiments

Next-day (one-step) predictions on the original $ scale, for the same 435 test days across all variants. Rows are ranked by validation RMSE, and the deployed model is in bold:

variantparamsval RMSE ($)test RMSE ($)test MAE ($)test MAPE (%)
naive_persistence-2.5834.4693.0201.233
lstm_returns (deployed)16,9612.5884.4833.0261.237
simple_rnn_levels4,2894.56212.87510.8034.159
lstm_levels16,9615.89614.48210.9044.173
stacked_lstm_multi51,0096.54421.97518.1076.854
  • Price levels break under a train-fit scaler. Train closes range from $22.58 to $182.01, and test closes from $172.42 to $340.08. Models that predict MinMax-scaled levels must extrapolate beyond the range they were trained on, so they lag badly: their test RMSE is $12.88 to $21.98. Adding volume, RSI and EMA features (the stacked multivariate LSTM) makes this worse.
  • Log-returns fix the scaling problem, but the model has no signal to find. The returns target is roughly stationary, so the LSTM stays in its training range and matches naive persistence: test RMSE $4.483 vs $4.469, MAPE 1.237 % vs 1.233 %. Its validation loss was lowest after the first epoch, which means it mostly predicts the average daily return.
  • Multi-day forecasts (what the Space shows): the recursive forecast was run from 84 test cutoffs (every 5th test day, 2024-11-01 to 2026-07-02) for 20 business days each. Its mean MAE is $10.67, against $10.87 for repeating the cutoff close. The small edge comes from the positive drift built into the forecast during a period when AAPL mostly rose. It is not evidence of predictive skill.
  • Changes from the earlier version of this project: the model is now chosen on validation instead of test RMSE, and everything runs in float32 (the old GPU path enabled mixed precision without float32 heads). The Space now serves a frozen copy of the data instead of calling yfinance, and it compares every forecast with the naive baseline. With the same data and seed, the retrained test metrics match the earlier run.

Model comparison Test forecast Multi-step MAE Training curves

Evaluation

Deployed model (lstm_returns), next-day predictions on the test split (2024-11-04 to 2026-07-31):

metric (test)value
rmse4.4831
mae3.0255
mape1.2368

Naive persistence on the same days: RMSE 4.469, MAE 3.020, MAPE 1.233 %.

Limitations

  • It does not beat naive persistence on next-day prices. Do not use it for trading. Not financial advice.
  • One stock, one period. It was trained on AAPL from 2015 to 2023 only. The return statistics (mean and std) are Apple's, and the model was not validated on any other ticker.
  • Frozen data. Forecasts exist only for cutoffs up to 2026-07-31. Refreshing needs a retrain and a new prices.csv.
  • Recursive forecasts converge to the drift. After a few steps the forecast is close to a smooth exponential trend at about 0.08 % a day. It has no notion of earnings, news or volatility regimes.
  • Close only. Prices are split-adjusted but not dividend-adjusted, and there are no uncertainty bands.
  • Educational portfolio project.

Как запустить

На своей GPU в ailist. Цена — по текущим предложениям провайдеров

GPU в ailist

Универсальный рантайм · keras

Нельзя запустить

Keras/TensorFlow-модели рантайм не загружает.

Ревизия весов
94a174c

0 моделей