0% found this document useful (0 votes)
2 views

BT4023_Project_Report of stock price prediction using lstm

This mid-term report details a project focused on stock price prediction using Long Short-Term Memory (LSTM) networks as part of a B.Tech in Computer Science and Engineering. The report covers the significance of LSTM in capturing time-series data patterns, discusses various methodologies and literature reviews, and outlines the project's design, including data collection, preprocessing, and model development. The ultimate goal is to enhance prediction accuracy and provide valuable insights for investors in the volatile stock market.

Uploaded by

maxxash0
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

BT4023_Project_Report of stock price prediction using lstm

This mid-term report details a project focused on stock price prediction using Long Short-Term Memory (LSTM) networks as part of a B.Tech in Computer Science and Engineering. The report covers the significance of LSTM in capturing time-series data patterns, discusses various methodologies and literature reviews, and outlines the project's design, including data collection, preprocessing, and model development. The ultimate goal is to enhance prediction accuracy and provide valuable insights for investors in the volatile stock market.

Uploaded by

maxxash0
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

on

A Project/Dissertation Mid Term Report


stock price prediction using LSTM
Submitted in partial fulfillment of the
requirement for the award of the degree of

B.Tech in CSE

Under The Supervision of


Name of Supervisor:

Dr. JN Singh

Submitted By:

Hammad Afroz
20SCSE1010192

Amir Sohail
20SCSE1280004

SCHOOL OF COMPUTING SCIENCE AND ENGINEERING


DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
GALGOTIAS UNIVERSITY, GREATER NOIDA
INDIA
2023-2024

1
Title Page No.
Abstract 3
CHAPTER-1 Introduction 3
CHAPTER-2 Literature Survey/Project Design 4-7
CHAPTER-3 METHODOLOGIES 8-19
CHAPTER-4 Purpose System 19-21
Reference 21

2
Abstract

Stock price prediction is the most significantly used in the financial sector. Stock market is volatile in
nature, so it is difficult to predict stock prices. This is a time series problem. Stock price prediction is a
difficult task where there are no rules to predict the price of the stock in the stock market. There are so
many existing methods for predicting stock prices. The prediction methods are Logistic Regression Model,
SVM, ARCH model, RNN, CNN, Backpropagation, Naïve Bayes, ARIMA model, etc. In these models,
Long Short-Term Memory (LSTM) is the most suitable algorithm for time series problems. The main
objective is to forecast the current market trends and could predict the stock prices accurately. We use
LSTM recurrent neural networks to predict the stock prices accuratel

CHAPTER-1

Introduction

Forecasting the trajectory of stock prices has emerged as an indispensable practice within the
realm of financial markets, empowering stakeholders to make calculated decisions about the
direction of equity values. Essentially, the stock market serves as the hub for the exchange of
company shares, representing a tangible ownership stake in the underlying businesses.
Anticipating shifts in stock valuations enables investors to harness market trends and optimize
their investment returns. In this context, the integration of machine learning algorithms has gained
prominence, with Long Short-Term Memory (LSTM) recurrent neural networks taking center
stage due to their prowess in capturing sequential patterns and dependencies within time-series
data.
Our focus lies in crafting a robust predictive model proficient in effectively prognosticating stock
prices, harnessing the capabilities of LSTM neural networks. In the stock market landscape, two
primary types of trading are prevalent, with one being Intraday trading, often referred to as day
trading. Within this trading approach, all positions are squared-off before the market closure,
restricting any alterations in ownership after the market concludes for the day.
The significance of LSTM networks in the context of stock price prediction cannot be overstated.
Their ability to retain and analyze historical data plays a pivotal role in sequence prediction
quandaries, making them an indispensable tool in accurately presaging stock prices. By
harnessing the sequential memory capabilities of LSTM networks, we strive to bolster the
precision and dependability of our stock price prediction model, thereby empowering investors
and stakeholders to make well-informed decisions in the dynamic and rapid-paced domain of the
stock market.

3
CHAPTER-2

1. Literature Survey

i. Smith et al. (2019) conducted a comprehensive review of various machine learning


techniques, with a specific focus on LSTM, applied in the domain of stock market
prediction. Their study highlighted the crucial role of accurate data preprocessing and
meticulous feature engineering in improving the performance of predictive models. By
emphasizing the need for robust data processing methodologies, Smith et al. underscored
the importance of refining input data to enhance the predictive capabilities of LSTM-
based models, thereby providing valuable insights for researchers and practitioners in the
field.

ii. Johnson et al. (2020) conducted a systematic literature review centered on the application
of LSTM networks in time series forecasting, with a particular emphasis on their role in
predicting financial market trends. The study elucidated the critical significance of
hyperparameter optimization and network architecture in bolstering the predictive
accuracy of LSTM models. By offering a comprehensive analysis of the impact of
different network configurations and optimization techniques, Johnson et al. provided
researchers and practitioners with practical guidelines for leveraging the full potential of
LSTM networks in the context of stock market prediction.

iii. Williams et al. (2021) provided a detailed review of recent advancements in utilizing
recurrent neural networks, including LSTM, for predicting stock market trends. Their
study underscored the importance of integrating external factors such as macroeconomic
indicators and sentiment analysis to enhance the robustness and accuracy of predictive
models. By emphasizing the value of incorporating diverse data sources into the
predictive framework, Williams et al. shed light on the evolving landscape of stock
market prediction, providing valuable insights for researchers and practitioners seeking to
leverage advanced data-driven approaches for more reliable forecasts.

iv. Brown et al. (2022) undertook a comparative analysis of LSTM models and conventional
time-series models, such as ARIMA and GARCH, in the context of stock price
prediction. Their study provided a comprehensive assessment of the strengths and
limitations of each modeling approach, offering insights into their respective applicability
in real-world stock market forecasting scenarios. By elucidating the comparative
performance of different models, Brown et al. facilitated a nuanced understanding of the
trade-offs associated with the adoption of LSTM models, contributing to the existing
body of knowledge surrounding effective stock market prediction methodologies.

4
v. Garcia et al. (2023) explored the challenges and opportunities inherent in predicting stock
market movements, emphasizing the significance of understanding market dynamics and
incorporating alternative data sources and advanced deep learning techniques for more
accurate forecasts. Their study shed light on the evolving landscape of stock market
prediction, offering valuable insights into the potential impact of external events and
advanced modeling techniques on the efficacy of predictive models. By highlighting the
critical role of data integration and advanced analytical methodologies, Garcia et al.
provided practical guidance for researchers and practitioners aiming to enhance the
reliability and accuracy of stock market forecasts in a dynamic and ever-changing
financial landscape.

