0
votes

I am working on an application in Python that will allow a user to select a group of candlesticks and match them with similar patterns found within an entire database of candlesticks.

I followed the 2nd tutorial in this link and was actually able to do something akin to what I want to do with Template Matching.

https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_imgproc/py_template_matching/py_template_matching.html

Template enter image description here

Image to search enter image description here

Matched result enter image description here

After matching different patterns to the template, I would like to show the candles that appeared after those matched patterns occurred. The point is to see what happened in the past with similar patterns to help determine what could happen now that a similar pattern is present.

Obviously it would be extremely inefficient to write a script that will iterate through candlestick databases and produce a bunch of chart images for Image Template Matching.

Is there something similar to Image Template Matching I can use to find candlestick patterns similar to a specified subset?

Eg. "Look at the latest 5 candles in the database, then look at the entire database and find similar patterns along with a similarity %"

I read databases into dictionaries like so:

candle_dictionary = {
"opens": [123, 121, 122, 103],
"highs": [126, 131, 122, 133],
"lows": [143, 71, 92, 100],
"closes": [173, 124, 128, 123]
}

So the close value of the newest candle in the database would be candle_dictionary["closes"][0], which would be 173.

1

1 Answers

1
votes

super simple short answer:

Take last N values and make it to a vector with N entries. Use pyflann to build a database and to search it.

Short but still simple answer:

Take N last candles and compute the log return between consecutive ones logret=log(c[t]/c[t-1]). Build a histogram of them with K bins. Use it as a K-dimensional vector.

Advanced: Have a look at this repository and the papers referenced by the author. https://github.com/patrickzib/SFA