Increasing Pattern Complexity: Machine Learning for Algorithmic Trading in Forex and Stocks

sentdex · Beginner ·📐 ML Fundamentals ·12y ago
Skills: ML Pipelines80%

Key Takeaways

Increases pattern complexity by lengthening pattern recognition for machine learning in algorithmic trading of forex and stocks

Full Transcript

you hello and welcome to the 10th machine learning for use of Forex and stock algo trading automated trading or just plain analysis or just learning to do machine learning where we left off we were plotting up our similar patterns on a matplotlib so we can see them visually and we said that we actually wanted to do we extend our pattern lengths that we're going to look for and when we do this the other thing too is as soon we're going to be looking for a bunch of patterns not just on the end patterns but eventually we do need to back test this so the first thing that we need to do first is we're going to change a couple things here in our percent change of formula it's possible to arrive at a zero percent change then to calculate the percent change from zero to a point will be problematic for us if if that occurs and as we expand this and not only expand the length of our pattern but also we're going to run through all of the patterns the chances of us hitting something like that is actually pretty likely so what I want to do is first listen in case everything here may try indent and accept so Sept and we're not going to throw an exception here because of what we're going to do so we're going to say instead of a term we're going to say x equals the following then what we're going to say is if x equals zero point zero as in if X is a zero because now normally we don't really care if the percentage change was zero right that matters actually but what we do care is when we do a percentage change of a percentage change that yielded a zero that's going to be very hurtful to us so we never want to throw with zero percent change we need something so we're just going to say return zero point zero zero zero zero zero one okay so basically zero but we can actually work with this number so that's what we'll do else will return X otherwise we're going to get a negative infinity insert and we don't want that and then um accept and if anything else goes wrong we'll also return a zero points or something like that percent change so let us solve a few of our issues obviously this is a perfect math but that is the best way to handle a negative infinity when the percentage change of a percentage change of zero comes into question now the next thing we need to do is we want to allow a everything we want to do instead of ten points we want to do 30 points so continuing on I guess I had that in my mind well let's see x equals average line minus 30 you really need this to be minus 30 now plus another 30 so really mine is 60 so we can always look into the future now Y since we're going to expand not from 10 to 30 Y needs to be 31 pattern stays the same come down here we need to change this so copy and paste and paste again now the first thing we need to do is we need to change so this goes to 10 1 to 10 1 to 10 so this will be actually fairly easy to do our edit so 11 12 13 14 15 system and this is 20 so just change these same thing down here this is B 21 22 23 24 25 person or something now I am 30 now let's not be dopey and forget to do this stuff like we did last time so instead of y equals minus 10 we should have made this edit first sorry guys anyway 30 now right and now we'll just paste this in here through this this is the joyous joyous stuff faster this way probably 330 very very 30 okay now we need to go through and fix ladies this one will be easy again so it's 29 28 27 26 on equality for 51 and this will be Y minus 20 then this will be 19 18 17 is e Levin and then this will be minus 10 and then 9 8 7 6 5 4 3 2 1 0 basically hmm done that you just let's just glance at this make sure we did everything you need to do 13 it looks good okay so we've done that now the next thing we need to do is pend all of our patterns again the above here and this and the next few things that we do should have been done in a wow loop for the length of whatever pattern length we chosen and we'll maybe get to that in the future videos but again I really wanted to first start off by writing everything out just so everyone can easily follow but again I recognize this is not the most efficient way or pythonic way to do it so anyway uh now we want to do so we need to append all the other patterns so we'll do that so this is a same kind of edit styles before so 11 changes to 20 and then here 21 and 30 and just check your quick edit that we made make sure we make the errors looks good looks good to me and that should finish out this formula or this function rather now we come down here oh man we got another one to do yeah so a similar editing style that we need to do again just mention this is not the most efficient way to do it but it makes it easiest to understand so again we'll edit this similar editing style 20 and 21 - what have I done there we go 30 and come back up this now all of these eight we did the same thing that we do before remember on this one I was like well we should a copy and paste it with the 30 what a big dummy anyway this needs to be 31 so we'll just do this all the way through sorry I should've thought about that if I didn't do then fallen for the same stuff twice in a row it's a definition of insanity continuing on all right now you need to fix this one now this means instead of being negative ten sees this one needs to be 30 29 28 27 is -21 then this needs to be warning and then this will be 2,900 oh wait wait wait getting ahead of myself here let's fix this 20 19 18 17 11 and then 10 9 8 7 6 probably good quick glance over to look for any problems so these are all 30 ones good these here 30:21 jism 10 9 8 7 6 5 okay it looks good now we need to fix this one as well so copy here paste paste listen ezbee 11 19 20 and 21 to 28 29 and third a quick glance over make sure we did that all right yep now we come down to pattern recognition you guessed it now we need to do the same thing here this one should be a little easier and let's make sure I think everything the only thing we change here is the numbers in the pattern here and this one will actually be a little bit easier to edit since its 0 to 9 foot anyway paste paste sound 11 12 13 14 15 system since 18 19 and a 20 subsequently 21 20 2011 sister country 9 and a 30 and then we come into the array itself and we need to edit both of these let's not forget like we did last time 10 11 12 13 14 15 16 17 18 19 come down here 20 come on do the eight and twenty nine 10 11 both of people to get assistance every 15 19 and down here same thing 21 / 0-9 nice quick glance over make sure our edits went well tell em totally good and this one looks good too okay now I believe we are to the last thing we have to do and that is all these little additions let's go ahead and just automatically put that 30 there before we forget and subsequently we do this throw a little plus sign here enter paste plus sign enter paste now we will do I think there was a better way to do this but I don't think there is so 12 13 14 15 16 17 18 19 20 here 21 22 23 24 25 26 and 30 so that's going to add them all up do that averaging equation that we did before now hmm with this since we've made the pattern much longer how sim of 70 across one one pattern is basically probably not going to happen very unlikely that to hit that let's just drop this 240 just for ease of actually finding a pattern before we start building the back test so 40 this is all good now the only thing okay we need edit this this needs to go all the way to 30 now so you eleven twelve thirteen sixteen seventeen eighteen nineteen twenty one twenty two twenty three point six twenty seven eight nine and thirty okay and actually you know what sort of typing that out and pretty sure you just do x equals one colon thirty anyway that was pretty dumb I might actually need to be one : 31 anyway that was pretty stupid that's okay though continuing on also through here I believe that's everything so let's go ahead and save this and run and see what the heck we get so we run it here we go first we got a store everything I guess has even done that part yet I don't know alright cool so we got a pattern now and now it's in the degree of 30 points as we can see there's that pattern let's see if we get any other patterns looking through everything and we got another pattern here's another pattern that matches and you can actually probably see the you know one two three four five six seven eight nine ten so you can see that our old pattern is you know right here as well just in case you don't notice and that's it so even though it says entire processing time took 40 seconds didn't really because we were looking at charts so just keep that in mind since we graphed up those charts a took that long but it wouldn't normally take 40 seconds so let's going to conclude this video in the next video we're going to begin building up our actual back testing or running through old data so this one we were you know only comparing that most recent plot as being as if the last plot in our data set however if we want to back test data we can do that as well starting at the first plot and then running through each plot as if we were comparing or running through future data so as we continue getting more plots we're comparing to only the previous plots not the future plots so that's what we're going to do in the next videos is actually run through the data set as if it was reality and start building saving up each pattern that each new pattern it finds and seeing how long it takes to do this and you'll see that initially it's very quick and as we continue getting more and more data and more and more patterns stored the memory that's when we start actually being taxed on our arm or Ram starts to get taxed as that array grows but anyway that's what we're gonna start doing the next video is actually back beginning to build the back tester and really it's like all it back testings we're testing against old data but it's actually better than a back tester it's really like back testing the forward test or something I don't know anyway that's what we're going to be doing in the next video as always thanks for watching thanks for the support of the subscriptions and until next time

