This video has us beginning to build our comparison ability, which will be used in pattern recognition. This part could be done in a logarithmic fashion, but we’re going to try to keep things as simple as possible!

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

+1 for mentioning logs

avgLine will be an int/float ; how did you use a len(avgLine) over it as

its not a string? I am getting an error

isn’t reduce(lambda x, y: x+y, outcomeRange) functionally equivalent to

sum(outcomeRange) ?

Hi. I dont understand why that code is working avgLine = ((bid+ask)/2) in

your tutorial. How you divided the list on 2 . Or perhaps ask and bid

isn’t lists.

Sentdex, can you please post the code.

Traceback (most recent call last):“, line 1, in

File “

patternFinder()

File “C:/Python27/GraphWork.py”, line 19, in patternFinder

avgLine = ((bif+ask)/2)

NameError: global name ‘bif’ is not defined

any help lol?

can u provide me the whole code!!

would it be correct to say that the pattern finder is calculating the

percent change between the first value: n and all subsequent values up to

n+9.

This window of 10 values is being moved through the whole data set.

hi,it’s me again, why this video don’t have captions .

can you upload the video again with adding captions .

Please…

Isn’t changing the 100 to 100.00 in the percentChange function useless? I

can’t think of a possible situation where multiplying a number by 100 in

python will cast it to an integer

EDIT: Actually I forgot you’re using Python 2, so maybe that can happen

since division is a bit different there.

I can’t help but feel there must have been a better way to write that while

loop!

python 3.5 codes

import time

import datetime

import matplotlib

import matplotlib.pyplot as plt

import matplotlib.ticker as mticker

import matplotlib.dates as mdates

import numpy as np

date,bid,ask = np.loadtxt(‘GBPUSD1d.txt’,

unpack=True,

delimiter=’,’,

converters={0:mdates.bytespdate2num(‘%Y%m%d%H%M%S’)})

# numpy passes a byte string to the converter instead of a string. In

python 2, since bytes and str are equivalent it does not matter. For python

3, however, this results in an error as strpdate2num passes it to the

standard library’s strptime which only expects a string.

def percentChange(startPoint,currentPoint):

return ((currentPoint-startPoint)/startPoint)*100.00

def patternFinder():

”’

The goal of patternFinder is to begin collection of %change patterns

in the tick data. From there, we also collect the short-term outcome

of this pattern. Later on, the length of the pattern, how far out we

look to compare to, and the length of the compared range be changed,

and even THAT can be machine learned to find the best of all 3 by

comparing success rates.

”’

#Simple Average

avgLine = ((bid+ask)/2)

#This finds the length of the total array for us

x = len(avgLine)-30

#This will be our starting point, allowing us to compare to the

#past 10 % changes.

y = 11

# where we are in a trade. #

# can be none, buy,

currentStance = ‘none’

while y < x:p1 = percentChange(avgLine[y-10], avgLine[y-9]) p2 = percentChange(avgLine[y-10], avgLine[y-8]) p3 = percentChange(avgLine[y-10], avgLine[y-7]) p4 = percentChange(avgLine[y-10], avgLine[y-6]) p5 = percentChange(avgLine[y-10], avgLine[y-5]) p6 = percentChange(avgLine[y-10], avgLine[y-4]) p7 = percentChange(avgLine[y-10], avgLine[y-3]) p8 = percentChange(avgLine[y-10], avgLine[y-2]) p9 = percentChange(avgLine[y-10], avgLine[y-1]) p10= percentChange(avgLine[y-10], avgLine[y])outcomeRange = avgLine[y+20:y+30] currentPoint = avgLine[y]#function to account for the average of the items in the array reduce= lambda x, y: x + y, outcomeRange/ len(outcomeRange) print (reduce)print (currentPoint) print ('--------------------------') print (p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) time.sleep(55)y+=1def graphRawFx(): fig = plt.figure(figsize=(10,7)) ax1= plt.subplot2grid((40,40), (0,0), rowspan=40, colspan=40) ax1.plot(date,bid) ax1.plot(date,ask) #plt.gca().get_yaxis().get_major_formatter().setuseoffset(False)ax1.xaxis.set_major_formatter(mdates.DateFormatter('%y-%m-%d %H:%M:%S')) for label in ax1.xaxis.get_ticklabels(): label.set_rotation(45)ax1_2=ax1.twinx() ax1_2.fill_between(date, 0, (ask-bid), facecolor='g', alpha=.3) plt.subplot(bottom=.23) plt.grid(True) plt.show()graphRawFx()patternFinder()