Files
OpenBB/gamestonk_terminal/prediction_techniques
2021-03-15 19:56:56 +00:00
..
2021-02-26 21:57:17 -08:00
2021-03-13 22:57:14 +00:00
2021-03-13 22:57:25 +00:00
2021-03-15 19:56:42 +00:00
2021-03-13 23:29:31 +00:00
2021-03-14 00:12:41 +00:00
2021-03-13 22:57:43 +00:00

PREDICTION TECHNIQUES

This menu aims to predict the share price of a pre-loaded stock, and the usage of the following commands along with an example will be exploited below.

  • sma
    • simple moving average
  • ets
    • Exponential Smoothing (e.g. Holt-Winters)
  • knn
    • k-Nearest Neighbors
  • linear
    • linear regression (polynomial 1)
  • quadratic
    • quadratic regression (polynomial 2)
  • cubic
    • cubic regression (polynomial 3)
  • regression
    • regression (other polynomial)
  • arima
    • autoregressive integrated moving average
  • prophet
    • Facebook's prophet prediction
  • mlp
    • MultiLayer Perceptron
  • rnn
    • Recurrent Neural Network
  • lstm

Note: Use this at your own discretion. All of these prediciton techniques rely solely on the closing price of the stock. This means that there are several factors that the models aren't aware of at the time of prediction, and may - drastically - move the price up or down. Examples are: news, analyst price targets, reddit post, tweets from Elon Musk, and so on.

sma

usage: sma [-l N_LENGTH] [-d N_DAYS]

Simple Moving Average:

  • -l : length of SMA window. Default 20.
  • -d : prediciton days. Default 5.
  • -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.

sma

ets

usage: ets [-t TREND] [-s SEASONAL] [-p SEASONAL_PERIODS] [-d N_DAYS]