Original Description

In this tutorial, we increase the pattern complexity, ie: increase the pattern length for pattern recognition. Welcome to the Machine Learning for Forex and Stock analysis and algorithmic trading tutorial series. In this series, you will be taught how to apply machine learning and pattern recognition principles to the field of stocks and forex. This is especially useful for people interested in quantitative analysis and algo or high frequency trading. Even if you are not, the series will still be of great use to anyone interested in learning about machine learning and automatic pattern recognition, through a hands-on tutorial series. Sentdex.com Facebook.com/sentdex Twitter.com/sentdex
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from sentdex · sentdex · 0 of 60

← Previous Next →
1 Matplotlib Python Tutorial Part 1: Basics and your first Graph!
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
2 Python Encryption Tutorial with PyCrypto
Python Encryption Tutorial with PyCrypto
sentdex
3 Python's Logging Function
Python's Logging Function
sentdex
4 wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
5 wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
6 wxPython Programming Tutorial 3: Menu Bar and Menu Button
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
7 wxPython Programming Tutorial 4: Panels
wxPython Programming Tutorial 4: Panels
sentdex
8 wxPython Programming Tutorial 5: User Input Saved To Variables
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
9 wxPython Programming Tutorial 6: Multiple Choice Input
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
10 wxPython Programming Tutorial 7: Adding Static Text and Colors
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
11 wxPython Programming Tutorial 8: Custom Button Images
wxPython Programming Tutorial 8: Custom Button Images
sentdex
12 wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
13 Basic PHP Tutorial 13: Multi-dimensional Array
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
14 Basic PHP Tutorial 15: Functions and Global Variables
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
15 Basic PHP Tutorial 12: Associative Array
Basic PHP Tutorial 12: Associative Array
sentdex
16 Basic PHP Tutorial 14: Foreach loop
Basic PHP Tutorial 14: Foreach loop
sentdex
17 Basic PHP Tutorial 16: Include and Require
Basic PHP Tutorial 16: Include and Require
sentdex
18 Basic PHP Tutorial 7: Assignment, comparison and Logical operators
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
19 Basic PHP Tutorial 4: Variables and Comments
Basic PHP Tutorial 4: Variables and Comments
sentdex
20 Basic PHP Tutorial 11: Arrays part 1, basic array
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
21 Basic PHP Tutorial 6: If else and else if conditionals cont'd
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
22 Basic PHP Tutorial 1: Intro to PHP
Basic PHP Tutorial 1: Intro to PHP
sentdex
23 Basic PHP Tutorial 3: HTML with PHP
Basic PHP Tutorial 3: HTML with PHP
sentdex
24 Basic PHP Tutorial 9: While Loop
Basic PHP Tutorial 9: While Loop
sentdex
25 Basic PHP Tutorial 10: Switch Statement
Basic PHP Tutorial 10: Switch Statement
sentdex
26 Basic PHP Tutorial 2: Print and Echo
Basic PHP Tutorial 2: Print and Echo
sentdex
27 Basic PHP Tutorial 5: If else and else if conditional statements
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
28 Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
29 Basic PHP Tutorial 17: User Input Form Example / String Manipulation
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
30 Basic PHP Tutorial 18: HTML Entities and forms cont'd
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
31 Basic PHP Tutorial 19: Finding words in strings
Basic PHP Tutorial 19: Finding words in strings
sentdex
32 Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
33 Basic PHP Programming Tutorial 22: Hashing part 2: salting
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
34 Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
35 Basic PHP Programming Tutorial 21: MD5 Hashing For Security
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
36 Basic PHP Programming Tutorial 24: String similarity
Basic PHP Programming Tutorial 24: String similarity
sentdex
37 Basic PHP Programming Tutorial 25: Time and Time stamps
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
38 Basic PHP Programming Tutorial 26: Die and Exit
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
39 Basic PHP Programming Tutorial 27: MySQL Databases Part 1
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
40 Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
41 Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
42 Basic PHP Programming Tutorial 30: MySQL database in Use
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
43 Django Tutorial Web Development with Python Part 1: Installing Django
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
44 Python Tutorial: File Deletion and Folder Deletion / directory deletion
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
45 Python Tutorial: How to Rename Files and Move Files with Python
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
46 3D Graphs in Matplotlib for Python: Basic 3D Line
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
47 3D Plotting in Matplotlib for Python: 3D Scatter Plot
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
48 3D Charts in Matplotlib for Python: Multiple datasets scatter plot
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
49 Sikuli Tutorial 1: Visually programming in python!
Sikuli Tutorial 1: Visually programming in python!
sentdex
50 Sikuli Tutorial 2: Program visually in python!
Sikuli Tutorial 2: Program visually in python!
sentdex
51 Sikuli Tutorial 3: Program visually in python!
Sikuli Tutorial 3: Program visually in python!
sentdex
52 3D Bar Charts in Python and Matplotlib
3D Bar Charts in Python and Matplotlib
sentdex
53 3D Plane wire frame Graph Chart in Python
3D Plane wire frame Graph Chart in Python
sentdex
54 Raspberry Pi Part 1 Introduction
Raspberry Pi Part 1 Introduction
sentdex
55 Raspberry Pi Part 8: First Download and Update! (Firmware)
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
56 Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
57 Raspberry Pi Part 11: Remote Desktop
Raspberry Pi Part 11: Remote Desktop
sentdex
58 Twitter Analysis: How to rank a user's influence
Twitter Analysis: How to rank a user's influence
sentdex
59 GPIO Tutorial for Pi Part 2 - Programming the GPIO
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
60 GPIO Tutorial for Raspberry Pi Part 1 - Setting up
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex

Related AI Lessons

Mastering TypeScript — Understanding the TypeScript Compiler (tsc) from Scratch — Lesson 2
Learn the basics of the TypeScript compiler to write better JavaScript code
Medium · JavaScript
Stop Overfitting With Basically One Line of Code
Learn to prevent overfitting with a simple code tweak and understand the difference between Ridge and Lasso regression
Medium · AI
Stop Overfitting With Basically One Line of Code
Learn to prevent overfitting in machine learning models with a simple code tweak and understand the difference between Ridge and Lasso regression
Medium · Machine Learning
Stop Overfitting With Basically One Line of Code
Prevent overfitting in models with a simple code tweak, understanding the difference between Ridge and Lasso regression
Medium · Data Science
Up next
Learn Deep Learning by Hand (Beginner's Guide - Part 1)
Thu Vu
Watch →