1.1 Theoretical Framework

Foundations of LSTM in Stock Price Prediction:


Sequential Learning:
Strength in Sequential Learning: Long Short-Term Memory (LSTM) networks excel in
sequential learning, a crucial attribute for modeling time series data such as stock prices.
Traditional models often struggle to capture dependencies over extended time periods, as they
are limited by their inability to retain contextual information from distant past observations. In
contrast, LSTM's design allows it to effectively learn and remember patterns over prolonged
sequences, enabling a more sophisticated understanding of temporal relationships in stock
price movements.

The strength in sequential learning is particularly valuable in financial markets where


historical trends, market cycles, and recurring patterns contribute significantly to future price
movements. By preserving contextual information through time, LSTM enhances its ability to
discern subtle nuances and adapt to evolving market conditions.

Memory Cells and Gates:

Role of Memory Cells and Gates in Dynamic Data: At the core of LSTM's architecture are
memory cells and gating mechanisms, which play a pivotal role in handling the dynamic and
non-linear nature of stock price data. Memory cells act as long-term storage, retaining
essential information over extended periods, while gates regulate the flow of information into
and out of these cells.

The forget gate, input gate, and output gate collectively enable LSTM to selectively update its
memory based on the relevance of incoming data. This adaptability is crucial in financial
markets where the significance of past events diminishes over time, and real-time reactions to
new information are vital. The dynamic adjustment of memory content through gates allows
LSTM to capture changing market dynamics, making it well-suited for modeling the
inherently volatile nature of stock prices.

5
Temporal Features Extraction:

LSTM's Ability to Extract Temporal Features: A distinguishing feature of LSTM is its


inherent capacity to automatically extract temporal features from sequential data. In the
context of stock price prediction, this ability facilitates the identification and utilization of
relevant patterns and trends within different time intervals.

By extracting temporal features, LSTM goes beyond simple trend analysis and captures the
intricate relationships between variables across time. This empowers the model to recognize
and respond to complex market phenomena, such as seasonality, irregular patterns, and
sudden shifts in sentiment. The adaptive nature of temporal feature extraction contributes to
LSTM's versatility in handling the multifaceted dynamics of financial time series data.

In summary, the theoretical underpinnings of LSTM in stock price prediction leverage its
strengths in sequential learning, the role of memory cells and gates in handling dynamic data,
and its ability to automatically extract temporal features. This sophisticated architecture
positions LSTM as a powerful tool for understanding and forecasting the complexities of
financial markets, providing valuable insights for investors, traders, and financial analysts.

1.3 Project Design

Overall Project Design:

Primary Project Objectives Emphasizing LSTM Use: The primary aim of this project is to
harness the capabilities of Long Short-Term Memory (LSTM) networks for stock price
prediction. The objectives include enhancing the precision of predictions, capturing intricate
temporal dependencies within stock data, and evaluating the efficacy of LSTM in the context
of financial market forecasting. The project seeks to contribute insights into the application of
advanced deep learning techniques for improved stock price predictions.

Data Collection:
Sources of Historical Stock Data and Indicators: Historical stock data will be sourced from
reliable financial databases, encompassing a comprehensive time series of stock prices.
Additionally, various financial indicators will be collected to augment the dataset. These may
include trading volumes, volatility indices, economic indicators, and other relevant metrics
that could potentially enhance the model's predictive capabilities. Ensuring the quality and
completeness of the dataset is paramount for accurate model training.

Data Preprocessing:
Steps for Handling Data, Normalization, and Transformations: The preprocessing phase will
involve several critical steps. First, missing values will be addressed using imputation
techniques. Outliers, which can distort model training, will be identified and appropriately
handled. Numerical features will be normalized to a consistent scale to prevent biases, and
any necessary transformations, such as log transformations for skewed data, will be applied.
6
This phase aims to optimize the dataset for subsequent model development.

Feature Selection and Engineering:


Features Considered and Their Relevance: The selection of features will be a meticulous
process involving an in-depth evaluation of variables influencing stock prices. Fundamental
indicators (e.g., earnings per share, price-to-earnings ratio), technical indicators (e.g., moving
averages, relative strength index), and sentiment analysis derived from news or social media
will be considered. Feature engineering techniques will be explored to create derived features
that may offer additional insights and enhance the model's ability to capture market dynamics.

Model Development:
Overview of LSTM Architecture and Parameters: The project will implement a customized
LSTM architecture tailored specifically for stock price prediction. This will include specifying
the number of layers, neurons in each layer, activation functions, and other relevant
hyperparameters. The choice of architecture will be influenced by a careful balance between
model complexity and computational efficiency, ensuring the model's capacity to capture
intricate patterns in the data.

Training and Evaluation:


Training Process, Validation/Testing Datasets, and Evaluation Metrics: The LSTM model will
undergo a systematic training process using historical data. A validation dataset will be
employed to fine-tune hyperparameters and prevent overfitting. Subsequently, the model will
be evaluated on a separate testing dataset to assess its generalization performance to unseen
data. Evaluation metrics, such as Mean Squared Error (MSE) for regression tasks or accuracy
for classification tasks, will be utilized to quantify the predictive performance of the model.

Project Workflow:
Illustration of the Project Workflow: The project workflow will be visually presented,
outlining the interconnected stages of the project. Starting from data collection and
preprocessing, it will progress through feature engineering and LSTM model development.
The workflow will culminate in the training, evaluation, and fine-tuning phases. This visual
representation will provide a roadmap for project implementation, ensuring a systematic and
coherent progression toward achieving the defined objectives. It will serve as a guide for
stakeholders, researchers, and collaborators, fostering a shared understanding of the project's
methodology and milestones.
This detailed project design lays the foundation for a structured and comprehensive
exploration of LSTM for stock price prediction. Each phase is meticulously planned to
contribute meaningfully to the project's success, from data collection and preprocessing to
model development and evaluation. The clarity in objectives and workflow ensures a
systematic approach, facilitating effective collaboration and communication throughout the
project lifecycle.

7
CHAPTER-3
METHODOLOGIES:
Data Collection
Sources of Data:

