{"id":15320412,"url":"https://github.com/resotto/laplace","last_synced_at":"2025-07-02T07:35:35.724Z","repository":{"id":202305882,"uuid":"187457830","full_name":"resotto/laplace","owner":"resotto","description":"LSTM Model to predict BTCUSD ticker values","archived":false,"fork":false,"pushed_at":"2020-11-03T00:39:40.000Z","size":4441,"stargazers_count":10,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-15T02:38:25.828Z","etag":null,"topics":["bidirectional-lstm","deep-learning","keras","lstm","numpy","python","python3","recurrent-neural-networks","scikit-learn","sklearn","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/resotto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":"resotto"}},"created_at":"2019-05-19T09:35:04.000Z","updated_at":"2024-05-15T20:58:36.000Z","dependencies_parsed_at":null,"dependency_job_id":"ffb0586c-8c10-4deb-a6e2-7de4a3426c09","html_url":"https://github.com/resotto/laplace","commit_stats":null,"previous_names":["resotto/laplace"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/resotto/laplace","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/resotto%2Flaplace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/resotto%2Flaplace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/resotto%2Flaplace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/resotto%2Flaplace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/resotto","download_url":"https://codeload.github.com/resotto/laplace/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/resotto%2Flaplace/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263094403,"owners_count":23412965,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bidirectional-lstm","deep-learning","keras","lstm","numpy","python","python3","recurrent-neural-networks","scikit-learn","sklearn","tensorflow"],"created_at":"2024-10-01T09:08:25.652Z","updated_at":"2025-07-02T07:35:35.680Z","avatar_url":"https://github.com/resotto.png","language":"Python","funding_links":["https://github.com/sponsors/resotto"],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003elaplace\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://twitter.com/home?status=Rate%20Prediction%20with%20TensorFlow%20Bidirectional%20RNN%20by%20%40_resotto_%20https://github.com/resotto/laplace\"\u003e\u003cimg src=\"https://img.shields.io/badge/twitter-tweet-blue.svg\"/\u003e\u003c/a\u003e\n  \u003ca href=\"https://twitter.com/_resotto_\"\u003e\u003cimg src=\"https://img.shields.io/badge/feedback-@_resotto_-blue.svg\" /\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/resotto/laplace/blob/master/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-GPL%20v3.0-brightgreen.svg\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  Laplace predicts BTCUSD ticker values.\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://raw.github.com/wiki/resotto/laplace/img/demon.png\"\u003e\n\u003c/p\u003e\n\n## Getting Started\nPlease install [TensorFlow](https://www.tensorflow.org/) and [scikit-learn(sklearn)](https://scikit-learn.org/stable/) in advance.\n```bash\ngit clone git@github.com:resotto/laplace.git\ncd laplace/btcusd\npython3\n```\n```python\n\u003e\u003e\u003e import laplace as la\n\u003e\u003e\u003e input = la.make_input_data()\n\n\u003e\u003e\u003e type(input)\n\u003cclass 'numpy.ndarray'\u003e\n\n\u003e\u003e\u003e input.shape\n(41, 4)\n\n\u003e\u003e\u003e predicted = la.predict(input)\n\u003e\u003e\u003e predicted                         # following values are examples\narray([ 9191.143,  9191.745,  9191.728, 19837.059], dtype=float32)\n\n\u003e\u003e\u003e rising = la.predict_rising_from(input)\n\u003e\u003e\u003e rising                            # following values are examples\narray([False, False, False, False])\n\n\u003e\u003e\u003e falling = la.predict_falling_from(input)\n\u003e\u003e\u003e falling                           # following values are examples\narray([ True,  True,  True,  True])\n```\n\n## Features\n- Predicting BTCUSD ticker values\n- Predicting rising of BTCUSD ticker values with boolean\n- Predicting falling of BTCUSD ticker values with boolean\n\n## Loss \u0026 Accuracy\n- Final loss value:\n\n| Loss |  Value  |\n|:-----|:--------|\n| MSE  |9.807e-4|\n\n- Final average of the last 10 accuracy(%):\n\n| bid |  ask  | last_price | volume |\n|:---:|:-----:|:----------:|:------:|\n| 85  |  85   | 80         | 50     |\n\n\n## Details\n- Predicted values are 10 minutes after the last input data (adjustable).\n- Input data is the past 41 minutes ticker values (adjustable).\n- Input dimension and output dimension are 4 (adjustable).\n- Accuracy is calculated per 10 epochs (adjustable).\n\n\n- Forward hidden layer is `tf.keras.layers.LSTMCell`.\n- Backward hidden layer is `tf.keras.layers.LSTMCell`.\n- Entire hidden layer is `tf.nn.static_bidirectional_rnn`.\n- Optimizer is `Adam`.\n- Loss is calculated by `MSE`.\n\n\n- Model's parameters are saved to `.model`.\n- TensorBoard's logs are saved to `.tensorboard/logs`.\n\n## Build\nFirst, let's create input data.  \nYou can change the URL of public ticker API in `create_csv.py`.\n```python\nL5: URL    = 'https://api.bitfinex.com/v1/pubticker/btcusd' # Please change this url as you like\n```\n\nIf you changed URL, you also need to fix those parts in `create_csv.py`:\n```python\nL7: HEADER = 'time,bid,ask,last_price,volume' # Csv header. After changing above url, you may need to fix this\nL44: write(time, body)                        # After changing above url, you also need to fix this depending on ticker response\n```\n\nNow, you start fetching.  \nAfter running `create_csv.py`, `input.csv` will be created to current directory.\n```bash\npython3 create_csv.py\n```\n\nSecond, please convert time units of the data in `input.csv` from seconds to minutes.  \nAfter runnning `convert.py`, `input_min.csv` will be created to current directory.  \n`input_min.csv` is input data for learning.\n```bash\npython3 convert.py\n```\n\nThird, before learning, you can adjust parameters in `laplace.py`.\n```python\nMAXLEN           = 41                                     # Time series length of input data\nINTERVAL         = 10                                     # Time interval between the last input value and answer value\nN_IN             = 4                                      # Input dimension\nN_HIDDEN         = 13                                     # Number of hidden layers\nN_OUT            = 4                                      # Output dimension\nLEARNING_RATE    = 0.0015                                 # Optimizer's learning rate\nPATIENCE         = 10                                     # Max step of EarlyStopping\nINPUT_VALUE_TYPE = ['bid', 'ask', 'last_price', 'volume'] # Input value type\nEPOCHS           = 2500                                   # Epochs\nBATCH_SIZE       = 50                                     # Batch size\nTESTING_INTERVAL = 10                                     # Test interval\n\nRANDOM_LEARNING_ENABLED = True                            # Index of data determined randomly or not\nEARLY_STOPPING_ENABLED  = False                           # Early Stopping enabled or not\n```\n\nFinally, please start learning.\n```bash\npython3 laplace.py\n```\n\nAfter learning model, you also can check TensorBoard.\n```bash\ntensorboard --logdir .tensorboard/logs/\n```\nWhen predicting, please follow [Getting Started](#getting-started).\n\n## Feedback\n- Report a bug to [Bug report](https://github.com/resotto/laplace/issues/1).\n- [Tweet me](https://twitter.com/_resotto_) with any other feedback.\n\n## License\n[GNU General Public License v3.0](https://github.com/resotto/laplace/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fresotto%2Flaplace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fresotto%2Flaplace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fresotto%2Flaplace/lists"}