stocksml.model

BuildModel(fdf, choices, layers=[('rnn', 32), ('dnn', 64), ('dnn', 32)], depth=5, count=2)[source]

Build a model with the given structure

Parameters
  • fdf (pandas.DataFrame) – feature dataframe

  • choices (int) – number of ticker symbols model can choose between

  • layers (list of tuples) – list of tuples defining structure of model. Each tuple is (layer, size) where layer can be ‘dnn’, ‘cnn’, ‘lstm’, ‘rnn’, or ‘drop’. Default is a 3-layer model with [(‘rnn’,32),(‘dnn’,64),(‘dnn’,32)]

  • depth (int) – depth of time dimension for recurrent and convolutional networks (rnn, cnn, lstm). Ignored if using dnn only. Default is 5.

  • count (int) – number of models to build. Default is 2

Returns

list of keras Models built, compiled and ready for training along with the appropriate data array for training

Return type

list of keras.Model, numpy.ndarray

LearnStrategy(models, sdf, dx, symbols, baseline=None, days=5, maxiter=1000, notebook=False)[source]

Learn a trading strategy by training models against provided data

Parameters
  • models (list of keras.Model) – list of prebuilt models to train

  • sdf (pandas.DataFrame) – symbol dataframe with price information

  • dx (numpy.array) – vectorized training data

  • symbols (list of str) – list of ticker symbols available to the trading strategy. Must all be contained in sdf

  • baseline (str) – ticker symbol to use for baselining of trading strategy. Default None performs no baseline

  • days (int) – number of days to use for trading strategy. Default is 5

  • maxiter (int) – maximum number of training iterations. Default is 1000

  • notebook (bool) – configures live plots for running in a Jupyter notebook. Default is False

ExamineStrategy(model, sdf, dx, symbols, start_date, days=5, baseline=None)[source]

Explore a strategy learned by a model

Parameters
  • model (keras.Model) – trained model to execute strategy with

  • sdf (pandas.DataFrame) – symbol dataframe with price information

  • dx (numpy.array) – vectorized training data

  • symbols (list of str) – list of ticker symbols available to the trading strategy. Must all be contained in sdf

  • start_date (str) – date to start trading strategy on. yyyy-mm-dd format

  • days (int) – number of days to run strategy for. Default is 5

  • baseline (str) – ticker symbol to use for baselining of trading strategy. Default None performs no baseline

Demo(notebook=False)[source]

Demonstration of how to use this package

Parameters

notebook (bool) – set live plots for running properly in Jupyter notebooks. Default is False