0% found this document useful (0 votes)
32 views11 pages

ML Report Miniproject

ml project report

Uploaded by

sablemadhav18
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)
32 views11 pages

ML Report Miniproject

ml project report

Uploaded by

sablemadhav18
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/ 11

“Market Stock Prediction by Analyzing

Ups and Downs in Market”


Mini Project Report Submitted in fulfillment of the requirements for the

Machine Learning

Year 2024-2025

Submitted By

Mayuri Avhad 1
Gauri Chaudhari 9
Hemangi Jadhav 21
Khyati Raghvani 48

Department of Computer Engineering

Maratha Vidya Prasarak Samaj's


Karmaveer Adv. Baburao Ganpatrao Thakare College of
Engineering
Udoji Maratha Boarding Campus, Near Pumping Station, Gangapur Road, Nashik
Title: Market Stock Prediction by Analyzing Ups and Downs in Market

1. Introduction

Analyzing Tesla's stock involves examining various factors that drive its price fluctuations,
including product innovations, earnings reports, market competition, and broader economic
trends. Tesla's stock is particularly volatile due to its leadership in the electric vehicle market,
with key influences such as new vehicle releases, advancements in battery technology, and
CEO Elon Musk's public statements. Additionally, the stock is affected by external factors like
global supply chain issues, government policies on clean energy, and competition from other
automakers. Investors use tools like technical analysis and market sentiment to predict future
stock movements, seeking to capitalize on the frequent "ups" and "downs" that characterize
Tesla's stock performance.

2. Objectives

• To analyze historical stock price trends of Tesla for identifying patterns.

• To evaluate the impact of Tesla's product launches and innovations on stock performance.

• To assess the influence of quarterly earnings reports on Tesla's stock fluctuations.

• To examine the role of market competition in Tesla's stock volatility.

3. Key Points

• Volatility of Tesla Stock: Known for significant fluctuations due to market sentiment and
external factors.

• Influence of Innovation: New vehicle models, battery advancements, and technological


innovations often drive price changes.

• Earnings Reports: Quarterly earnings significantly affect investor confidence and stock
movement.

• Elon Musk’s Influence: CEO statements and actions can trigger immediate price reactions.

• Market Competition: Growing competition in the electric vehicle space impacts Tesla’s
market share and stock.

• Global Economic Factors: Supply chain issues, energy policies, and macroeconomic
conditions contribute to stock volatility.
4. Code:

1) import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sb

from sklearn.model_selection import train_test_split


from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
from xgboost import XGBClassifier
from sklearn import metrics

import warnings
warnings.filterwarnings('ignore')

2) df = pd.read_csv('Tesla.csv')
df.head()

Date Open High Low Close Adj Close Volume

0 2010-06-29 19.000000 25.00 17.540001 23.889999 23.889999 18766300

1 2010-06-30 25.790001 30.42 23.299999 23.830000 23.830000 17187100

2 2010-07-01 25.000000 25.92 20.270000 21.959999 21.959999 8218800

3 2010-07-02 23.000000 23.10 18.709999 19.200001 19.200001 5139800

4 2010-07-06 20.000000 20.00 15.830000 16.110001 16.110001 6866900


3) df.shape
(2416, 7)

4) df.describe()

5) df.info()

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2416 entries, 0 to 2415
Data columns (total 7 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Date 2416 non-null object
1 Open 2416 non-null float64
2 High 2416 non-null float64
3 Low 2416 non-null float64
4 Close 2416 non-null float64
5 Adj Close 2416 non-null float64
6 Volume 2416 non-null int64
dtypes: float64(5), int64(1), object(1)

memory usage: 132.3+ KB

6) plt.figure(figsize=(15,5))
plt.plot(df['Close'])
plt.title('Tesla Close price.', fontsize=15)
plt.ylabel('Price in dollars.')
plt.show()
7) df[df['Close'] == df['Adj Close']].shape

(2416, 7)

8) df = df.drop(['Adj Close'], axis=1)


df.isnull().sum()

Date 0
Open 0
High 0
Low 0
Close 0
Volume 0
dtype: int64

9) features = ['Open', 'High', 'Low', 'Close', 'Volume']

plt.subplots(figsize=(20,10))

for i, col in enumerate(features):


plt.subplot(2,3,i+1)
sb.distplot(df[col])
plt.show()
10) plt.subplots(figsize=(20,10))
for i, col in enumerate(features):
plt.subplot(2,3,i+1)
sb.boxplot(df[col])
plt.show()

11) df['is_quarter_end'] = np.where(df['month']%3==0,1,0)


df.head()

12) data_grouped = df.drop('Date', axis=1).groupby('year').mean()


plt.subplots(figsize=(20,10))

for i, col in enumerate(['Open', 'High', 'Low', 'Close']):


plt.subplot(2,2,i+1)
data_grouped[col].plot.bar()
plt.show()
13) df['open-close'] = df['Open'] - df['Close']
df['low-high'] = df['Low'] - df['High']
df['target'] = np.where(df['Close'].shift(-1) > df['Close'], 1, 0)

import pandas as pd
import matplotlib.pyplot as plt

# Sample dataset creation (replace with your actual dataset)


data = {
'target': [0, 1, 1, 0, 1, 0, 1, 0, 1, 0] # Example target data
}
df = pd.DataFrame(data)

