0% found this document useful (0 votes)
7 views8 pages

Advance Coding Mini Project

The 'Stock Price Tracker' mini project report outlines the development of a Python application designed to track and analyze daily stock prices using arrays. Key functionalities include adding and removing prices, calculating statistics (average, max, min), detecting trends, and visualizing data with Matplotlib. This project serves as a practical application of programming concepts to assist investors and analysts in making informed decisions based on stock price trends.

Uploaded by

msomavar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views8 pages

Advance Coding Mini Project

The 'Stock Price Tracker' mini project report outlines the development of a Python application designed to track and analyze daily stock prices using arrays. Key functionalities include adding and removing prices, calculating statistics (average, max, min), detecting trends, and visualizing data with Matplotlib. This project serves as a practical application of programming concepts to assist investors and analysts in making informed decisions based on stock price trends.

Uploaded by

msomavar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

STOCK PRICE TRACKER

Advance coding (24CSEN2371)

Mini project report

Semester-VII

BACHELOR OF TECHNOLOGY
IN
COMPUTER SCIENCE AND ENGINEERING

Submitted by

HEMASRI.GULIPALLI - VU21CSEN0101443
S.J MEGHANA - VU21CSEN0101487
PILLA.SAI SHANKAR - VU21CSEN0101446
Under esteemed guidance of
Mr. Ambeshwar Kumar

DEPARTMENT OF COMPUTER SCIENCE ENGINEERING

GITAM
(Deemed to be University)
VISAKHAPATNAM
NOVEMBER 2024

1
INTRODUCTION

In today’s rapidly evolving financial markets, tracking and analyzing stock


prices has become essential for informed decision-making. With the
fluctuations in stock prices influenced by economic factors, company
performance, and investor sentiment, investors and analysts require
efficient tools to monitor trends and detect patterns over time. The
"Stock Price Tracker" case study is designed to demonstrate the practical
application of arrays (or lists) in programming, specifically focusing on
holding and analyzing daily stock prices.
By utilizing arrays, we create a fundamental data structure that
efficiently stores daily price data and enables a range of analytical
operations. In this case study, we explore a Python-based application
that not only records daily prices but also provides functionality for
critical analysis. The program allows users to add new prices, remove
historical prices, and retrieve key metrics such as average price,
maximum and minimum values. It also enables users to view price
changes between specific days and detect trends such as increasing or
decreasing movements, which are essential for understanding stock
behavior over time.
A unique aspect of this case study is the graphical representation of stock
prices, achieved through integration with the Matplotlib library. By
visualizing data, the tracker provides users with an immediate
understanding of price trends, which can aid in quick decision-making
and more comprehensive analysis.

2
IMPLEMENTATION
The implementation of the Stock Price Tracker in Python involves
designing a program that utilizes arrays (lists) to hold and manipulate
daily stock prices. This tracker provides several key functionalities:
adding, removing, analyzing, and visualizing stock prices, with each
feature structured to allow straightforward data management and
analysis.
1. Data Storage with Arrays: We begin by creating a class
called StockPriceTracker that uses a list to store daily stock prices.
Each day’s price is appended to this list, simulating a daily record.
Using a list is efficient here, as it allows dynamic resizing, enabling
the addition and removal of prices without predefined constraints
on the number of entries.
2. Adding and Removing Prices: The add_price method allows the
user to input a stock price for a new day, automatically appending
it to the list. The remove_price method is designed to delete a
price from a specific day (1-indexed), allowing users to make
adjustments or correct data.
3. Statistical Analysis: The tracker includes methods to calculate the
average, maximum, and minimum stock prices within the stored
data, providing essential statistics for understanding stock
behavior. Additionally, the price_change method calculates the
difference between stock prices on any two given days.
4. Data Visualization: Finally, we integrate Matplotlib for data
visualization. The plot_prices method generates a line graph of
the stock prices over the days. This visual representation of data is
crucial for identifying trends and patterns that are not
immediately obvious from the raw data.

3
IMPLEMENTATION OF CODE

import matplotlib.pyplot as plt

class StockPriceTracker:
def __init__(self):
self.daily_prices = []