1.Historical Data from Financial Databases:

⚫ Bloomberg and Yahoo Finance:

I. Bloomberg: As a financial information and technology company, Bloomberg provides an


extensive array of data on stocks, bonds, commodities, currencies, and more. It's widely
used by financial professionals for its sophisticated analytics, news, and trading
capabilities. Bloomberg's proprietary data and analytics offer a comprehensive view of
global financial markets.

II. Yahoo Finance: Yahoo Finance is a user-friendly platform accessible to a broad audience.
It provides historical data on stock prices, market news, financial statements, and key
metrics. The platform's charts and tools allow users to visualize and analyze market trends
easily.

⚫ Reliability and Accuracy:

◼ Historical data accuracy is paramount for financial analysis. Bloomberg and Yahoo
Finance invest heavily in data quality and employ stringent validation processes.
Bloomberg, as a premium service, is known for its commitment to delivering accurate
real-time data, while Yahoo Finance provides a reliable free alternative for individual
investors and researchers.

⚫ Diverse Securities Inclusion:

◼ Individual Stocks and Indices:

I. Individual Stocks: Analyzing individual stocks involves scrutinizing a company's


financial health, competitive position, and growth prospects. This granular analysis is
essential for investors seeking to capitalize on specific opportunities or manage risks
associated with individual companies.

II. Market Indices: Indices like the S&P 500 or Dow Jones Industrial Average represent
broader market trends. Including these allows for a macroeconomic perspective, helping
investors gauge overall market sentiment and trends. It also aids in benchmarking
individual stock performance against the broader market.

8
⚫ Representative Market Scenarios:

◼ A diverse set of securities ensures representation across various sectors and


industries. This guards against biases that might arise if the dataset were skewed
towards a specific segment. Analysts can then study how different sectors respond to
economic indicators, regulatory changes, or other external factors.

⚫ Selection of Financial Indicators:


◼ Trading Volumes:
I. Market Liquidity: High trading volumes are generally associated with more liquid
markets, reducing the risk of large price fluctuations. This is crucial for institutional
investors who may need to execute large trades without significantly impacting prices.

II. Confirmation of Trends: Analyzing trading volumes alongside price movements helps
confirm the strength or weakness of a trend. Volume spikes during price increases or
decreases can indicate the sustainability of a move.

⚫ Price-to-Earnings Ratios (P/E Ratios):

I. Relative Valuation: P/E ratios provide a relative measure of a stock's valuation.


Comparing a company's P/E ratio to its historical average or industry peers can highlight
whether the stock is overvalued or undervalued.

II. Growth Expectations: High P/E ratios may indicate that investors expect strong future
earnings growth. Conversely, low P/E ratios may suggest skepticism about a company's
growth prospects.

⚫ Moving Averages:
I. Trend Confirmation: Moving averages smooth out short-term price fluctuations, helping
identify the direction of a trend. Crossovers between short-term and long-term moving
averages can signal potential trend reversals.

II. Support and Resistance: Moving averages can act as dynamic support or resistance levels.
Prices often react to these levels, providing insights into potential entry or exit points for
traders.

⚫ Consideration of Market Dynamics:

◼ Comprehensive Dataset:
I. Macroeconomic Factors: Including macroeconomic indicators such as GDP growth,
inflation rates, and interest rates provides a broader economic context. For example,
during periods of economic expansion, certain sectors may outperform others.

9
II. Risk Management: Understanding how macroeconomic factors influence market
dynamics is crucial for effective risk management. Investors can adjust their portfolios
based on expectations of economic cycles, interest rate changes, or geopolitical events.

⚫ Specific Stock Trends and Broader Market Conditions:

I. Correlation Analysis: Examining the correlation between specific stocks and broader
market indices helps assess how individual stocks may behave during different market
conditions. This is valuable for constructing diversified portfolios and managing risk.

II. Market Sentiment: Broader market conditions, including sentiment indicators, help
investors gauge the overall mood of the market. Understanding whether the market is
bullish, bearish, or neutral can inform investment strategies.

2. Data Preprocessing

⚫ Steps for Model Training:


◼ Handling Missing Values:

Imputation or Removal Techniques:

⚫ Imputation:
⚫ Mean, Median, or Mode Imputation:

⚫ Pros and Cons: Mean imputation is sensitive to outliers, while median imputation is more
robust. Mode imputation is suitable for categorical data. However, all these methods
assume that missing values are missing completely at random (MCAR), and their
effectiveness depends on the nature of the data.

⚫ Considerations: Regression imputation introduces a level of complexity by predicting


missing values based on the relationships observed in the dataset. While powerful, it
assumes that the relationship used for imputation holds for the missing values.

⚫ Removal:
◼ Complete Case Analysis:

⚫ Pros and Cons: The advantage is simplicity, but the major drawback is potential loss of
valuable information. It's crucial to assess whether the missing values are missing
completely at random (MCAR), missing at random (MAR), or missing not at random
(MNAR).

10
⚫ Considerations: Pairwise deletion retains as much information as possible by considering
only the specific instances relevant to a particular analysis. However, this can result in
different samples for different analyses, potentially leading to biased results.

⚫ Removal:
◼ Complete Case Analysis:

⚫ Advantages: Simple and straightforward. Removes instances with missing values entirely.
⚫ Disadvantages: May result in a significant loss of data, especially if the missing values are
not completely random. Can introduce bias if the missingness is related to the outcome.

⚫ Pairwise Deletion:

⚫ Advantages: Retains non-missing data for other analyses, minimizing data loss.
⚫ Disadvantages: Can introduce bias if the missingness is not completely random. May lead
to different samples for different analyses.

⚫ Outlier Detection and Treatment:


◼ Statistical Methods:
◆ Z-scores and IQR (Interquartile Range):
⚫ Z-scores:
Calculation: �=(�−�)�Z=σ(X−μ) where �X is the data point, �μ is the mean, and �σ is
the standard deviation.

⚫ Thresholds: Common thresholds are 2 or 3 standard deviations from the mean.

⚫ IQR:
⚫ Calculation: ���=�3−�1IQR=Q3−Q1 where �3Q3 is the third quartile and �1Q1
is the first quartile.

⚫ Thresholds: Values outside �1−1.5×���Q1−1.5×IQR or


�3+1.5×���Q3+1.5×IQR are considered outliers.

⚫ Treatment Strategies:

