Code Monkey home page Code Monkey logo

tradingpatternscanner's Introduction

TradingPatternScanner

Python CI

Author: Preetam Sharma

Overview

Trading Pattern Scanner Identifies complex patterns like head and shoulder, wedge and many more.

New Enhancements

Four new features for pattern detection have been added:

  1. Basic Head-Shoulder Detection: The initial unfiltered version of pattern detection. It uses a rolling window to track high and low points, then identifies Head and Shoulder and Inverse Head and Shoulder patterns.
  2. Head-Shoulder Detection with Savitzky-Golay Filter: This feature uses the Savitzky-Golay filter to reduce noise and improve pattern detection. It also considers the height of the "Head" or "Inverse Head" to avoid false pattern recognition.
  3. Head-Shoulder Detection with Kalman Filter: This feature utilizes the Kalman Filter, a recursive filter that estimates the state of a system in real time. It's particularly suitable for financial data due to its inherent noise and uncertainties.
  4. Head-Shoulder Detection with Wavelet Denoising: This final feature applies wavelet denoising to eliminate noise while preserving key features in the data. It makes pattern detection more robust and reliable, especially in the presence of high-frequency noise.

These enhancements provide more accurate pattern detection for your financial analysis needs.

Analysis

Each method has been rigorously tested and analysed on synthetic data that closely mirrors real-world financial data. However, it's important to note that synthetic data is not an exact representation of the real-world, and the performance of each algorithm may vary in a live setting. Therefore, users are encouraged to test each algorithm against their own datasets and pick the one that best suits their needs.

  • Accuracy for head_shoulder_pattern_window: 78.50%
  • Accuracy for head_shoulder_pattern_filter: 78.50%
  • Accuracy for head_shoulder_pattern_kf: 73.50%
  • Accuracy for head_shoulder_pattern_wavelet: 84.50%

Analysis

Heatmap Interpretation

  • For instance, let's consider a cell in the 2nd row and 2nd column. the score is 10, it means that a significant number of instances were correctly identified as "Head and Shoulder" pattern (abbreviated as HS).

  • On the contrary, a dark cell outside this diagonal indicates a high number of misclassifications. For example, a dark cell at the intersection of "HS" row and "I-HS" column would mean that a large number of instances were true "HS" but were incorrectly predicted as "Inverse Head and Shoulder" (abbreviated as I-HS) by the scanner.

Abbreviations

The abbreviations used in the heatmap and the code are as follows:

  • HS - Head and Shoulder pattern
  • I-HS - Inverse Head and Shoulder pattern

Installation / Usage

Install using pip:

$ pip install tradingpattern

TradingPatternScanner

Trading patterns:

  • Head and Shoulder and inverse Head and Shoulder: These patterns indicate a potential reversal in the market, with the "head" being the highest point, and the "shoulders" being the points on either side at a slightly lower level.
  • Multiple top and bottom: These patterns indicate a range-bound market, with multiple highs and lows forming a horizontal range.
  • Horizontal support and resistance: These patterns indicate key levels at which the market has previously struggled to break through.
  • Ascending and Descending Triangle pattern: These patterns indicate a potential breakout in the market, with the upper trendline being resistance and the lower trendline being support.
  • Wedge up and down: These patterns indicate a potential reversal in the market, with the trendlines converging towards each other.
  • Channel up and down: These patterns indicate a strong trend in the market, with price moving within a well-defined upper and lower trendline.
  • Double top and bottom: These patterns indicate a potential reversal in the market, with the market hitting a high or low twice and then reversing.
  • Trend line support and resistance: These patterns indicate key levels at which the market is likely to experience support or resistance based on historical price action.
  • Finding Higher-High and Lower-Low

Designed for fast performance:

  • Uses only Pandas as Numpy, no other external libraries: This approach helps to keep the library lightweight and fast.
  • Uses the concept of vectorization: This approach helps to improve performance by processing large amounts of data at once, rather than iterating over each individual data point.

New and Unique:

  • No other python library exists for such task currently: This library is new and unique, as it aims to provide an all-in-one solution for identifying various trading patterns.

Lets check if its works for simplicity I used finviz and checked the pattern with the respective stock.

  • Head and Shoulder: Head and Shoulder

We can see that it finds out that we have inverse head and shoulder pattern in the stock on 9th Januray 2023 in 1 day interval. Lets match with Finviz. Finviz

  • We can see that Finviz also detects on 9th Januray 2023 in 1 day interval.
  • You can adjust the window size to your liking. A smaller window size will be more sensitive to detecting patterns, but it will also increase the chances of false positives. A larger window size will be less sensitive to detecting patterns, but it will also decrease the chances of false positives.

Future add-ons:

  • Request your favourite pattern to get added in the list: The library is open for suggestions for adding new patterns.
  • Work on visualization and plotting: The library can be extended to include visualization and plotting features to help users better understand the patterns identified.
  • Add unit testing: The library can be extended to include unit testing to ensure that the code is working as expected and to catch any bugs early on.

tradingpatternscanner's People

Contributors

mateuszgemzicki avatar white07s avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tradingpatternscanner's Issues

The signal seems to be too sensitive

I tried the codebase and there are so many signals that are not obvious
But still feel that this codebase is too useful, really looking forward to the subsequent code

Executing detect_wedge() fails

Hi,

thanks a lot for setting up, sharing and maintaining this project. You are doing a very good job!

