Advance Coding Mini Project
Advance Coding Mini Project
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
GITAM
(Deemed to be University)
VISAKHAPATNAM
NOVEMBER 2024
1
INTRODUCTION
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
class StockPriceTracker:
def __init__(self):
self.daily_prices = []
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)
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()
5
# Calculating statistics
print(f"Average price: {tracker.average_price()}")
print(f"Maximum price: {tracker.max_price()}")
print(f"Minimum price: {tracker.min_price()}")
# 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