Bitcoin Trading Bot (Tutorial)
Skills:
ML for Analytics80%
Key Takeaways
Creates a simple Bitcoin trading bot using an LSTM neural network in Keras to predict Bitcoin's future price
Full Transcript
hi I'd like to buy this phone we only accept dogecoin what hello world its Suraj and let's build a simple Bitcoin trading bot using machine learning crypto currencies are generally considered high-risk investments so many traditional finance and economic gurus from the famous investor Warren Buffett to the Nobel prize-winning economist Joseph Stiglitz have said that bitcoin is a scam with no substantial worth and that it will soon experience a crash as bad as the 17th century tulipmania that overtook the Netherlands if we look at the chart of bitcoins price over the years we can see that there have been several mini crashes throughout its history by definition a bubble is a price largely above the real value of an asset and it bursts when people realize that so the question then becomes what is the fair value of Bitcoin we know that Bitcoin doesn't require the bank credit mechanism for money creation it uses mathematical algorithms to mint its tokens it can also be used where normal money would be impractical like in micro transfers between machines aka the Internet of Things or trading in multiplayer games it's unsensible and it allows for anonymous transactions bitcoins current supplies around 17 million bitcoins while the current cash in circulation in the u.s. is 1.5 trillion dollars meaning we could currently replace 50 percent of all US cash with Bitcoin clearly it has real value unlike ripple but that doesn't mean it's price will continually rise forever who knows what its real value is it could be fifteen thousand or fifteen dollars per coin it's fair to say though that at this point Bitcoin must have developed price curve inefficiencies that can be exploited in a trading system we could try momentum investing not momentum from gradient descent Wizards this is an investment strategy that aims to capitalize on the continuous continuance of existing trends in the market the idea is that once a trend is established it's more likely to continue in that direction than to move against that trend the problem however is that crypto is far too volatile so conventional model based strategies won't work well we need a fast trading trend agnostic strategy that means it holds positions for only a few minutes and is not exposed to the bubble risk we need to exploit short-term price patterns using an algorithm of our choice but before we pick an algorithm let's find ourselves a nice Bitcoin data set luckily for us kaggle has a fun data set of minute by minute historical prices of Bitcoin it includes seven factors that we can use including prices and volume and before we feed this data into our model we need to normalize it that means adjusting the values of all of these features that are measured on different scales to one common scale this will later boost our models performance since the feature values will relate to each other more so it will be easier to find the relationship patterns that exist between them one easy way to do this is to take a sliding window of a size we decide and slide it across the data to make sure that there are no 0 or n Hagan values there normally this would be a pain since we've got multiple dimensions here but thanks to the Python pandas library we can represent each window as a panda's data frame then perform the normalization operation across the whole data frame meaning all of its columns for the sake of cleanliness let's give functions their own self-contained class as a data loader that way we can reuse it later to extract transform and load our datasets now that we've done this we simply need a model that accepts data of shape M where m is a number of dimensions in our data so what can we choose here if we look through the academic literature on the topic of predicting market trends that hasn't been burned by the Big Ben we'll see that all sorts of models have been used for time series forecasting which is what this problem is considered random forests support vector machines neural networks and seeing as how neural networks tend to propel perform most other machine learning models most of the time when given lots of data and compute aka deep learning we might as well try that model keep in mind that a neural network is a composite function every layer in the network is a function and the network as a whole then becomes a function of functions for as many layers as there are the output of the previous layer is what feeds into the next layer as input until a final output is computed if we train a feed-forward neural network on this data it will be the case that at every time step it will use a new data point as its input but we are under the hypothesis that each data point is closely related to the data point that came before it that there is some relationship between successive prices in the graph so we need a way for our network to be able to understand this these data points are not created in isolation they are a part of a larger sequence so we can make a change to our model instead of feeding it every new data point at every time step so that the hidden layer is continuously updated we'll feed it in the current data point as well as the previous learned hidden state keep in mind that the hidden state is just a matrix through the learning process it's going to be modified so that when dot product operations are continuously applied to it to produce an output during inference the resulting output will be much more accurate this recurrence allows the network to not just learn from the data but to learn from what its previously learned allowing for sequence learning but recurrent networks have a big problem they can't remember really long sequences so Bollywood movies are out of the question this is called the bay gradiant problem during the optimization process the gradient is recursively computed and applied to every layer of the network from the last one all the way back to the first and as this gradient is computed layer by layer it gets smaller and smaller and because the gradient update gets smaller the network isn't able to store the memory of the changes it's learning over a long period of time that memory slowly diminishes so we need to use a special and popular subset of recurrent Nets called long short term memory networks the idea is simple rather than each of the nodes of the network just having a single activation function each node is a memory cell in that it can store other information so it maintains its own cell state while our n NS are fed their previous hidden states and the current input and every time step on an LST M does the same except it also takes in its old cell state and outputs its new cell state what's happening inside of this memory cell is really cool it's digital biology there are three steps here the cell needs to forget the irrelevant parts of the previous state it needs to selectively update itself based on the new input it's just seen and it needs to decide what parts of the cell state to output as a new hidden state this is all achieved by using a forget gate an input gate and an output gate a gate is a way to optionally let data through each is composed of a single sigmoid neural net layer and a multiplication operation that's it so firstly a function of the previous hidden state and the new input passes through the forget gate which lets us know what is irrelevant and can be removed from our cell state it will output values close to one for parts of the cell state we want to keep and zero for the ones we want to get rid of for example if the price starts spiking super high for days because of some major event the price before that could be irrelevant we can forget that next a function of the inputs passes through the input gate and is added to the cell state to update it there could be something new we've noticed and we want to add it to the cell state that's why this is there and lastly the output gate decides what values from the cell state are going to be added to the hidden state output so this will learn the parts of the sequence in the distant past that are worth remembering and those that are not this ability to preserve information in the cell state for long stretches of time is what makes lsdm networks so special they solve the problem of managing gradients since the forget gate is essentially the weights and activation function for the cell state and because the lsdm can learn to set that forget gate to one for important things in the cell state data can pass through unchanged notice that our Bitcoin dataset is super big since it's minute by minute we can't just load 1 million data windows all at once into chaos a train that would require a god-like amount of RAM that only Jeff Bezos has a better solution would be to use the chaos generator function to iterate over data of unknown length passing on the next piece every time it's called we can train our model on one small chunk of data at a time and thanks to chaos building an L STM model requires just a few lines of code under 15 to be precise when we start training our model it will take a few hours but afterwards we can try forecasting the Bitcoin price we can do this either on a point by point basis meaning we add one to the T variable then shift the window of true data predicting the next point along or we do the same but multiple steps ahead we can see that one step ahead is doing a reasonable job but the predictions seem kind of volatile without doing more tests it's hard to decide why this is the case and whether better parameters might fix this could add in sentiment data from Twitter to see how the crowd affects the price here News sentiment is another option and we could merge the data then nor why's it so it's all numerical using pandas a cutting-edge technique right now is to use Bayesian methods alongside LS TM networks to compensate for the fact that the factors that influence price variations themselves change over time details on all of that in the video description before you crash the stock market hit the subscribe button and I'll keep making you better faster and smarter for now I've got to investing some furniture so thanks for watching [Music]
Original Description
Cryptocurrency can be a high-risk, high-reward game for those willing to deal with the volatility. Can we use AI to help us make predictions about Bitcoin's future price? In this video, i'll show you how to build a simple Bitcoin trading bot using an LSTM neural network in Keras. Along the way I'll explain why we use LSTM networks through code and animations, as well as a review of the vanishing gradient problem.
Code for this video:
https://github.com/llSourcell/Bitcoin_Trading_Bot
Please Subscribe! And like. And comment. That's what keeps me going.
Want more education? Connect with me here:
Twitter: https://twitter.com/sirajraval
Facebook: https://www.facebook.com/sirajology
instagram: https://www.instagram.com/sirajraval
This video is apart of my Machine Learning Journey course:
https://github.com/llSourcell/Machine_Learning_Journey
More Learning Resources:
https://medium.com/swlh/developing-bitcoin-algorithmic-trading-strategies-bfdde5d5f6e0
https://bitcoin.stackexchange.com/questions/48093/how-to-build-a-bitcoin-trading-bot
https://blog.patricktriest.com/analyzing-cryptocurrencies-python/
https://github.com/lefnire/tforce_btc_trader
Join us in the Wizards Slack channel:
http://wizards.herokuapp.com/
Sign up for the next course at The School of AI:
https://www.theschool.ai
And please support me on Patreon:
https://www.patreon.com/user?u=3191693
Signup for my newsletter for exciting updates in the field of AI:
https://goo.gl/FZzJ5w
Hit the Join button above to sign up to become a member of my channel for access to exclusive content! Join my AI community: http://chatgptschool.io/ Sign up for my AI Sports betting Bot, WagerGPT! (500 spots available): https://www.wagergpt.xyz
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Siraj Raval · Siraj Raval · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
What is Bitcoin?
Siraj Raval
5 Ways to Use Bitcoin
Siraj Raval
BTC Fever - Siraj [Music Video]
Siraj Raval
5 Reasons to Build Decentralized Apps
Siraj Raval
The Interplanetary File System
Siraj Raval
How to Build a Dapp in 3 min
Siraj Raval
Life Before Smartphones
Siraj Raval
4 Ways to Use Smart Contracts
Siraj Raval
3 Dapps You HAVE to See
Siraj Raval
Char's Life as a BitTorrent Engineer
Siraj Raval
4 Reasons AlphaGo is a Huge Deal
Siraj Raval
Build a Neural Net in 4 Minutes
Siraj Raval
Sentiment Analysis in 4 Minutes
Siraj Raval
The Hackathon Life
Siraj Raval
Your First ML App - Machine Learning for Hackers #1
Siraj Raval
Build an AI Composer - Machine Learning for Hackers #2
Siraj Raval
Build a Game AI - Machine Learning for Hackers #3
Siraj Raval
Build a Movie Recommender - Machine Learning for Hackers #4
Siraj Raval
Build an AI Artist - Machine Learning for Hackers #5
Siraj Raval
Build a Chatbot - ML for Hackers #6
Siraj Raval
Build an AI Reader - Machine Learning for Hackers #7
Siraj Raval
Build an AI Writer - Machine Learning for Hackers #8
Siraj Raval
Build a Chatbot w/ an API - ML for Hackers #9
Siraj Raval
One-Shot Learning - Fresh Machine Learning #1
Siraj Raval
Generative Adversarial Nets - Fresh Machine Learning #2
Siraj Raval
Tone Analysis - Fresh Machine Learning #3
Siraj Raval
Generate Rap Lyrics - Fresh Machine Learning #4
Siraj Raval
Build an Autoencoder in 5 Min - Fresh Machine Learning #5
Siraj Raval
Build a Self Driving Car in 5 Min - Fresh Machine Learning #6
Siraj Raval
Build an Antivirus in 5 Min - Fresh Machine Learning #7
Siraj Raval
TensorFlow in 5 Minutes (tutorial)
Siraj Raval
Build a Recurrent Neural Net in 5 Min
Siraj Raval
Build a Simulation in 5 Min
Siraj Raval
Build a TensorFlow Image Classifier in 5 Min
Siraj Raval
Tensorboard Explained in 5 Min
Siraj Raval
Generate Music in TensorFlow
Siraj Raval
Build a Game Bot (LIVE)
Siraj Raval
Deep Learning Frameworks Compared
Siraj Raval
Introduction - Learn Python for Data Science #1
Siraj Raval
Build a Neural Network (LIVE)
Siraj Raval
Twitter Sentiment Analysis - Learn Python for Data Science #2
Siraj Raval
Recommendation Systems - Learn Python for Data Science #3
Siraj Raval
Predicting Stock Prices - Learn Python for Data Science #4
Siraj Raval
Pong Neural Network (LIVE)
Siraj Raval
Deep Dream in TensorFlow - Learn Python for Data Science #5
Siraj Raval
Visualizing Data with D3.js (LIVE)
Siraj Raval
Genetic Algorithms - Learn Python for Data Science #6
Siraj Raval
Enter Siraj [Music Video]
Siraj Raval
Build a Web Scraper (LIVE)
Siraj Raval
Why is P vs NP Important?
Siraj Raval
How to Make a Neural Network (LIVE)
Siraj Raval
How to Make an Amazing Tensorflow Chatbot Easily
Siraj Raval
How to Make an Amazing Video Game Bot Easily
Siraj Raval
How to Make a Tensorflow Neural Network (LIVE)
Siraj Raval
How to Make a Simple Tensorflow Speech Recognizer
Siraj Raval
Joel Shor - Really Quick Questions with an Awesome Google Engineer
Siraj Raval
How to Make a Path Planning Algorithm Easily (LIVE)
Siraj Raval
The Best Way to Prepare a Dataset Easily
Siraj Raval
Catherine Olsson - Really Quick Questions with an OpenAI Engineer
Siraj Raval
How to Make a Tic Tac Toe Neural Network Easily (LIVE)
Siraj Raval
More on: ML for Analytics
View skill →Related AI Lessons
⚡
⚡
⚡
⚡
Want to get started with deep learning
Reddit r/deeplearning
Building a Deepfake Detector From Scratch — What Nobody Tells You
Medium · Deep Learning
Unfolding the Meandering Path: High-Dimensional Invariance and the Flat 2D Plane of Neural…
Medium · Deep Learning
Implementing Neural Style Transfer from Scratch: The Project That Started It All
Medium · Deep Learning
🎓
Tutor Explanation
DeepCamp AI