nehulagrawal commited on
Commit
9634a9d
·
verified ·
1 Parent(s): a5f43ff

This version is capable of capturing real-time stock images, detecting patterns in them, and generating a video and an Excel file containing annotated or predicted images with labels and timestamps.

Files changed (1) hide show
  1. README.md +87 -104
README.md CHANGED
@@ -7,14 +7,14 @@ tags:
7
  - vision
8
  - object-detection
9
  - pytorch
10
- - finance
11
  - stock market
12
  - candlesticks
13
  - pattern recognition
14
  - option trading
15
  - chart reader
16
  library_name: ultralytics
17
- library_version: 8.0.43
18
  inference: false
19
  model-index:
20
  - name: foduucom/stockmarket-pattern-detection-yolov8
@@ -34,26 +34,24 @@ pipeline_tag: object-detection
34
  <img width="500" alt="foduucom/stockmarket-pattern-detection-yolov8" src="https://huggingface.co/foduucom/stockmarket-pattern-detection-yolov8/resolve/main/thumbnail.jpg">
35
  </div>
36
 
37
- # Model Card for YOLOv8s Stock Market Pattern Detection on Live Trading Video Data
38
 
39
  ## Model Summary
40
 
41
- The YOLOv8s Stock Market Pattern Detection model is an object detection model based on the YOLO (You Only Look Once) framework. It is designed to detect various chart patterns in real-time stock market trading video data. The model aids traders and investors by automating the analysis of chart patterns, providing timely insights for informed decision-making. The model has been fine-tuned on a diverse dataset and achieved high accuracy in detecting and classifying stock market patterns in live trading scenarios.
42
 
43
  ## Model Details
44
 
45
  ### Model Description
46
- The YOLOv8s Stock Market Pattern Detection model offers a transformative solution for traders and investors by enabling real-time detection of crucial chart patterns within live trading video data. As stock markets evolve rapidly, this model's capabilities empower users with timely insights, allowing them to make informed decisions with speed and accuracy.
47
 
48
- The model seamlessly integrates into live trading systems, providing instant pattern detection and classification. By leveraging advanced bounding box techniques and pattern-specific feature extraction, the model excels in identifying patterns such as 'Head and shoulders bottom,' 'Head and shoulders top,' 'M_Head,' 'StockLine,' 'Triangle,' and 'W_Bottom.' This enables traders to optimize their strategies, automate trading decisions, and respond to market trends in real-time.
49
 
50
- To facilitate integration into live trading systems or to inquire about customization, please contact us at [email protected]. Your collaboration and feedback are instrumental in refining and enhancing the model's performance in dynamic trading environments.
51
 
52
  - **Developed by:** FODUU AI
53
  - **Model type:** Object Detection
54
- - **Task:** Stock Market Pattern Detection on Live Trading Video Data
55
-
56
- The YOLOv8s Stock Market Pattern Detection model is designed to adapt to the fast-paced nature of live trading environments. Its ability to operate on real-time video data allows traders and investors to harness pattern-based insights without delay.
57
 
58
  ### Supported Labels
59
 
@@ -64,126 +62,111 @@ The YOLOv8s Stock Market Pattern Detection model is designed to adapt to the fas
64
  ## Uses
65
 
66
  ### Direct Use
67
-
68
- The YOLOv8s Stock Market Pattern Detection model can be directly integrated into live trading systems to provide real-time detection and classification of chart patterns. Traders can utilize the model's insights for timely decision-making.
69
 
70
  ### Downstream Use
71
-
72
  The model's real-time capabilities can be leveraged to automate trading strategies, generate alerts for specific patterns, and enhance overall trading performance.
73
 
74
- ### Training data
75
- The Stockmarket model was trained on custom dataset consisting of 9000/800 annotated images for training/validation respectively.
76
-
77
 
78
  ### Out-of-Scope Use
79
-
80
- The model is not designed for unrelated object detection tasks or scenarios outside the scope of stock market pattern detection in live trading video data.
81
 
82
  ## Bias, Risks, and Limitations
83
 
84
- The YOLOv8s Stock Market Pattern Detection model may exhibit some limitations and biases:
85
-
86
- - Performance may be affected by variations in video quality, lighting conditions, and pattern complexity within live trading data.
87
- - Rapid market fluctuations and noise in video data may impact the model's accuracy and responsiveness.
88
- - Market-specific patterns or anomalies not well-represented in the training data may pose challenges for detection.
89
 
90
  ### Recommendations
91
-
92
- Users should be aware of the model's limitations and potential biases. Thorough testing and validation within live trading simulations are advised before deploying the model in real trading environments.
93
 
94
  ## How to Get Started with the Model
95
 
96
- To begin using the YOLOv8s Stock Market Pattern Detection model on live trading video data, follow these steps:
97
  ```bash
98
- pip install ultralyticsplus==0.0.28 ultralytics==8.0.43
99
  ```
100
 