# Get the value counts for the target variable


value_counts = df['target'].value_counts()

# Create the pie chart


plt.pie(value_counts.values,
labels=value_counts.index, # Use the unique values from the tar
get as labels
autopct='%1.1f%%')
plt.title('Distribution of Target Variable') # Add a title for clarity
plt.show()
14) import pandas as pd

# Sample data (replace this with your actual DataFrame)


data = {
'Date': [
'2010-06-29', '2010-06-30', '2010-07-01', '2010-07-02', '201
0-07-06'
],
'Open': [19.0, 25.79, 25.0, 23.0, 20.0],
'High': [25.0, 30.42, 25.92, 23.1, 20.0],
'Low': [17.54, 23.3, 20.27, 18.71, 15.83],
'Close': [23.89, 23.83, 21.96, 19.2, 16.11],
'Adj Close': [23.89, 23.83, 21.96, 19.2, 16.11],
'Volume': [18766300, 17187100, 8218800, 5139800, 6866900]
}

df = pd.DataFrame(data)

# Convert 'Date' column to datetime


df['Date'] = pd.to_datetime(df['Date'])

# Extract day, month, and year


df['day'] = df['Date'].dt.day
df['month'] = df['Date'].dt.month
df['year'] = df['Date'].dt.year

# Display the updated DataFrame


print(df.head()

Date Open High Low Close Adj Close Volume day


month \
0 2010-06-29 19.00 25.00 17.54 23.89 23.89 18766300 29
6
1 2010-06-30 25.79 30.42 23.30 23.83 23.83 17187100 30
6
2 2010-07-01 25.00 25.92 20.27 21.96 21.96 8218800 1
7
3 2010-07-02 23.00 23.10 18.71 19.20 19.20 5139800 2
7
4 2010-07-06 20.00 20.00 15.83 16.11 16.11 6866900 6
7
15) import pandas as pd
import seaborn as sb
import matplotlib.pyplot as plt

# Sample DataFrame creation (replace this with your actual


DataFrame)
data = {
'feature1': [1, 2, 3, 4, 5],
'feature2': [5, 4, 3, 2, 1],
'feature3': [2, 3, 4, 5, 6],
# 'Date': ['2024-01-01', '2024-01-02', '2024-01-03', '2024-01-
04', '2024-01-05'] # Example Date column
}
df = pd.DataFrame(data)

# Check if the 'Date' column exists and drop it if it does


if 'Date' in df.columns:
df_corr = df.drop('Date', axis=1).corr()
else:
df_corr = df.corr()

# Plotting the heatmap


plt.figure(figsize=(10, 10))
sb.heatmap(df_corr > 0.9, annot=True, cbar=False)
plt.title('Heatmap of Correlation (Threshold > 0.9)') # Adding
title for clarity
plt.show()

16) import pandas as pd


from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler

# Sample DataFrame creation (replace this with your actual


DataFrame)
data = {
'open-close': [1.5, 2.0, 0.5, 1.0],
'low-high': [0.5, 1.0, 1.5, 1.0],
'is_quarter_end': [0, 1, 0, 1],
'target': [0, 1, 0, 1]
}
df = pd.DataFrame(data)
# Check the columns of the DataFrame
print("Columns in DataFrame:", df.columns)

# Verify if the required columns exist


required_columns = ['open-close', 'low-high', 'is_quarter_end']

# Ensure the required columns are in the DataFrame


missing_columns = [col for col in required_columns if col not in
df.columns]
if missing_columns:
print(f"Missing columns: {missing_columns}")
else:
features = df[required_columns]
target = df['target']

scaler = StandardScaler()
features = scaler.fit_transform(features)

X_train, X_valid, Y_train, Y_valid = train_test_split(


features, target, test_size=0.1, random_state=2022)

print(X_train.shape, X_valid.shape)

Columns in DataFrame: Index(['open-close', 'low-high',


'is_quarter_end', 'target'], dtype='object')
(3, 3) (1, 3)

17) import numpy as np


from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
from xgboost import XGBClassifier
from sklearn import metrics

# Check unique values in target variables


print("Unique values in Y_train:", np.unique(Y_train))
print("Unique values in Y_valid:", np.unique(Y_valid))

# Only proceed if both classes are present


if len(np.unique(Y_train)) == 2 and len(np.unique(Y_valid)) ==
2:
models = [LogisticRegression(), SVC(kernel='poly',
probability=True), XGBClassifier()]

for model in models:


model.fit(X_train, Y_train)

print(f'{model} : ')
print('Training Accuracy : ', metrics.roc_auc_score(
Y_train, model.predict_proba(X_train)[:, 1]))
print('Validation Accuracy : ', metrics.roc_auc_score(
Y_valid, model.predict_proba(X_valid)[:, 1]))
print()
else:
print("Error: Not enough classes in target variable.")
Conclusions

In conclusion, analyzing Tesla’s stock requires a comprehensive understanding of both internal


factors, such as product innovations, earnings reports, and leadership influence, and external
factors, like market competition and global economic conditions. Tesla's stock is known for its
volatility, with price movements driven by investor sentiment and news surrounding the company.
By using historical data, technical analysis, and market sentiment, investors and analysts can gain
insights into potential future trends, helping them make more informed decisions regarding Tesla's
stock performance.

You might also like