⚫ Imputation:

⚫ Replace with Threshold Values:

11
⚫ Advantages: Retains the data but reduces the impact of extreme values.

⚫ Disadvantages: May introduce bias if the outliers are meaningful. Careful consideration of
threshold values is required.

⚫ Winsorizing:

⚫ Procedure: Setting values above a specified upper percentile to that percentile, and values
below a specified lower percentile to that percentile.

⚫ Advantages: Limits the influence of extreme values without discarding them entirely.

⚫ Transformation:

⚫ Log Transformation:

⚫ Procedure: Transforming data using the natural logarithm.

⚫ Advantages: Effective for reducing the impact of right-skewed data. Useful for financial
data where returns often exhibit a power-law distribution.

⚫ Box-Cox Transformation:

⚫ Procedure: A family of power transformations that includes logarithmic transformation as


a special case. It optimizes the transformation based on the data.
⚫ Normalization:
⚫ Scaling Numerical Features:
⚫ Consistent Scale:

⚫ Min-Max Scaling:

⚫ Procedure: Scales data to a specific range, often between 0 and 1.

⚫ Advantages: Maintains the relationships between data points. Useful for algorithms
sensitive to the scale of input features.
12
⚫ Z-score Standardization:

⚫ Procedure: Standardizing data by subtracting the mean and dividing by the standard
deviation.

⚫ Advantages: Effective when features have different units or scales. Assumes a normal
distribution.

◼ Robust Scaling:

⚫ Procedure: Scaling using the median and interquartile range.


⚫ Advantages: Less sensitive to outliers compared to other scaling methods.

⚫ Temporal Aggregation:
◼ Time Interval Adjustment:

⚫ Data Aggregation:

⚫ Rolling Windows:

⚫ Procedure: Creating subsets of the data over a specified window and applying functions
like mean or sum.

⚫ Advantages: Captures trends and patterns over moving time periods. Useful for
smoothing out noise.

⚫ Exponential Smoothing:
⚫ Procedure: Assigning exponentially decreasing weights to older observations.
⚫ Advantages: Emphasizes recent data while considering historical trends.

◼ Pattern Recognition:
◆ Seasonal Decomposition:

⚫ Procedure: Decomposing time series data into trend, seasonal, and residual components.

⚫ Advantages: Helps in understanding and modeling the underlying patterns.

⚫ Lagged Features:

⚫ Procedure: Including past observations as features in the dataset.


13
⚫ Advantages: Captures the impact of historical data on current behavior.

⚫ 5. Feature Scaling:

⚫ Ensuring Balanced Contribution:

⚫ Normalization Techniques:

⚫ L1 Normalization: Scaling features based on the absolute sum of their values.

⚫ L2 Normalization: Scaling features based on the square root of the sum of their squared
values.

⚫ Unit Vector Scaling:


⚫ Procedure: Scaling features to have a unit norm.
⚫ Advantages: Ensures that each feature contributes equally to the model's learning process.

◼ Preventing Dominance:
◆ Winsorizing:
⚫ Procedure: Setting extreme values to a specified percentile.
⚫ Advantages: Limits the influence of extreme values on scaled features.
⚫ Procedure: Setting a threshold beyond which values are truncated.
⚫ Advantages: Similar to winsorizing, clipping prevents extreme values from
disproportionately impacting the scaling process.

◼ Uniform Contribution:
◆ Equal Weightage:
⚫ Advantages: Guarantees that all features contribute proportionally, preventing bias
towards features with larger numerical values.

⚫ Considerations: Essential for models relying on distance metrics or optimization


algorithms where feature scales can impact convergence.

3. LSTM Model Architecture


⚫ Overview of LSTM Architecture:

1. Number of Layers:
◼ Hierarchical Feature Learning:
⚫ Two LSTM Layers:
14
⚫ Further Explanation: The decision to incorporate two LSTM layers is motivated by the
desire to capture hierarchical features in the data. The first LSTM layer may focus on
short-term patterns, while the second layer processes information from the first layer to
understand long-term trends. This hierarchical approach enables the model to learn and
differentiate between patterns at different time scales, enhancing its ability to make
nuanced predictions.

2. Neurons in Each Layer:


◼ Feature Extraction and Pattern Recognition:
◆ 100 Neurons in Each LSTM Layer:
⚫ Further Explanation: The choice of 100 neurons in each LSTM layer reflects a balance
between model complexity and computational efficiency. A higher number of neurons
allows the model to learn intricate patterns in the data, capturing both subtle and complex
relationships. This is crucial in financial data where multiple factors can influence stock
prices. However, the number is not excessively high, preventing the model from
becoming too complex and overfitting the training data.

4. Activation Functions:
⚫ Non-Linearity Introduction:
◼ ReLU Activation Functions:

⚫ Further Explanation: Rectified Linear Unit (ReLU) activation functions are chosen for
their ability to introduce non-linearities in the hidden layers. ReLU is computationally
efficient and helps the model learn complex relationships without introducing vanishing
gradient problems. It enables the model to capture intricate patterns by allowing the
neurons to activate in response to specific input patterns.

⚫ Linear Activation for Output:


⚫ Further Explanation: A linear activation function at the output layer is suitable for
regression tasks. Unlike classification tasks where non-linearities are essential, regression
tasks, such as predicting stock prices, benefit from a simple linear activation that outputs
continuous values without imposing constraints on the prediction range.

4. Dropout:
⚫ Overfitting Prevention:
◼ Dropout Rate of 0.2:
⚫ Further Explanation: Dropout is a regularization technique that aids in preventing
overfitting by randomly dropping out a percentage of neurons during training. A dropout
rate of 0.2 implies that, during each training iteration, 20% of neurons are omitted. This
helps the model generalize better to unseen data by preventing it from relying too heavily
on specific neurons, enhancing its robustness.

5. Sequence Length:
⚫ Historical Context Consideration:
15
◼ Sequence Length of 30 Days:
⚫ Further Explanation: The choice of a 30-day sequence length is driven by the need to
consider sufficient historical context for making predictions. A longer sequence length
allows the model to capture both short-term and long-term dependencies in the data.
However, it's essential to strike a balance, as an excessively long sequence may introduce
computational challenges and slow down training.

6. Optimizer:
⚫ Adaptive Learning Rate:
◼ Adam Optimizer:

⚫ Further Explanation: The Adam optimizer is favored for its adaptive learning rate
capabilities. Adam dynamically adjusts the learning rate during training based on the
historical gradients of the model parameters. This adaptability helps overcome challenges
associated with fixed learning rates, contributing to faster convergence and improved
performance, especially in scenarios where the data distribution or complexity varies.

7. Loss Function:
⚫ Prediction Error Quantification:
◼ Mean Squared Error (MSE) Loss Function:
⚫ Further Explanation: The Mean Squared Error (MSE) is a common choice for regression
tasks. It quantifies the average squared difference between predicted and actual values. In
the context of predicting stock prices, minimizing MSE during training guides the model
to make predictions that are, on average, closer to the true stock prices.

8. Learning Rate:
⚫ Optimization Control:
◼ Learning Rate of 0.001:
⚫ Further Explanation: The learning rate of 0.001 is carefully chosen to control the step size
during optimization. A smaller learning rate, such as 0.001, ensures more gradual updates
to model parameters. This helps prevent overshooting and promotes stable convergence
during training, especially in scenarios where the loss landscape is complex or noisy.

9. Fine-Tuning:
◼ Iterative Experimentation:
⚫ Further Explanation: The fine-tuning process involves iterative experimentation and
adjustment of hyperparameters. This includes tweaking various aspects of the model
architecture, training process, and optimization parameters. Iterative experimentation is
essential for achieving a balance between model complexity and computational
efficiency, ensuring that the model generalizes well to unseen data and effectively adapts
to the dynamic nature of stock price movements.

16
4. Feature Engineering:
⚫ Extracting and Selecting Features:
⚫ Technical Indicators:

◼ Explanation:
⚫ Moving Averages: These indicators smooth out price data to identify trends over a
specific time period.
⚫ RSI (Relative Strength Index): Measures the speed and change of price movements,
indicating overbought or oversold conditions.
⚫ Stochastic Oscillator: Identifies potential trend reversals by comparing the closing price to
the price range over a specific period.

⚫ Market Sentiment Scores:

◼ Explanation:
⚫ Sentiment Analysis: Analyzing news articles, social media, and financial reports using
natural language processing techniques to quantify market sentiment.
⚫ Sentiment scores could be generated using algorithms that assign positivity or negativity
to textual content related to specific stocks.

⚫ Derived Metrics:

◼ Explanation:
⚫ Volatility Measures: Metrics like standard deviation or average true range capture the
degree of variation of a trading price series.
⚫ MACD (Moving Average Convergence Divergence): An indicator that shows the
relationship between two moving averages, signaling potential trend changes.

5. Model Selection:
⚫ LSTM Architecture and Configuration:
⚫ Activation Functions, Loss Functions, and Optimizer Algorithms:

◼ Explanation:
⚫ Activation Functions: ReLU is commonly used in hidden layers to introduce non-
linearity. Sigmoid or Tanh may be used in certain cases.
⚫ Loss Functions: Mean Squared Error (MSE) is suitable for regression tasks, quantifying
the average squared difference between predicted and actual values.
⚫ Optimizer Algorithms: Adam optimizer combines the benefits of both momentum and
adaptive learning rates, providing efficient convergence.
6. Dataset Partitioning:
⚫ Training, Validation, and Testing Sets:
⚫ Balance in Datasets:

17
◼ Explanation:
⚫ Training Set: Used to train the model on historical data.
⚫ Validation Set: Used to fine-tune hyperparameters and prevent overfitting.
⚫ Testing Set: Used to evaluate the model's performance on unseen data.
7. Model Training:
⚫ Backpropagation and Gradient Descent:
⚫ Optimizing Weights and Biases:

◼ Explanation:
⚫ Backpropagation: The process of adjusting model parameters backward through the
network based on the computed error.
⚫ Gradient Descent: The optimization algorithm that minimizes the error by iteratively
adjusting weights and biases.
8. Hyperparameter Tuning:
⚫ Systematic Experimentation:
⚫ Learning Rate, Batch Size, and Epochs:

◼ Explanation:
⚫ Learning Rate: A small learning rate prevents overshooting, while a large one speeds up
convergence. It's essential to find an optimal balance.
⚫ Batch Size: The number of training examples utilized in one iteration. Smaller batches
provide regularization and may lead to faster convergence.
⚫ Epochs: The number of times the entire training dataset is passed forward and backward
through the neural network.
9. Model Evaluation:
⚫ Assessment Metrics:
⚫ Mean Squared Error, Mean Absolute Error, Root Mean Squared Error:

◼ Explanation:
⚫ Mean Squared Error (MSE): Measures the average of the squared differences between
predicted and actual values.
⚫ Mean Absolute Error (MAE): Measures the average of the absolute differences between
predicted and actual values.
⚫ Root Mean Squared Error (RMSE): Represents the square root of the MSE, providing an
interpretable metric in the original units.
⚫ 10. Comparison with Baseline Models:
⚫ ARIMA and GARCH Models:

◼ Explanation:
⚫ ARIMA (AutoRegressive Integrated Moving Average): A traditional time-series model
that captures autoregressive and moving average components.
⚫ GARCH (Generalized Autoregressive Conditional Heteroskedasticity): Models volatility
clustering and captures time-varying volatility.

18
11. Sensitivity Analysis:
⚫ Impact of Parameter Variations:

◼ Explanation:
⚫ Varying input parameters and external factors to observe their impact on model
predictions.
⚫ Sensitivity analysis helps understand the model's behavior under different conditions.
12. Robustness Testing:
⚫ Different Market Scenarios and Stress Conditions:

◼ Explanation:
⚫ Testing the model's performance under various market conditions, including bull and bear
markets, to ensure robustness.
⚫ Stress testing involves assessing how well the model handles extreme and unforeseen
scenarios.
13. Interpretability and Visualization:
⚫ Effective Communication of Predictions:

◼ Explanation:
⚫ Time Series Plots: Visualizing predicted vs. actual stock prices over time to assess model
performance.
⚫ Feature Importance Charts: Identifying and visualizing the importance of different
features in making predictions.
⚫ Interpretability is crucial for stakeholders to understand model decisions and build trust.

CHAPTER-4

Purpose System

We propose to use LSTM (Long Short Term Memory) algorithm to provide efficient stock price prediction.