Exponential Smoothing (based on trend+seasonality, see https://otexts.com/fpp2/taxonomy.html):

  • -t : trend component: N: None, A: Additive, Ad: Additive Damped. Default N.
  • -s : seasonality component: N: None, A: Additive, M: Multiplicative. Default N.
  • -p : seasonal periods. Default 5.
  • -d : prediciton days. Default 5.
  • -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.

ets_pltr

knn

usage: knn [-i N_INPUTS] [-d N_DAYS] [-j N_JUMPS] [-n N_NEIGHBORS]

k-Nearest Neighbors:

  • -i : number of days to use for prediction. Default 40.
  • -d : prediciton days. Default 5.
  • -j : number of jumps in training data. Default 1.
  • -n : number of neighbors to use on the algorithm. Default 20.
  • -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.

knn

linear

usage: linear [-i N_INPUTS] [-d N_DAYS] [-j N_JUMPS]
usage: regression -p 1 [-i N_INPUTS] [-d N_DAYS] [-j N_JUMPS]

Linear Regression (p=1):

  • -i : number of days to use for prediction. Default 40.
  • -d : prediciton days. Default 5.
  • -j : number of jumps in training data. Default 1.
  • -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.

linear

quadratic

usage: quadratic [-i N_INPUTS] [-d N_DAYS] [-j N_JUMPS]
usage: regression -p 2 [-i N_INPUTS] [-d N_DAYS] [-j N_JUMPS]

Quadratic Regression (p=2):

  • -i : number of days to use for prediction. Default 40.
  • -d : prediciton days. Default 5.
  • -j : number of jumps in training data. Default 1.
  • -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.

quadratic

cubic

usage: cubic [-i N_INPUTS] [-d N_DAYS] [-j N_JUMPS]
usage: regression -p 3 [-i N_INPUTS] [-d N_DAYS] [-j N_JUMPS]

Cubic Regression (p=3):

  • -i : number of days to use for prediction. Default 40.
  • -d : prediciton days. Default 5.
  • -j : number of jumps in training data. Default 1.
  • -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.

cubic

regression

usage: regression -p N_POLYNOMIAL [-i N_INPUTS] [-d N_DAYS] [-j N_JUMPS]

Regression:

  • -i : number of days to use for prediction. Default 40.
  • -d : prediciton days. Default 5.
  • -j : number of jumps in training data. Default 1.
  • -p : polynomial associated with regression. Required.
  • -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.

regression

arima

usage: arima [-d N_DAYS] [-i {aic,aicc,bic,hqic,oob}] [-s] [-r] [-o S_ORDER]

Auto-Regressive Integrated Moving Average:

  • -d : prediciton days. Default 5.
  • -i : information criteria - used if auto_arima library is invoked. Default aic.
  • -s : weekly seasonality flag. Default False.
  • -r : results about ARIMA summary flag. Default False.
  • -o : arima model order. If the model order is defined, auto_arima is not invoked, deeming information criteria useless.
    Example: -o 514, where:
    • p = 5 : order (number of time lags) of the autoregressive model.
    • d = 1 : degree of differencing (the number of times the data have had past values subtracted).
    • q = 4 : order of the moving-average model.
  • -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.

arima

prophet

usage: fbprophet [-d N_DAYS]

Facebook's Prophet:

  • -d : prediciton days. Default 5.
  • -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.

prophet

mlp

usage: mlp [-d N_DAYS] [-i N_INPUTS] [-j N_JUMPS] [-e N_EPOCHS] [-p {normalization,standardization,none}]
[-o {adam,adagrad,adadelta,adamax,ftrl,nadam,optimizer,rmsprop,sgd}] [-l {mae,mape,mse,msle}]

MulitLayer Perceptron:

  • -d : prediciton days. Default 5.
  • -i : number of days to use for prediction. Default 40.
  • -j : number of jumps in training data. Default 1.
  • --epochs : number of training epochs. Default 200.
  • -p : pre-processing data. Default normalization.
  • -o : optimization technique. Default adam.
  • -l : loss function. Default mae.
  • -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.

Due to the complexity of defining a model through command line, one can define it in: config_neural_network_models.txt

MultiLayer_Perceptron \
    = [ {'Dense':
                {'units':50, 'activation':'relu'} },
        {'Dense':
                {'units':100, 'activation':'relu'} },
        {'Dense':
                {'units':80, 'activation':'relu'} },
        {'Dense':
                {'units':30, 'activation':'relu'} },
        {'Dense':
                {'activation':'linear'} }]

mlp

rnn

usage: rnn [-d N_DAYS] [-i N_INPUTS] [-j N_JUMPS] [-e N_EPOCHS] [-p {normalization,standardization,none}]
[-o {adam,adagrad,adadelta,adamax,ftrl,nadam,optimizer,rmsprop,sgd}] [-l {mae,mape,mse,msle}]

Recurrent Neural Network:

  • -d : prediciton days. Default 5.
  • -i : number of days to use for prediction. Default 40.
  • -j : number of jumps in training data. Default 1.
  • --epochs : number of training epochs. Default 200.
  • -p : pre-processing data. Default normalization.
  • -o : optimization technique. Default adam.
  • -l : loss function. Default mae.
  • -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.

Due to the complexity of defining a model through command line, one can define it in: config_neural_network_models.txt

Recurrent_Neural_Network \
    = [ {'SimpleRNN':
                {'units':100, 'activation':'linear', 'return_sequences':True} },
        {'SimpleRNN':
                {'units':50, 'activation':'linear', 'return_sequences':True} },
        {'Dropout':
                {'rate':0.2} },
        {'SimpleRNN':
                {'units':21, 'activation':'linear', 'return_sequences':False} },
        {'Dense':
                {'activation':'linear'} }]

rnn

lstm

usage: lstm [-d N_DAYS] [-i N_INPUTS] [-j N_JUMPS] [-e N_EPOCHS] [-p {normalization,standardization,none}]
[-o {adam,adagrad,adadelta,adamax,ftrl,nadam,optimizer,rmsprop,sgd}] [-l {mae,mape,mse,msle}]

Long-Short Term Memory:

  • -d : prediciton days. Default 5.
  • -i : number of days to use for prediction. Default 40.
  • -j : number of jumps in training data. Default 1.
  • --epochs : number of training epochs. Default 200.
  • -p : pre-processing data. Default normalization.
  • -o : optimization technique. Default adam.
  • -l : loss function. Default mae.
  • -e : end date (format YYYY-MM-DD) of the stock - Backtesting. Default None.

Due to the complexity of defining a model through command line, one can define it in: config_neural_network_models.txt

Long_Short_Term_Memory \
    = [ {'LSTM':
                {'units':25, 'activation':'tanh', 'return_sequences':True} },
        {'LSTM':
                {'units':15, 'activation':'tanh', 'return_sequences':False} },
        {'Dense':
                {'activation':'linear'} }]

lstm

Backtesting Example

appl_pred

apple_error

Captura de ecrã 2021-03-14, às 00 06 51