I have a small question:

I executed detect_wedge(df, window=3): from TradingPatternScanner/tradingpatterns/tradingpatterns.py.

Unfortunately, I get an error:

File ".../lib/python3.10/site-packages/pandas/core/indexes/range.py", line 416, in get_loc
raise KeyError(key) from err
KeyError: -1

This error comes up at this line:

df['trend_high'] = df['High'].rolling(window=roll_window).apply(lambda x: 1 if (x[-1] - x[0]) > 0 else -1 if (x[-1] - x[0]) < 0 else 0)

Am I doing something wrong? Respectively: what do I have to do to get beyond this point?

used versions:

pandas: 2.1.0
python: 3.10.12

Thanks in advance.

Unclear how to use this code

Hi, this code seems like its everything i could need rn, but i struggle to understand how i can utilize it. As I've understodd you can run analysis.py and get future predictions on trends and price just like on a chart. My question is, how can i use this to predict the futures cryptocurrency BTCUSDT.P?
Screenshot 2023-08-06 at 15 17 59

Request improvement

hello
I'm interested this project because it's similar to my work in the company.
your project is cool but, i want some improvement

  1. chart pattern start point and end point : It's unclear when the charts start and end.
  2. detail : each point to be clear which part of the chart pattern.

my project uses argrelextrema function in scipy to recognize zigzag patterns.
next Explore patterns using different conditional expressions in zigzag pattern.
call me if you're interested. I want to join you in your project to share opinion.
image

pip install problem

I get this error can you help me?

C:\Users*****>pip install TradingPatternScanner-0.1.2.zip
Defaulting to user installation because normal site-packages is not writeable
Processing c:\users\ebaha\tradingpatternscanner-0.1.2.zip
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> [35 lines of output]
Traceback (most recent call last):
File "C:\Users\ebaha\AppData\Roaming\Python\Python39\site-packages\pip_vendor\pep517\in_process_in_process.py", line 351, in
main()
File "C:\Users\ebaha\AppData\Roaming\Python\Python39\site-packages\pip_vendor\pep517\in_process_in_process.py", line 333, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "C:\Users\ebaha\AppData\Roaming\Python\Python39\site-packages\pip_vendor\pep517\in_process_in_process.py", line 118, in get_requires_for_build_wheel
return hook(config_settings)
File "C:\Users\ebaha\AppData\Local\Temp\pip-build-env-_z8zdzw4\overlay\Lib\site-packages\setuptools\build_meta.py", line 338, in get_requires_for_build_wheel
return self._get_build_requires(config_settings, requirements=['wheel'])
File "C:\Users\ebaha\AppData\Local\Temp\pip-build-env-_z8zdzw4\overlay\Lib\site-packages\setuptools\build_meta.py", line 320, in _get_build_requires
self.run_setup()
File "C:\Users\ebaha\AppData\Local\Temp\pip-build-env-_z8zdzw4\overlay\Lib\site-packages\setuptools\build_meta.py", line 335, in run_setup
exec(code, locals())
File "", line 1, in
File "C:\Users\ebaha\AppData\Local\Temp\pip-build-env-z8zdzw4\overlay\Lib\site-packages\setuptools_init.py", line 108, in setup
return distutils.core.setup(**attrs)
File "C:\Users\ebaha\AppData\Local\Temp\pip-build-env-_z8zdzw4\overlay\Lib\site-packages\setuptools_distutils\core.py", line 147, in setup
_setup_distribution = dist = klass(attrs)
File "C:\Users\ebaha\AppData\Local\Temp\pip-build-env-_z8zdzw4\overlay\Lib\site-packages\setuptools\dist.py", line 475, in init
_Distribution.init(
File "C:\Users\ebaha\AppData\Local\Temp\pip-build-env-_z8zdzw4\overlay\Lib\site-packages\setuptools_distutils\dist.py", line 283, in init
self.finalize_options()
File "C:\Users\ebaha\AppData\Local\Temp\pip-build-env-_z8zdzw4\overlay\Lib\site-packages\setuptools\dist.py", line 904, in finalize_options
ep(self)
File "C:\Users\ebaha\AppData\Local\Temp\pip-build-env-_z8zdzw4\overlay\Lib\site-packages\setuptools_scm\integration.py", line 127, in infer_version
_assign_version(dist, config)
File "C:\Users\ebaha\AppData\Local\Temp\pip-build-env-_z8zdzw4\overlay\Lib\site-packages\setuptools_scm\integration.py", line 63, in _assign_version
_version_missing(config)
File "C:\Users\ebaha\AppData\Local\Temp\pip-build-env-z8zdzw4\overlay\Lib\site-packages\setuptools_scm_init.py", line 108, in _version_missing
raise LookupError(
LookupError: setuptools-scm was unable to detect version for C:\Users\ebaha\AppData\Local\Temp\pip-req-build-cpe0__4u.

  Make sure you're either building from a fully intact git repository or PyPI tarballs. Most other sources (such as GitHub's tarballs, a git checkout without the .git folder) don't contain the necessary metadata and will not work.

  For example, if you're using pip, instead of https://github.com/user/proj/archive/master.zip use git+https://github.com/user/proj.git#egg=proj
  [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

Cosmetic change in find_pivots

Cosmetic change in find_pivots
While all other methods, its High and Low, in this method it was high and low ( all lowers )
Thank you. Arun

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.