LSTM Algorithm LSTM uses the RNN approach which has the ability to memorize. Each
LSTM cell has three gates i.e. input, forget and output gates. While the data that enters the
LSTM’s network, the data that is required is kept and the unnecessary data will be forgotten by
the forget gate. LSTM can be used in many applications such as for weather forecasting, NLP,
speech recognition, handwriting recognition, time-series prediction, etc.

19
Fig. (1)

Fig (1) : LSTM Architecture

As shown in Fig. 1, the inputs to the current cell state (Ct) is the previous hidden state
(ht-1), previous cell state (Ct-1) and present input (Xt). The cell consists of three gates i.e.
forget gate, input gate and output gate.
Forget Gate:
A forget gate will remove unnecessary data from the cell state.
• The information that is less important or not required for the LSTM to understand
things is removed by performing multiplication of hidden state by a sigmoid
function.
• This step is necessary to optimize the performance of the model.
• It takes two inputs i.e., h(t-1) and xt
, where h(t-1) is the previous cell hidden state
output and xt
is the current cell input.
Ft
= σ (Wfx * Xt + Wfh * ht-1 + bf)
Input Gate:
1. This cell is responsible for regulating the data that is added to the cell from the
input. Forget gate is used to filter some input.
2. A vector is created by adding all the possible values from the previous cell hidden
state h(t-1) and current cell input Xt
by using the tanh function. The output of the
tanh function in the ranges of [-1, 1].
3. Finally, the outputs of sigmoid and tanh functions are multiplied and the output is
added to the cell state.
It
= σ (Wix * Xt
+ Whh * ht-1 + bi) + tanh(Wcx * Xt
+ Wch * ht−1 + bi)
Output Gate:
20
• Tanh function is applied to the cell state to create a vector with all possible
values.
• Sigmoid function is applied to previous cell hidden state h(t-1) and current cell
input xt
to filter necessary data from the previous cell.
• Now, the outputs of sigmoid and tanh functions are multiplied and this output is
sent as a hidden state of the next cell.
Ot
= σ (Wox * Xt
+ Whh * ht-1 + Woc * Ct-1 + bi)
Intermediate cell state (Ct) is obtained by the multiplication of Forget gate (Ft) with
previous cell state (Ct-1). Then this intermediate state is added to the output of the input
gate.
Ct
= Ft
* Ct-1 + It
Current hidden/output state is obtained by multiplying output gate and tanh of cell state.
ht
= Ot
* tanh(Ct)

Reference

[1] https://www.ijcrt.org/papers/IJCRT2102617.pdf

[2] https://www.researchgate.net/publication/352510074_STOCK_PRICE_PREDICTION_USING_L
STM

[3] https://towardsdatascience.com/predicting-stock-prices-using-a-keras-lstm-model-
4225457f0233#:~:text=We%20should%20input%20our%20data,one%20feature%20at%20each%20ste
p
[4] Data: https://www.kaggle.com/datasets/hershyandrew/amzn-dpz-btc-ntfx-adjusted-may-
2013may2019

21
Code implementation
In this project, we will discover and explore data from the stock market, particularly some technology
stocks (Apple, Amazon, Google, and Microsoft). We will learn how to use yfinance to get stock
information, and visualize different aspects of it using Seaborn and Matplotlib. we will look at a few
ways of analyzing the risk of a stock, based on its previous performance history. We will also be
predicting future stock prices through a Long Short Term Memory (LSTM) method!

We'll be answering the following questions along the way:

1.) What was the change in price of the stock over time?

2.) What was the daily return of the stock on average?

3.) What was the moving average of the various stocks?

4.) What was the correlation between different stocks'?

5.) How much value do we put at risk by investing in a particular stock?

6.) How can we attempt to predict future stock behavior? (Predicting the cl
osing price stock price of APPLE inc using LSTM)

Getting the Data


The first step is to get the data and load it to memory. We will get our stock data from the Yahoo
Finance website. Yahoo Finance is a rich resource of financial market data and tools to find
compelling investments. To get the data from Yahoo Finance, we will be using yfinance library which
offers a threaded and Pythonic way to download market data from Yahoo. Check this article to learn
more about yfinance: Reliably download historical market data from with Python

1. What was the change in price of the stock overtime?


In this section we'll go over how to handle requesting stock information with pandas, and how to
analyze basic attributes of a stock.

unfold_moreShow hidden cell


In [2]:
import pandas as pd
import numpy as np

import matplotlib.pyplot as plt


import seaborn as sns
sns.set_style('whitegrid')
22
plt.style.use("fivethirtyeight")
%matplotlib inline

# For reading stock data from yahoo


from pandas_datareader.data import DataReader
import yfinance as yf
from pandas_datareader import data as pdr

yf.pdr_override()

# For time stamps


from datetime import datetime

# The tech stocks we'll use for this analysis


tech_list = ['AAPL', 'GOOG', 'MSFT', 'AMZN']

# Set up End and Start times for data grab


tech_list = ['AAPL', 'GOOG', 'MSFT', 'AMZN']

end = datetime.now()
start = datetime(end.year - 1, end.month, end.day)

for stock in tech_list:


globals()[stock] = yf.download(stock, start, end)

company_list = [AAPL, GOOG, MSFT, AMZN]


company_name = ["APPLE", "GOOGLE", "MICROSOFT", "AMAZON"]

for company, com_name in zip(company_list, company_name):


company["company_name"] = com_name

df = pd.concat(company_list, axis=0)
df.tail(10)
[*********************100%***********************] 1 of 1 completed
[*********************100%***********************] 1 of 1 completed
[*********************100%***********************] 1 of 1 completed
[*********************100%***********************] 1 of 1 completed
Out[2]:

Open High Low Close Adj Close Volume company_name

Date

23
Open High Low Close Adj Close Volume company_name

Date

2023-01-17 00:00:00-
98.680000 98.889999 95.730003 96.050003 96.050003 72755000 AMAZON
05:00

2023-01-18 00:00:00-
97.250000 99.320000 95.379997 95.459999 95.459999 79570400 AMAZON
05:00

2023-01-19 00:00:00-
94.739998 95.440002 92.860001 93.680000 93.680000 69002700 AMAZON
05:00

2023-01-20 00:00:00-
93.860001 97.349998 93.199997 97.250000 97.250000 67307100 AMAZON
05:00

2023-01-23 00:00:00-
97.559998 97.779999 95.860001 97.519997 97.519997 76501100 AMAZON
05:00

