brianrisk/Stock-Prediction-Neural-Network-and-Machine-Learning-Examples
Tentang
Examples of python neural net and ML stock prediction methods with sample stock data.
Pembelajaran mesinPertumbuhan bintang terukur
- dalam 24 jam
- 0
- dalam 7 hari
- 0
- dalam 15 hari
- Mengumpulkan riwayat
- dalam 1 bulan
- Mengumpulkan riwayat
Perubahan bersih pada periode yang tumpang tindih, bukan total harian. Pengukuran yang belum tersedia dibiarkan kosong. Bintang menunjukkan perhatian, bukan kualitas.
README.md
AsliStock Prediction with Neural Networks and Machine Learning (Python)
Contents
Simple Examples
This repository contains small, runnable machine learning (ML) and neural network (NN) examples for stock classification. Each example focuses on the essential parts of a technique: loading data, training a model, evaluating it, and ranking the latest observations by predicted score.
Educational use only: These examples are demonstrations, not investment advice or evidence of a profitable strategy. Classification scores do not account for slippage, liquidity, taxes, market impact, or regime changes.
Machine learning examples
- Genetic algorithm
- Gradient boosting
- K-means clustering
- Logistic regression
- Random forest
- Support vector machine (SVM)
Neural network architectures
- Feed-forward neural network (FFNN)
- Long short-term memory network (LSTM)
- Recurrent neural network (RNN)
The neural network examples use Keras, PyTorch, PyTorch Lightning, and
TensorFlow. Browse the implementations in
simple_examples.
Getting Started
Python 3.10, 3.11, or 3.12 is required.
- Clone this repository and change to its directory.
- Create and activate a virtual environment:
python -m venv .venv
source .venv/bin/activate
- Install libraries:
pip install -r requirements.txt
- Download the starter data and place the
extracted
example_datadirectory at the repository root:
example_data/
├── latest.csv
├── test.csv
└── train.csv
- Run an example from the repository root:
python -m simple_examples.machine_learning.logistic_regression
python -m simple_examples.neural_networks.pytorch_ffnn
Hyperparameter Optimization
The neural network tuner supports configurable grid and random searches and uses multiple processes to evaluate configurations.
- Edit
hyperparameter_tuning/config.py. - From the repository root, run:
python -m hyperparameter_tuning.hyper_main
The tuner uses the chronological tail of train.csv for model selection and
does not inspect test.csv. Configure VALIDATION_FRACTION and EMBARGO_ROWS
in config.py. Results are written to the results directory.
See the hyperparameter tuning guide for the search strategies and available settings.
About the Example Stock Data
The examples use the D.AT example dataset.
The dataset contains five years of price data for S&P 500 companies, divided into 30-trading-day windows. Values within each window are divided by the most recent value in that window. A row is labeled positive when the stock gains at least 5% during the following 10 trading days.
train.csvcontains the first four years of labeled data.test.csvcontains the final year of labeled data.latest.csvcontains one unlabeled row per stock for generating current rankings. Its first column contains the ticker symbol.
CSV schema and ordering
train.csvandtest.csvhave no header. Every column except the last is a numeric feature; the last column is the binary label (0or1).latest.csvhas a header. Its first column is the ticker and its remaining columns must match the training features in number and order.- Labeled rows must be sorted chronologically. If nearby windows share
observations, set
EMBARGO_ROWSso training and validation cannot overlap. Retain ticker/date metadata upstream so leakage can be audited. - Reserve
test.csvfor evaluation after model and threshold selection. Repeatedly choosing models from test results leaks information.
The examples print precision, recall, F1, balanced accuracy, coverage, and a
Fisher exact-test p-value. For a trading study, provide realized returns to
evaluation.backtest_top_scores and choose realistic transaction costs.
Getting new data
The example dataset is static and does not contain current prices. You can download recent customizable data from D.AT with additional strategy and feature-engineering options.
Jelajahi proyek terkait
Memuat…