Skip to content

Commit afeac08

Browse files
Merge pull request #10 from Muawiya-contact/STA
STA → Stocks Trend Analyzer
2 parents 1e95d07 + 5d3b991 commit afeac08

19 files changed

Lines changed: 503 additions & 0 deletions

Stocks Trend Analyzer/README.md

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# 📈 Stocks Trend Analyzer (Data Structures Project)
2+
3+
**Course:** Data Structures & Algorithms (DSA)
4+
**Semester:** 3rd
5+
**Submitted To:** Sir Hasnain Yousaf Khan
6+
**Submitted By:**
7+
8+
- 🧠 *Shazada M. Umar* (2k24_BSAI_42)
9+
- 🧠 *Moavia Amir* (2k24_BSAI_72) — contactmuawia@gmail.com
10+
- ⚙️ *Faizan Ishfaq* (2k24_BSAI_50)
11+
- ⚙️ *M. Hamza* (2k24_BSAI_46)
12+
13+
---
14+
15+
## 📘 Project Overview
16+
17+
**Stocks Trend Analyzer** is a Python-based application that analyzes historical stock market data using **Data Structures and Algorithms**.
18+
The system detects rising/falling patterns, computes moving averages, highlights buy–sell intervals, and visualizes trends using **Tkinter** and **Matplotlib**.
19+
20+
The goal is to help students understand how DSA concepts apply to real-world financial time-series data.
21+
22+
---
23+
24+
## 🔍 Problem Statement
25+
26+
Financial datasets are large, noisy, and difficult for beginners to interpret. Without proper analysis, it becomes challenging to identify:
27+
28+
- Continuous rising or falling trends
29+
- Local highs and lows
30+
- Smoothed patterns (moving averages)
31+
- Optimal moments to buy or sell
32+
33+
This project provides a simple and visual solution using efficient algorithms and Python-based tools.
34+
35+
---
36+
37+
## 🎯 Objectives
38+
39+
- Build a working desktop tool to analyze stock time-series data
40+
- Implement DSA concepts such as arrays, queues, stacks, and maps
41+
- Detect trends and compute moving averages
42+
- Identify the best buy–sell intervals using an O(n) algorithm
43+
- Visualize insights using charts
44+
- Create a user-friendly GUI for easy interaction
45+
46+
---
47+
48+
## 🧠 System Overview
49+
50+
| Component | Purpose |
51+
|----------|----------|
52+
| **Python (Core)** | Implements algorithms and data structures |
53+
| **Tkinter** | GUI for importing and analyzing data |
54+
| **Matplotlib** | Visualization of trends and signals |
55+
| **CSV Dataset** | Yahoo Finance or Kaggle stock data |
56+
| **DSA Used** | Arrays, Lists, Stacks, Queues, Maps |
57+
58+
---
59+
60+
## 🔬 Working Principle
61+
62+
1. User loads a CSV file containing daily stock prices.
63+
2. Data is stored in custom **Array/List** structures.
64+
3. Algorithms run on the dataset:
65+
- Trend detection
66+
- Moving average calculation (Queue / Sliding Window)
67+
- Local high/low using Stack logic
68+
- Max-profit interval (Buy–Sell Strategy)
69+
4. Tkinter displays results and summary.
70+
5. Matplotlib generates charts with lines, markers, and trends.
71+
72+
---
73+
74+
## 🛠 Features
75+
76+
- 📊 **Trend Detection:** Identifies rising/falling streaks
77+
- 📉 **Moving Averages:** Smooths noisy data using queue-based windows
78+
- 💹 **Best Buy–Sell Interval:** Shows most profitable days
79+
- 📈 **Visual Charts:** Price lines, moving averages, highs/lows
80+
- 🖥 **User-Friendly GUI:** Import CSV and analyze instantly
81+
- 🧠 **DSA-Focused Implementation:** Each module uses required structures
82+
83+
---
84+
85+
## 🛠 Technologies & Tools
86+
87+
- Python
88+
- Tkinter (GUI)
89+
- Matplotlib (Visualization)
90+
- Custom Data Structures
91+
- CSV Data (Stock Prices)
92+
93+
---
94+
95+
## 📂 Folder Structure
96+
97+
```
98+
Stocks-Trend-Analyzer/
99+
├─ README.md # (this file)
100+
├─ main.py # Tkinter GUI
101+
├─ algorithms/
102+
│ ├─ trend_analysis.py
103+
│ ├─ moving_average.py
104+
│ ├─ max_profit.py
105+
│ └─ local_high_low.py
106+
├─ dsa/
107+
│ ├─ array_list.py
108+
│ ├─ queue.py
109+
│ └─ stack.py
110+
├─ data/
111+
│ └─ sample_stock.csv
112+
├─ charts/
113+
│ └─ generated_charts.png
114+
└─ docs/
115+
├─ Proposal.pdf
116+
└─ Report.pdf
117+
```
118+
---
119+
120+
## 📅 Project Timeline (6 Weeks)
121+
122+
| Week | Task |
123+
|------|------|
124+
| Week 1 | Requirement analysis, dataset collection |
125+
| Week 2 | Implement data structures |
126+
| Week 3 | Implement algorithms |
127+
| Week 4 | Develop Tkinter GUI |
128+
| Week 5 | Add Matplotlib charts |
129+
| Week 6 | Testing, debugging, documentation |
130+
131+
```
132+
133+
---
134+
135+
## 🎓 Expected Learning Outcomes
136+
137+
- Understand and apply DSA to financial datasets
138+
- Learn how queues, stacks, and arrays operate in practical use-cases
139+
- Gain experience with GUI development
140+
- Learn data visualization techniques
141+
- Strengthen algorithmic thinking and problem-solving
142+
143+
---
144+
145+
## 🧾 Conclusion
146+
147+
The **Stocks Trend Analyzer** blends algorithms, data structures, and visualization to provide meaningful insights into stock behavior.
148+
This project demonstrates the power of DSA in solving real-world problems and sets a foundation for advanced financial analytics, predictive modeling, and multi-stock comparison systems.
149+
150+
---
151+
152+
## 📫 Contact
153+
154+
- **Moavia Amir** — contactmuawia@gmail.com
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from dsa.stack import Stack
2+
3+
class LocalHighLow:
4+
def __init__(self, prices):
5+
self.prices = prices
6+
7+
def find_local_extremes(self):
8+
stack = Stack()
9+
extremes = []
10+
n = len(self.prices)
11+
for i in range(n):
12+
if i == 0 or i == n-1:
13+
continue
14+
if self.prices[i] > self.prices[i-1] and self.prices[i] > self.prices[i+1]:
15+
extremes.append((i, "High", self.prices[i]))
16+
elif self.prices[i] < self.prices[i-1] and self.prices[i] < self.prices[i+1]:
17+
extremes.append((i, "Low", self.prices[i]))
18+
return extremes
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class MaxProfit:
2+
def __init__(self, prices):
3+
self.prices = prices
4+
5+
def best_interval(self):
6+
if not self.prices:
7+
return None, None, 0
8+
9+
min_price = self.prices[0]
10+
min_index = 0
11+
max_profit = 0
12+
buy_day = 0
13+
sell_day = 0
14+
15+
for i, price in enumerate(self.prices):
16+
if price - min_price > max_profit:
17+
max_profit = price - min_price
18+
buy_day = min_index
19+
sell_day = i
20+
if price < min_price:
21+
min_price = price
22+
min_index = i
23+
return buy_day, sell_day, max_profit
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from dsa.queue import Queue
2+
3+
class MovingAverage:
4+
def __init__(self, window_size):
5+
self.window_size = window_size
6+
7+
def calculate(self, prices):
8+
q = Queue()
9+
moving_avgs = []
10+
for price in prices:
11+
q.enqueue(price)
12+
if q.size() > self.window_size:
13+
q.dequeue()
14+
moving_avgs.append(q.average())
15+
return moving_avgs
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from dsa.array_list import ArrayList
2+
3+
class TrendAnalysis:
4+
def __init__(self, prices):
5+
# prices: ArrayList of closing prices
6+
self.prices = prices
7+
8+
def detect_trends(self):
9+
trends = ArrayList()
10+
n = self.prices.size()
11+
if n == 0:
12+
return trends
13+
14+
streak = 1
15+
for i in range(1, n):
16+
if self.prices.get(i) > self.prices.get(i-1):
17+
streak = streak + 1 if streak > 0 else 1
18+
elif self.prices.get(i) < self.prices.get(i-1):
19+
streak = streak - 1 if streak < 0 else -1
20+
else:
21+
streak = 0 # no change
22+
trends.append(streak)
23+
return trends
41.6 KB
Loading

0 commit comments

Comments
 (0)