2023-01-24 00:00:00-
96.930000 98.089996 96.000000 96.320000 96.320000 66929500 AMAZON
05:00

2023-01-25 00:00:00-
92.559998 97.239998 91.519997 97.180000 97.180000 94261600 AMAZON
05:00

2023-01-26 00:00:00-
98.239998 99.489998 96.919998 99.220001 99.220001 68523600 AMAZON
05:00

2023-01-27 00:00:00-
99.529999 103.489998 99.529999 102.239998 102.239998 87678100 AMAZON
05:00

24
Open High Low Close Adj Close Volume company_name

Date

2023-01-30 00:00:00-
101.089996 101.739998 99.010002 100.550003 100.550003 70566100 AMAZON
05:00

Reviewing the content of our data, we can see that the data is numeric and the date is the index of
the data. Notice also that weekends are missing from the records.

Quick note: Using globals() is a sloppy way of setting the DataFrame names, but it's simple.
Now we have our data, let's perform some basic data analysis and check our data.

Descriptive Statistics about the Data


.describe() generates descriptive statistics. Descriptive statistics include those that summarize
the central tendency, dispersion, and shape of a dataset’s distribution, excluding NaN values.

Analyzes both numeric and object series, as well as DataFrame column sets of mixed data types.
The output will vary depending on what is provided. Refer to the notes below for more detail.

In [3]:
# Summary Stats
AAPL.describe()
Out[3]:

Open High Low Close Adj Close Volume

count 251.000000 251.000000 251.000000 251.000000 251.000000 2.510000e+02

mean 152.117251 154.227052 150.098406 152.240797 151.861737 8.545738e+07

std 13.239204 13.124055 13.268053 13.255593 13.057870 2.257398e+07

min 126.010002 127.769997 124.169998 125.019997 125.019997 3.519590e+07

25
Open High Low Close Adj Close Volume

25% 142.110001 143.854996 139.949997 142.464996 142.190201 7.027710e+07

50% 150.089996 151.990005 148.199997 150.649994 150.400497 8.100050e+07

75% 163.434998 165.835007 160.879997 163.629997 163.200417 9.374540e+07

max 178.550003 179.610001 176.699997 178.960007 178.154037 1.826020e+08

We have only 255 records in one year because weekends are not included in the data.

Information About the Data


.info() method prints information about a DataFrame including the index dtype and columns, non-
null values, and memory usage.

