Skip to main content

Stock environment for training machine learning agents

Project description

StockTrainer: Stock Environment for Human

StockTrainer: Stocks Made Easy

StockTrainer is high level API data generator for training python machine learning models on stock/cryptocurrency data and is capable of running with Keras, Tensorflow, sklearn, and many other machine learning APIs

Capabilities:

  • Predict day to day stock prices
  • Use multiple days to predict next stock price
  • Predict succeeding stock prices over multiple days
  • Train a reinforcement learning agent to simulate stock trades

Documentation available soon ;)

stocktrainer is compatible with: Python 3.6+

Getting Started

The core of algorithm is the model, here is a simple LSTM model to based on 5 days of stock data to predict the next day

import keras
import numpy as np
from keras.models import Sequential
from keras.layers import Dropout ,BatchNormalization, LSTM, Dense 


model = Sequential()
#input shape 5 days of data 
#each day has 6 data points (open, close, high , low volums, adj CLose)
model.add(BatchNormalization(input_shape=(5, 6)))#batchnorm bc high values
model.add(LSTM(512, return_sequences=True, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(512, activation='relu'))
model.add(Dense(128, activation='relu'))	
model.add(Dense(1, activation='relu'))

model.compile(loss='mse', optimizer='adam')

Next import stocktrainer and create your environment

from stocktrainer import Env
environment = Env("Standard", "AAPL")

Time to collect your data to train!!!

test_percent =.30
shuffle =True
start_date ='2003-01-01'
end_date='now'
agent_memory = 5
seed = 42
trainx,testx,trainy, testy = environment.train_test(
  test_percent= test_percent, shuffle = shuffle, start_date=start_date, 
  end_date=end_date, agent_memory=agent_memory, seed=seed)

Futher information on parameters in Documentation

That's it now train and test your model

#fit model
model.fit(trainx, trainy, epochs=10, batch_size=128, verbose=2)
model.save('model.h5')

#evaluate model
model.evaluate(testx,testy )
#use model to predict
model.predict(testx)

More examples on samples folder in github

Installation

Using pip

pip install stocktrainer

or download directly: https://pypi.org/project/StockTrainer/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stocktrainer-0.1.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file stocktrainer-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: stocktrainer-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.0

File hashes

Hashes for stocktrainer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 764feff1383e37b92788833484b2bef53ac223a6b99dc6478086a9380a94cf04
MD5 42c08d6cc034433cf9a415fcf7052cdf
BLAKE2b-256 14bd53c6b11b619e736488b133e007de540b9f01d81b2d8358846de197ac9ed9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page