def add_price(self, price):


"""Add a stock price for a new day."""
self.daily_prices.append(price)
print(f"Price {price} added for day {len(self.daily_prices)}.")

def remove_price(self, day):


"""Remove the stock price of a specific day (1-indexed)."""
if 1 <= day <= len(self.daily_prices):
removed_price = self.daily_prices.pop(day - 1)
print(f"Removed price {removed_price} from day {day}.")
else:
print("Invalid day. Please provide a valid day number.")

def average_price(self):
"""Calculate the average stock price."""
if not self.daily_prices:
return 0
return sum(self.daily_prices) / len(self.daily_prices)

def max_price(self):
"""Find the maximum stock price."""
if not self.daily_prices:
return None
return max(self.daily_prices)

def min_price(self):
"""Find the minimum stock price."""
if not self.daily_prices:
return None
return min(self.daily_prices)

def price_change(self, day1, day2):


"""Get the price change between two days (1-indexed)."""
if 1 <= day1 <= len(self.daily_prices) and 1 <= day2 <=
len(self.daily_prices):

4
return self.daily_prices[day2 - 1] - self.daily_prices[day1 -
1]
else:
print("Invalid days. Please provide valid day numbers.")
return None

def detect_trends(self):
"""Detect increasing or decreasing trends."""
trends = []
for i in range(1, len(self.daily_prices)):
if self.daily_prices[i] > self.daily_prices[i - 1]:
trends.append("Up")
elif self.daily_prices[i] < self.daily_prices[i - 1]:
trends.append("Down")
else:
trends.append("No Change")
return trends

def plot_prices(self):
"""Plot stock prices for visualization."""
if not self.daily_prices:
print("No prices to plot.")
return
days = list(range(1, len(self.daily_prices) + 1))
plt.figure(figsize=(10, 6))
plt.plot(days, self.daily_prices, marker='o', linestyle='-',
color='b')
plt.title("Stock Price Trend")
plt.xlabel("Day")
plt.ylabel("Price")
plt.grid(True)
plt.show()

# Example usage of the StockPriceTracker class


tracker = StockPriceTracker()

# Adding some daily prices


tracker.add_price(100)
tracker.add_price(102)
tracker.add_price(101)
tracker.add_price(104)
tracker.add_price(103)

# Removing a price (e.g., for day 3)


tracker.remove_price(3)

5
# Calculating statistics
print(f"Average price: {tracker.average_price()}")
print(f"Maximum price: {tracker.max_price()}")
print(f"Minimum price: {tracker.min_price()}")

# Price change between days


print(f"Price change between day 1 and day 4: {tracker.price_change(1,
4)}")

# Detecting trends
print("Trends:", tracker.detect_trends())

# Plotting prices
tracker.plot_prices()

OUTPUT
Price 100 added for day 1.
Price 102 added for day 2.
Price 101 added for day 3.
Price 104 added for day 4.
Price 103 added for day 5.
Removed price 101 from day 3.
Average price: 102.25
Maximum price: 104
Minimum price: 100
Price change between day 1 and day 4: 3
Trends: ['Up', 'Up', 'Down']

6
7
CONCLUSION

"Stock Price Tracker" case study demonstrates how fundamental


programming concepts, such as arrays, can be applied to solve real-world
financial problems and provide insights into stock price trends. By
leveraging a simple data structure, we built a functional and versatile
tracker that not only holds daily stock prices but also performs essential
analytical operations and visualizes data. This project illustrates how
arrays, combined with well-organized methods, can serve as the
backbone of a data analysis application, supporting various tasks from
data entry to complex calculations and graphical representations.
The implementation of features like average calculation, maximum and
minimum price identification, trend detection, and price change analysis
transforms this tracker into a useful tool for investors, students, and
analysts. These functionalities allow users to assess market behavior,
evaluate volatility, and make data-informed decisions. Additionally, the
trend detection feature offers valuable insights into stock price
movement, which is crucial for understanding the short-term behavior
of stocks. The integration of Matplotlib for visualizing the data further
enhances the usability of the tool by enabling users to quickly grasp
trends and patterns through graphical representations.

You might also like