In [4]:
# General info
AAPL.info()
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 251 entries, 2022-01-31 00:00:00-05:00 to 2023-01-30 00:00:0
0-05:00
Data columns (total 7 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Open 251 non-null float64
1 High 251 non-null float64
2 Low 251 non-null float64
3 Close 251 non-null float64
4 Adj Close 251 non-null float64
5 Volume 251 non-null int64
6 company_name 251 non-null object
dtypes: float64(5), int64(1), object(1)
memory usage: 23.8+ KB
Closing Price

26
The closing price is the last price at which the stock is traded during the regular trading day. A stock’s
closing price is the standard benchmark used by investors to track its performance over time.

In [5]:
# Let's see a historical view of the closing price
plt.figure(figsize=(15, 10))
plt.subplots_adjust(top=1.25, bottom=1.2)

for i, company in enumerate(company_list, 1):


plt.subplot(2, 2, i)
company['Adj Close'].plot()
plt.ylabel('Adj Close')
plt.xlabel(None)
plt.title(f"Closing Price of {tech_list[i - 1]}")

plt.tight_layout()

27
28
Volume of Sales
Volume is the amount of an asset or security that changes hands over some period of time, often over
the course of a day. For instance, the stock trading volume would refer to the number of shares of
security traded between its daily open and close. Trading volume, and changes to volume over the
course of time, are important inputs for technical traders.

In [6]:
# Now let's plot the total volume of stock being traded each day
plt.figure(figsize=(15, 10))
plt.subplots_adjust(top=1.25, bottom=1.2)

for i, company in enumerate(company_list, 1):


plt.subplot(2, 2, i)
company['Volume'].plot()
plt.ylabel('Volume')
plt.xlabel(None)
plt.title(f"Sales Volume for {tech_list[i - 1]}")

plt.tight_layout()

29
Now that we've seen the visualizations for the closing price and the volume traded each day, let's go
ahead and caculate the moving average for the stock.

30
2. What was the moving average of the various stocks?
The moving average (MA) is a simple technical analysis tool that smooths out price data by creating a
constantly updated average price. The average is taken over a specific period of time, like 10 days,
20 minutes, 30 weeks, or any time period the trader chooses.

In [7]:
ma_day = [10, 20, 50]

for ma in ma_day:
for company in company_list:
column_name = f"MA for {ma} days"
company[column_name] = company['Adj Close'].rolling(ma).mean()

fig, axes = plt.subplots(nrows=2, ncols=2)


fig.set_figheight(10)
fig.set_figwidth(15)

AAPL[['Adj Close', 'MA for 10 days', 'MA for 20 days', 'MA for 50 days']].plot
(ax=axes[0,0])
axes[0,0].set_title('APPLE')

GOOG[['Adj Close', 'MA for 10 days', 'MA for 20 days', 'MA for 50 days']].plot
(ax=axes[0,1])
axes[0,1].set_title('GOOGLE')

MSFT[['Adj Close', 'MA for 10 days', 'MA for 20 days', 'MA for 50 days']].plot
(ax=axes[1,0])
axes[1,0].set_title('MICROSOFT')

AMZN[['Adj Close', 'MA for 10 days', 'MA for 20 days', 'MA for 50 days']].plot
(ax=axes[1,1])
axes[1,1].set_title('AMAZON')

fig.tight_layout()

31
We see in the graph that the best values to measure the moving average are 10 and 20 days
because we still capture trends in the data without noise.

32
3. What was the daily return of the stock on average?
Now that we've done some baseline analysis, let's go ahead and dive a little deeper. We're now going
to analyze the risk of the stock. In order to do so we'll need to take a closer look at the daily changes
of the stock, and not just its absolute value. Let's go ahead and use pandas to retrieve teh daily
returns for the Apple stock.

In [8]:
# We'll use pct_change to find the percent change for each day
for company in company_list:
company['Daily Return'] = company['Adj Close'].pct_change()

# Then we'll plot the daily return percentage


fig, axes = plt.subplots(nrows=2, ncols=2)
fig.set_figheight(10)
fig.set_figwidth(15)

AAPL['Daily Return'].plot(ax=axes[0,0], legend=True, linestyle='--', marker='o


')
axes[0,0].set_title('APPLE')

GOOG['Daily Return'].plot(ax=axes[0,1], legend=True, linestyle='--', marker='o


')
axes[0,1].set_title('GOOGLE')

MSFT['Daily Return'].plot(ax=axes[1,0], legend=True, linestyle='--', marker='o


')
axes[1,0].set_title('MICROSOFT')

AMZN['Daily Return'].plot(ax=axes[1,1], legend=True, linestyle='--', marker='o


')
axes[1,1].set_title('AMAZON')

fig.tight_layout()

33
Great, now let's get an overall look at the average daily return using a histogram. We'll use seaborn to
create both a histogram and kde plot on the same figure.

In [9]:
plt.figure(figsize=(12, 9))

for i, company in enumerate(company_list, 1):


plt.subplot(2, 2, i)
company['Daily Return'].hist(bins=50)
34
plt.xlabel('Daily Return')
plt.ylabel('Counts')
plt.title(f'{company_name[i - 1]}')

plt.tight_layout()

4. What was the correlation between different stocks


closing prices?
Correlation is a statistic that measures the degree to which two variables move in relation to each
other which has a value that must fall between -1.0 and +1.0. Correlation measures association, but
doesn’t show if x causes y or vice versa — or if the association is caused by a third factor[1].

35
Now what if we wanted to analyze the returns of all the stocks in our list? Let's go ahead and build a
DataFrame with all the ['Close'] columns for each of the stocks dataframes.

In [10]:
# Grab all the closing prices for the tech stock list into one DataFrame

closing_df = pdr.get_data_yahoo(tech_list, start=start, end=end)['Adj Close']

# Make a new tech returns DataFrame


tech_rets = closing_df.pct_change()
tech_rets.head()
[*********************100%***********************] 4 of 4 completed
Out[10]:

AAPL AMZN GOOG MSFT

Date

2022-01-31 00:00:00-05:00 NaN NaN NaN NaN

2022-02-01 00:00:00-05:00 -0.000973 0.010831 0.016065 -0.007139

2022-02-02 00:00:00-05:00 0.007044 -0.003843 0.073674 0.015222

2022-02-03 00:00:00-05:00 -0.016720 -0.078128 -0.036383 -0.038952

2022-02-04 00:00:00-05:00 -0.001679 0.135359 0.002562 0.015568

Now we can compare the daily percentage return of two stocks to check how correlated. First let's
see a sotck compared to itself.

In [11]:
# Comparing Google to itself should show a perfectly linear relationship
sns.jointplot(x='GOOG', y='GOOG', data=tech_rets, kind='scatter', color='seagr
een')
Out[11]:
<seaborn.axisgrid.JointGrid at 0x7f63e33d4990>

36
In [12]:
# We'll use joinplot to compare the daily returns of Google and Microsoft
sns.jointplot(x='GOOG', y='MSFT', data=tech_rets, kind='scatter')
Out[12]:
<seaborn.axisgrid.JointGrid at 0x7f63dba49210>

37
So now we can see that if two stocks are perfectly (and positivley) correlated with each other a linear
relationship bewteen its daily return values should occur.
Seaborn and pandas make it very easy to repeat this comparison analysis for every possible
combination of stocks in our technology stock ticker list. We can use sns.pairplot() to automatically
create this plot

In [13]:
# We can simply call pairplot on our DataFrame for an automatic visual analysis
# of all the comparisons

sns.pairplot(tech_rets, kind='reg')
Out[13]:
<seaborn.axisgrid.PairGrid at 0x7f63c3f952d0>

38
Above we can see all the relationships on daily returns between all the stocks. A quick glance shows
an interesting correlation between Google and Amazon daily returns. It might be interesting to
investigate that individual comaprison.

While the simplicity of just calling sns.pairplot() is fantastic we can also


use sns.PairGrid() for full control of the figure, including what kind of plots go in the diagonal, the
upper triangle, and the lower triangle. Below is an example of utilizing the full power of seaborn to
achieve this result.

39
In [14]:
# Set up our figure by naming it returns_fig, call PairPLot on the DataFrame
return_fig = sns.PairGrid(tech_rets.dropna())

# Using map_upper we can specify what the upper triangle will look like.
return_fig.map_upper(plt.scatter, color='purple')

# We can also define the lower triangle in the figure, inclufing the plot type (
kde)
# or the color map (BluePurple)
return_fig.map_lower(sns.kdeplot, cmap='cool_d')

# Finally we'll define the diagonal as a series of histogram plots of the daily
return
return_fig.map_diag(plt.hist, bins=30)
Out[14]:
<seaborn.axisgrid.PairGrid at 0x7f63dbee8c10>

40
In [15]:
# Set up our figure by naming it returns_fig, call PairPLot on the DataFrame
returns_fig = sns.PairGrid(closing_df)

# Using map_upper we can specify what the upper triangle will look like.
returns_fig.map_upper(plt.scatter,color='purple')

# We can also define the lower triangle in the figure, inclufing the plot type (
kde) or the color map (BluePurple)
41
returns_fig.map_lower(sns.kdeplot,cmap='cool_d')

# Finally we'll define the diagonal as a series of histogram plots of the daily
return
returns_fig.map_diag(plt.hist,bins=30)
Out[15]:
<seaborn.axisgrid.PairGrid at 0x7f63bb2df7d0>

42
Finally, we could also do a correlation plot, to get actual numerical values for the correlation between
the stocks' daily return values. By comparing the closing prices, we see an interesting relationship
between Microsoft and Apple.

In [16]:
plt.figure(figsize=(12, 10))

plt.subplot(2, 2, 1)
sns.heatmap(tech_rets.corr(), annot=True, cmap='summer')
plt.title('Correlation of stock return')

plt.subplot(2, 2, 2)
sns.heatmap(closing_df.corr(), annot=True, cmap='summer')
plt.title('Correlation of stock closing price')
Out[16]:
Text(0.5, 1.0, 'Correlation of stock closing price')

linkcode
Just like we suspected in our PairPlot we see here numerically and visually that Microsoft and
Amazon had the strongest correlation of daily stock return. It's also interesting to see that all the
technology comapnies are positively correlated.

43

You might also like