101
- - Load model and perform real-time prediction:
102
-
103
  ```python
104
- from ultralyticsplus import YOLO, render_result
 
105
  import cv2
106
-
107
- # load model
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  model = YOLO('foduucom/stockmarket-pattern-detection-yolov8')
109
 
110
- # set model parameters
111
- model.overrides['conf'] = 0.25 # NMS confidence threshold
112
- model.overrides['iou'] = 0.45 # NMS IoU threshold
113
- model.overrides['agnostic_nms'] = False # NMS class-agnostic
114
- model.overrides['max_det'] = 1000 # maximum number of detections per image
115
-
116
- # initialize video capture
117
- # Open the video file
118
- video_path = "path/to/your/video/file.mp4"
119
- cap = cv2.VideoCapture(video_path)
120
-
121
- # Loop through the video frames
122
- while cap.isOpened():
123
- # Read a frame from the video
124
- success, frame = cap.read()
125
-
126
- if success:
127
- # Run YOLOv8 inference on the frame
128
- results = model(frame)
129
-
130
- # Visualize the results on the frame
131
- annotated_frame = results[0].plot()
132
-
133
- # Display the annotated frame
134
- cv2.imshow("YOLOv8 Inference", annotated_frame)
135
-
136
- # Break the loop if 'q' is pressed
137
- if cv2.waitKey(1) & 0xFF == ord("q"):
138
- break
139
- else:
140
- # Break the loop if the end of the video is reached
141
- break
142
-
143
- # Release the video capture object and close the display window
144
- cap.release()
145
- cv2.destroyAllWindows()
 
 
 
 
 
 
146
  ```
147
 
148
- ## Training Details
149
-
150
- ### Training Data
151
-
152
- The model is trained on a diverse dataset containing stock market chart images with various chart patterns, capturing different market conditions and scenarios.
153
-
154
- ### Training Procedure
155
-
156
- The training process involves extensive computation and is conducted over multiple epochs. The model's weights are adjusted to minimize detection loss and optimize performance for stock market pattern detection.
157
-
158
- #### Metrics
159
-
160
- - [email protected] (box):
161
- - All patterns: 0.932
162
- - Individual patterns: Varies based on pattern type
163
-
164
- ### Model Architecture and Objective
165
-
166
- The YOLOv8s architecture incorporates modifications tailored to stock market pattern detection. It features a specialized backbone network, self-attention mechanisms, and pattern-specific feature extraction modules.
167
-
168
- ### Compute Infrastructure
169
-
170
- #### Hardware
171
-
172
- NVIDIA GeForce RTX 3060 card
173
-
174
- #### Software
175
-
176
- The model was trained and fine-tuned using a Jupyter Notebook environment.
177
-
178
- ## Model Card Contact
179
-
180
  For inquiries and contributions, please contact us at [email protected].
181
 
182
  ```bibtex
183
  @ModelCard{
184
- author = {Nehul Agrawal and
185
- Pranjal Singh Thakur},
186
- title = {YOLOv8s Stock Market Pattern Detection on Live Trading Video Data},
187
  year = {2023}
188
  }
189
- ```
 
 
7
  - vision
8
  - object-detection
9
  - pytorch
10
+ - finance
11
  - stock market
12
  - candlesticks
13
  - pattern recognition
14
  - option trading
15
  - chart reader
16
  library_name: ultralytics
17
+ library_version: 8.3.94
18
  inference: false
19
  model-index:
20
  - name: foduucom/stockmarket-pattern-detection-yolov8
 
34
  <img width="500" alt="foduucom/stockmarket-pattern-detection-yolov8" src="https://huggingface.co/foduucom/stockmarket-pattern-detection-yolov8/resolve/main/thumbnail.jpg">
35
  </div>
36
 
37
+ # Model Card for YOLOv8s Stock Market Pattern Detection from Live Screen Capture
38
 
39
  ## Model Summary
40
 
41
+ The YOLOv8s Stock Market Pattern Detection model is an object detection model based on the YOLO (You Only Look Once) framework. It is designed to detect various chart patterns in real-time from screen-captured stock market trading data. The model aids traders and investors by automating the analysis of chart patterns, providing timely insights for informed decision-making. The model has been fine-tuned on a diverse dataset and achieves high accuracy in detecting and classifying stock market patterns in live trading scenarios.
42
 
43
  ## Model Details
44
 
45
  ### Model Description
46
+ The YOLOv8s Stock Market Pattern Detection model enables real-time detection of crucial chart patterns within stock market screen captures. As stock markets evolve rapidly, this model's capabilities empower users with timely insights, allowing them to make informed decisions with speed and accuracy.
47
 
48
+ The model is designed to work with screen capture of stock market trading charts. It can detect patterns such as 'Head and shoulders bottom,' 'Head and shoulders top,' 'M_Head,' 'StockLine,' 'Triangle,' and 'W_Bottom.' Traders can optimize their strategies, automate trading decisions, and respond to market trends in real-time.
49
 
50
+ To integrate this model into live trading systems or for customization inquiries, please contact us at [email protected].
51
 
52
  - **Developed by:** FODUU AI
53
  - **Model type:** Object Detection
54
+ - **Task:** Stock Market Pattern Detection from Screen Capture
 
 
55
 
56
  ### Supported Labels
57
 
 
62
  ## Uses
63
 
