Skip to content

resotto/laplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

laplace

Laplace predicts BTCUSD ticker values.

Getting Started

Please install TensorFlow and scikit-learn(sklearn) in advance.

git clone git@github.com:resotto/laplace.git
cd laplace/btcusd
python3
>>> import laplace as la
>>> input = la.make_input_data()

>>> type(input)
<class 'numpy.ndarray'>

>>> input.shape
(41, 4)

>>> predicted = la.predict(input)
>>> predicted                         # following values are examples
array([ 9191.143,  9191.745,  9191.728, 19837.059], dtype=float32)

>>> rising = la.predict_rising_from(input)
>>> rising                            # following values are examples
array([False, False, False, False])

>>> falling = la.predict_falling_from(input)
>>> falling                           # following values are examples
array([ True,  True,  True,  True])

Features

  • Predicting BTCUSD ticker values
  • Predicting rising of BTCUSD ticker values with boolean
  • Predicting falling of BTCUSD ticker values with boolean

Loss & Accuracy

  • Final loss value:
Loss Value
MSE 9.807e-4
  • Final average of the last 10 accuracy(%):
bid ask last_price volume
85 85 80 50

Details

  • Predicted values are 10 minutes after the last input data (adjustable).

  • Input data is the past 41 minutes ticker values (adjustable).

  • Input dimension and output dimension are 4 (adjustable).

  • Accuracy is calculated per 10 epochs (adjustable).

  • Forward hidden layer is tf.keras.layers.LSTMCell.

  • Backward hidden layer is tf.keras.layers.LSTMCell.

  • Entire hidden layer is tf.nn.static_bidirectional_rnn.

  • Optimizer is Adam.

  • Loss is calculated by MSE.

  • Model's parameters are saved to .model.

  • TensorBoard's logs are saved to .tensorboard/logs.

Build

First, let's create input data.
You can change the URL of public ticker API in create_csv.py.

L5: URL    = 'https://api.bitfinex.com/v1/pubticker/btcusd' # Please change this url as you like

If you changed URL, you also need to fix those parts in create_csv.py:

L7: HEADER = 'time,bid,ask,last_price,volume' # Csv header. After changing above url, you may need to fix this
L44: write(time, body)                        # After changing above url, you also need to fix this depending on ticker response

Now, you start fetching.
After running create_csv.py, input.csv will be created to current directory.

python3 create_csv.py

Second, please convert time units of the data in input.csv from seconds to minutes.
After runnning convert.py, input_min.csv will be created to current directory.
input_min.csv is input data for learning.

python3 convert.py

Third, before learning, you can adjust parameters in laplace.py.

MAXLEN           = 41                                     # Time series length of input data
INTERVAL         = 10                                     # Time interval between the last input value and answer value
N_IN             = 4                                      # Input dimension
N_HIDDEN         = 13                                     # Number of hidden layers
N_OUT            = 4                                      # Output dimension
LEARNING_RATE    = 0.0015                                 # Optimizer's learning rate
PATIENCE         = 10                                     # Max step of EarlyStopping
INPUT_VALUE_TYPE = ['bid', 'ask', 'last_price', 'volume'] # Input value type
EPOCHS           = 2500                                   # Epochs
BATCH_SIZE       = 50                                     # Batch size
TESTING_INTERVAL = 10                                     # Test interval

RANDOM_LEARNING_ENABLED = True                            # Index of data determined randomly or not
EARLY_STOPPING_ENABLED  = False                           # Early Stopping enabled or not

Finally, please start learning.

python3 laplace.py

After learning model, you also can check TensorBoard.

tensorboard --logdir .tensorboard/logs/

When predicting, please follow Getting Started.

Feedback

License

GNU General Public License v3.0.