64
  ### Direct Use
65
+ The model can be used for real-time pattern detection on screen-captured stock market charts. It can log detected patterns, annotate detected images, save results in an Excel file, and generate a video of detected patterns over time.
 
66
 
67
  ### Downstream Use
 
68
  The model's real-time capabilities can be leveraged to automate trading strategies, generate alerts for specific patterns, and enhance overall trading performance.
69
 
70
+ ### Training Data
71
+ The Stock Market model was trained on a custom dataset consisting of 9000 training images and 800 validation images.
 
72
 
73
  ### Out-of-Scope Use
74
+ The model is not designed for unrelated object detection tasks or scenarios outside the scope of stock market pattern detection from screen-captured data.
 
75
 
76
  ## Bias, Risks, and Limitations
77
 
78
+ - Performance may be affected by variations in chart styles, screen resolution, and market conditions.
79
+ - Rapid market fluctuations and noise in trading data may impact accuracy.
80
+ - Market-specific patterns not well-represented in the training data may pose challenges for detection.
 
 
81
 
82
  ### Recommendations
83
+ Users should be aware of the model's limitations and potential biases. Testing and validation with historical data and live market conditions are advised before deploying the model for real trading decisions.
 
84
 
85
  ## How to Get Started with the Model
86
 
87
+ To begin using the YOLOv8s Stock Market Pattern Detection model, install the necessary libraries:
88
  ```bash
89
+ pip install opencv-python==4.11.0.86 numpy==2.1.3 mss==10.0.0 ultralytics==8.3.94 openpyxl==3.1.5
90
  ```
91
 
92
+ ### Screen Capture and Pattern Detection Implementation
 
93
  ```python
94
+ import os
95
+ import mss
96
  import cv2
97
+ import numpy as np
98
+ import time
99
+ import glob
100
+ from ultralytics import YOLO
101
+ from openpyxl import Workbook
102
+
103
+ # Define paths
104
+ home_dir = os.path.expanduser("~")
105
+ save_path = os.path.join(home_dir, "yolo_detection")
106
+ screenshots_path = os.path.join(save_path, "screenshots")
107
+ detect_path = os.path.join(save_path, "runs", "detect")
108
+ os.makedirs(screenshots_path, exist_ok=True)
109
+ os.makedirs(detect_path, exist_ok=True)
110
+
111
+ # Define pattern classes
112
+ classes = ['Head and shoulders bottom', 'Head and shoulders top', 'M_Head', 'StockLine', 'Triangle', 'W_Bottom']
113
+
114
+ # Load YOLOv8 model
115
  model = YOLO('foduucom/stockmarket-pattern-detection-yolov8')
116
 
117
+ # Define screen capture region
118
+ monitor = {"top": 0, "left": 683, "width": 683, "height": 768}
119
+
120
+ # Create Excel file
121
+ excel_file = os.path.join(save_path, "classification_results.xlsx")
122
+ wb = Workbook()
123
+ ws = wb.active
124
+ ws.append(["Timestamp", "Predicted Image Path", "Label"])
125
+
126
+ # Initialize video writer
127
+ video_path = os.path.join(save_path, "annotated_video.mp4")
128
+ fourcc = cv2.VideoWriter_fourcc(*"mp4v")
129
+ fps = 0.5
130
+ video_writer = None
131
+
132
+ # Start capturing
133
+ with mss.mss() as sct:
134
+ start_time = time.time()
135
+ frame_count = 0
136
+
137
+ while time.time() - start_time < 60:
138
+ sct_img = sct.grab(monitor)
139
+ img = np.array(sct_img)
140
+ img = cv2.cvtColor(img, cv2.COLOR_BGRA2BGR)
141
+ timestamp = time.strftime("%Y-%m-%d %H:%M:%S")
142
+ image_name = f"predicted_images_{timestamp}_{frame_count}.png"
143
+ image_path = os.path.join(screenshots_path, image_name)
144
+ cv2.imwrite(image_path, img)
145
+
146
+ results = model(image_path, save=True)
147
+ predict_path = results[0].save_dir if results else None
148
+ annotated_images = sorted(glob.glob(os.path.join(predict_path, "*.jpg")), key=os.path.getmtime, reverse=True) if predict_path else []
149
+ final_image_path = annotated_images[0] if annotated_images else image_path
150
+
151
+ predicted_label = classes[int(results[0].boxes.cls.tolist()[0])] if results and results[0].boxes else "No pattern detected"
152
+ ws.append([timestamp, final_image_path, predicted_label])
153
+ wb.save(excel_file)
154
+
155
+ frame_count += 1
156
+ time.sleep(5)
157
+
158
+ print(f"Results saved to {excel_file}")
159
  ```
160
 
161
+ ## Model Contact
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
  For inquiries and contributions, please contact us at [email protected].
163
 
164
  ```bibtex
165
  @ModelCard{
166
+ author = {Nehul Agrawal,
167
+ Pranjal Singh Thakur, Arjun Singh},
168
+ title = {YOLOv8s Stock Market Pattern Detection from Live Screen Capture},
169
  year = {2023}
170
  }
171
+ ```
172
+