Professional Documents
Culture Documents
Maths in Stock Market Ashar Ghawte 4
Maths in Stock Market Ashar Ghawte 4
of
Submitted by
Department of Mathematics
B. K. Birla College of Arts, Science and Commerce
(Autonomous), Kalyan
1
Project on
Presented By
For
Affiliated to
University of Mumbai
2
CERTIFICATE
………………………………………………………………………………….,
3
CERTIFICATE
with Roll No. ……………… of the Final year M. Sc. (Applied Mathematics) has
……………………….……………………………………………………………………
…………………………………………………………………………………………….
as partial fulfillment of his/her project work for the fourth Semester of the Master of
Commerce (Autonomous) under the University of Mumbai for the A.Y. 2021 –
2023.
4
INDEX
5
INTRODUCTION
1. Statistics: Statistical analysis helps investors understand the distribution, trends, and
patterns in stock market data. Concepts such as mean, standard deviation, correlation,
and regression analysis are used to measure and analyse historical returns, volatility,
and relationships between different securities.
3. Time series analysis: Time series analysis is used to study and predict stock price
movements over time. Techniques such as moving averages, exponential smoothing,
and autoregressive integrated moving average (ARIMA) models are employed to
identify patterns, trends, and seasonality in stock market data.
It is important to note that while mathematics provides valuable tools for stock market
analysis, it is not a guarantee of accurate predictions or guaranteed profits. The stock
market is influenced by various factors, including economic conditions, geopolitical
events, and investor sentiment, which may go beyond mathematical models' scope.
Sound judgment, experience, and an understanding of market dynamics are equally
important for successful stock market investing.
6
LITERATURE REVIEW
This literature review examines the role of mathematics in stock market analysis. It
explores various mathematical concepts, models, and techniques used in understanding
and predicting stock market behaviour. The review focuses on the application of
mathematics in areas such as financial modeling, risk management, portfolio
optimization, and quantitative trading strategies. The findings highlight the significance
of mathematics in providing valuable insights and tools for investors and traders in the
stock market.
1. Introduction
- Overview of the stock market and its complexities
- Importance of mathematics in stock market analysis
2. Financial Modeling
- Stochastic calculus and its role in modeling stock prices
- Brownian motion and geometric Brownian motion
- Black-Scholes-Merton model for option pricing
- Monte Carlo simulation for risk assessment
4. Portfolio Optimization
- Modern Portfolio Theory (MPT) and the mean-variance framework
- Markowitz's efficient frontier and the Capital Asset Pricing Model (CAPM)
- Portfolio diversification and the benefits of risk reduction
7
5. Risk Management
- Value at Risk (VaR) calculations
- Conditional Value at Risk (CVaR) as an extension of VaR
- Copula functions for modeling dependence between assets
This literature review provides an overview of the diverse mathematical techniques and
models employed in stock market analysis. It emphasizes the importance of
mathematics in understanding market dynamics, managing risk, optimizing portfolios,
and developing quantitative trading strategies. By incorporating these mathematical
tools, investors and traders can make informed decisions and gain a competitive edge in
the stock market.
8
TIME SERIES ANALYSIS
Time series analysis is a branch of statistics and mathematics that focuses on the study
of data points collected over successive time intervals. It involves analysing and
modeling the temporal patterns, trends, and dependencies present in the data to
understand and make predictions about future values
Mathematically, time series analysis involves the study of a sequence of observations or
measurements {y₁, y₂, y₃, ..., yₙ}, where each observation yᵢ corresponds to a specific
time point tᵢ. The goal is to characterize the underlying structure and dynamics of the
time series by applying various mathematical techniques.
2. Trend: Trend refers to the long-term pattern or direction in the data. It represents
the overall upward or downward movement in the series. Trends can be linear (constant
slope) or nonlinear (curved).
3. Seasonality: Seasonality refers to the regular and repeating patterns in the data that
occur within fixed time intervals. For example, retail sales might exhibit a seasonal
pattern, with increased sales during holiday seasons.
9
5. Autocorrelation: Autocorrelation measures the relationship between an
observation and a lagged version of itself. It helps identify patterns in the data that
persist over time. Autocorrelation is often represented by the autocorrelation function
(ACF) and partial autocorrelation function (PACF).
6. Time Series Models: Various models are used to analyse and forecast time series
data. Some common models include autoregressive integrated moving average
(ARIMA), exponential smoothing models, and seasonal decomposition of time series
(STL).
Time series analysis provides valuable insights into the behaviour of data over time,
helping analysts make informed decisions and predictions based on historical patterns
and trends.
In this scenario, the historical data consists of daily or intraday stock price values over a
specific period. By applying time series analysis techniques, such as autoregressive
10
integrated moving average (ARIMA), exponential smoothing models, or machine
learning algorithms like recurrent neural networks (RNNs), analysts can identify
patterns and trends in the data and make predictions about future stock prices.
These predictions can be used by investors to make informed decisions about buying or
selling stocks. For example, if the analysis suggests that a stock's price is likely to
increase in the near future, an investor may decide to buy that stock. On the other hand,
if the analysis indicates a potential decline in stock price, an investor may choose to sell
their holdings.
It's important to note that stock price forecasting is a complex task and involves many
factors beyond just historical price data, such as market news, company performance,
and global events. Time series analysis serves as a valuable tool to help understand and
analyse the historical patterns in stock prices, but it's not a guarantee of future
performance.
Mathematical formula:
11
TRADING & INVESTMENT
Stock market trading and investment involve buying and selling stocks or other
securities with the goal of generating a profit. It can be a complex and dynamic field,
but here is a basic introduction to help you understand the key concepts:
1. Stocks: Stocks represent ownership shares in a company. When you buy shares of a
company's stock, you become a partial owner and have the potential to profit from the
company's success.
2. Stock Exchanges: Stock exchanges are platforms where stocks are bought and
sold. Examples include the New York Stock Exchange (NYSE) and the NASDAQ.
Stock exchanges provide a regulated marketplace for investors to trade stocks.
4. Investment Strategies: There are different investment strategies you can follow,
such as:
a. Long-term Investing: This strategy involves buying stocks with the intention of
holding them for an extended period, often years or even decades. The goal is to benefit
from the company's growth over time.
b. Value Investing: Value investors look for undervalued stocks, believing that
their true worth is higher than the market currently reflects. They aim to buy stocks at a
discount and hold them until the market recognizes their value.
12
c. Growth Investing: Growth investors focus on companies that are expected to
experience rapid growth in the future. They prioritize stocks of companies with strong
earnings potential and reinvestment plans.
d. Day Trading: Day traders aim to take advantage of short-term price fluctuations
within a single trading day. They buy and sell stocks rapidly, attempting to profit from
small price movements.
7. Risk Management: It's essential to manage risk when trading or investing in the
stock market. Diversification, setting stop-loss orders, and having a clear risk tolerance
are some strategies to mitigate risk
Mathematical formula:
13
2. Sharpe Ratio Formula:
The Sharpe ratio is a measure of risk-adjusted return. It is calculated using the
formula:
Sharpe Ratio = (Rp - Rf) / σp
Where: Rp = average return of the investment
Rf = risk-free rate of return
σp = standard deviation of the investment's return
14
PYTHON CODE FOR TRADING & INVESTMENT
INPUT:
import numpy as np
def calculate_returns(prices):
returns = np.diff(prices) / prices[:-1]
return returns
def calculate_average_return(returns):
average_return = np.mean (returns)
return average_return
def calculate_volatility(returns):
volatility = np.std(returns)
return volatility
15
# Calculate returns
returns =lculate_returns(stock_prices)
# Calculate volatilit
volatility = calculate_volatility(returns)
print("Volatility:", volatility)
OUTPUT:
16
PROBABLITY
Probability plays a significant role in the stock market as it helps investors and traders
assess and manage risk, make informed decisions, and understand the potential
outcomes of their investments. By understanding probability, market participants can
evaluate the likelihood of various events occurring, such as price movements, earnings
reports, or market trends.
In the context of the stock market, probability refers to the chance or likelihood of a
particular event happening. It involves quantifying uncertainty and estimating the
likelihood of different outcomes. By analysing historical data, market trends, and
various indicators, investors attempt to determine the probabilities associated with
different investment scenarios.
One common approach to probability in the stock market is through statistical analysis.
Investors often use historical price data to calculate probabilities based on patterns and
trends. For example, they may analyse the frequency and magnitude of price
fluctuations to assess the likelihood of future price movements.
Probability is also relevant in assessing the risk and potential returns of investments.
Investors use tools like standard deviation, beta, and correlation to measure the
volatility of stocks and portfolios. These measures help investors understand the
probability of a particular investment's performance deviating from the expected
returns.
1.Standard deviation:
A standard deviation (or σ) is a measure of how dispersed the data is in relation to the
mean. Low standard deviation means data are clustered around the mean, and high
standard deviation indicates data are more spread out.
17
Formula: Standard Deviation = √ (Σ (xi - μ) ² / N)
Where:
2. Compound interest:
Compound interest refers to the process of earning or accruing interest on an initial
amount of money, called the principal, as well as on any previously earned interest. In
other words, it is interest calculated on both the initial investment and the accumulated
interest from previous periods.
18
Formula:
A = P (1 + r/n) nt
Where:
A = the future value of the investment/loan, including interest
P = the principal amount (the initial investment/loan amount)
r = the annual interest rate (expressed as a decimal)
n = the number of times that interest is compounded per year
t = the number of years
Example:
19
REGRESSION ANALYSIS
Regression analysis is a statistical technique used to model and analyse the relationship
between a dependent variable and one or more independent variables. It is commonly
employed to understand the impact of changes in the independent variables on the
dependent variable.
In regression analysis, the dependent variable, also known as the outcome variable or
response variable, is the variable of interest that we want to predict or explain. The
independent variables, also referred to as predictor variables or explanatory variables, are
the factors that may influence or contribute to the variation in the dependent variable.
The most common form of regression analysis is linear regression, where the relationship
between the variables is assumed to be linear. However, there are also other types of
regression analysis, such as polynomial regression, multiple regression, logistic regression,
and so on, that accommodate different types of relationships and variable types.
By analysing the regression model, researchers can estimate the effect of each independent
variable on the dependent variable, test hypotheses about the significance of the
relationships, make predictions for new observations, and assess the overall goodness of fit
of the model to the data
20
Formula:
Regression analysis involves examining the relationship between a dependent variable and
one or more independent variables. The formula for a simple linear regression, which
involves a single independent variable, is as follows:
Y = β₀ + β₁X + ε
Where:
- Y represents the dependent variable (also known as the response or outcome variable).
- X represents the independent variable
- β₀ represents the y-intercept
- β₁ represents the slope or coefficient of the independent variable X
- ε represents the error term or residual (the difference between the observed value of Y and
the predicted value of Y).
The goal of regression analysis is to estimate the values of β₀ and β₁ that best fit the data,
minimizing the sum of the squared errors (ε) between the observed and predicted values of
Y.
For multiple linear regression, where there are more than one independent variables, the
formula expands as follows:
Where:
- X₁, X₂, ..., Xₚ represent the p independent variables.
- β₁, β₂, ..., βₚ represent the corresponding coefficients for each independent variable.
21
In practice, statistical software packages like R or Python's scikit-learn provide tools to
perform regression analysis and estimate the coefficients (β₀, β₁, β₂, ..., βₚ) based on the
given data.
Example:
22
Python code:
Input:
23
TRENDS:
Trends in the stock market refer to the general direction or movement of stock prices
over a specific period of time. Analysing and identifying trends is an essential aspect of
stock market analysis as it helps investors, traders, and analysts make informed
decisions about buying, selling, or holding stocks. Here are some common trends
observed in the stock market:
1.Uptrend: An uptrend occurs when stock prices show a consistent upward movement
over time. It indicates a positive market sentiment, with buyers outnumbering sellers.
Uptrends are characterized by higher highs and higher lows on price charts.
5.Bear Market: A bear market refers to a prolonged period of declining stock prices,
typically accompanied by negative economic indicators and widespread pessimism
24
among investors. Bear markets are associated with overall market pessimism and often
lead to increased selling activity.
6.Volatility: Volatility refers to the degree of price fluctuations in the market. High
volatility indicates significant price swings, while low volatility suggests relatively
stable price movements. Volatile markets can present opportunities for higher potential
gains but also come with increased risk.
7.Reversal: Reversal trends occur when the prevailing trend in stock prices changes
direction. For example, an uptrend may reverse and transition into a downtrend, or vice
versa. Reversals can indicate a shift in market sentiment and present opportunities for
traders to adjust their positions.
A trend line is a line drawn on a price chart to connect successive higher lows in an
uptrend or lower highs in a downtrend. The general formula to calculate a trend line is:
Y = mx + c
Where:
Y represents the value of the dependent variable (usually the stock price).
x represents the value of the independent variable
m represents the slope of the trend line.
c represents the y-intercept of the trend line.
The slope (m) and y-intercept (c) can be determined using various statistical techniques,
such as linear regression, to minimize the sum of squared errors between the data points
and the trend line.
25
Input:
26
BLACK SHOLES MODEL
The Black-Scholes model provides a way to estimate the fair value of options by taking
into account various factors, including the current price of the underlying asset, the strike
price of the option, the time to expiration, the risk-free interest rate, and the volatility of the
underlying asset's price.
The underlying principle behind the Black-Scholes model is that it assumes financial
markets are efficient and that the price of the underlying asset follows a geometric
Brownian motion. This means that the asset's price changes randomly over time but follows
a specific statistical distribution.
The Black-Scholes method revolutionized the field of options pricing and has been widely
adopted by financial institutions and investors. However, it is important to note that the
model has certain assumptions and limitations. For example, it assumes constant volatility,
which may not hold true in all market conditions. It also assumes no transaction costs,
dividends, or restrictions on short-selling. Nevertheless, the Black-Scholes method remains
a fundamental tool in options pricing and has paved the way for further advancements in
quantitative finance.
27
Formula:
Example:
One real-life example of the Black-Scholes model in action is the pricing of options on
stocks or other financial instruments. The Black-Scholes model is a mathematical formula
used to calculate the theoretical price of an option based on various factors such as the
current stock price, the strike price of the option, the time remaining until expiration, the
volatility of the underlying asset, and the risk-free interest rate.
Let's consider a hypothetical scenario where you have a call option on a stock. The Black-
Scholes model can be used to estimate the fair value of that call option based on the inputs
mentioned above. For example, if the stock price is $100, the strike price of the option is
$110, the time to expiration is 30 days, the volatility is 20%, and the risk-free interest rate is
2%, you can plug these values into the Black-Scholes formula to calculate the theoretical
price of the option.
The Black-Scholes model provides a framework for valuing options and is widely used by
traders, investors, and financial institutions in the real world. It helps in determining
whether an option is overpriced or under-priced relative to its theoretical value, and it also
assists in assessing the risk associated with options trading.
28
OPTION PRICING
Option pricing is a financial concept that involves determining the value of a financial
instrument called an option. Options are derivative contracts that give the holder the right,
but not the obligation, to buy (call option) or sell (put option) an underlying asset at a
predetermined price (strike price) within a specified period (expiration date).
The price of an option is influenced by several factors, including the current price of the
underlying asset, the strike price, the time remaining until expiration, the volatility of the
underlying asset's price, and the risk-free interest rate.
The primary models used for option pricing are the Black-Scholes model and the Binomial
model.
The Black-Scholes model is widely used due to its simplicity and analytical solution for
European options. However, it assumes constant volatility and does not account for early
exercise possibilities or transaction costs. The binomial model, on the other hand, can
handle a wider range of option types and allows for incorporating factors like dividends and
early exercise. However, it can be computationally intensive, especially for options with
longer time periods.
29
It's important to note that option pricing models provide estimates of option values and
serve as a starting point for determining fair prices. Market conditions and other factors can
cause actual option prices to deviate from the model's estimates. Traders and investors use
option pricing models to assess the relative value of options and make informed decisions
regarding buying, selling, or hedging options positions.
Formula:
30
Example:
Let's consider an example of option pricing using the Black-Scholes model, one of the
widely used models for valuing European-style options. Here's an example scenario:
where:
31
= -0.105 + 0.35
= 0.245
Using the cumulative standard normal distribution table (or a calculator), we can find the
values of N(d1) and N(d2) corresponding to 0.245 and 0.045, respectively.
Assuming N(d1) = 0.5962 and N(d2) = 0.5159, we can calculate the call option price:
Therefore, the estimated value of the call option, based on the Black-Scholes model, is
$8.37.
32
PORTFOLIO
1.Stock Selection: Investors typically choose stocks for their portfolio based on various
factors such as company fundamentals, industry outlook, growth potential, dividend yield,
risk tolerance, and investment strategy. The portfolio may consist of stocks from different
sectors, sizes (large-cap, mid-cap, small-cap), or geographic regions to spread the risk.
33
5.Performance Monitoring: Regular monitoring and evaluation of the portfolio's
performance is essential. Investors may compare their portfolio returns to benchmark
indices, track individual stock performance, and assess the portfolio's overall risk and
return characteristics. Adjustments may be made based on market conditions, changing
investment goals, or new investment opportunities.
Example:
Let's calculate the total value of a stock portfolio in Indian Rupees (INR) using an example:
Therefore, the total value of the stock portfolio in Indian Rupees is ₹122,000.
34
35
PERCENTAGE LOSS
Percentage loss in the stock market refers to the decrease in the value of an investment or
portfolio expressed as a percentage of the initial investment or portfolio value. It is a
measure of the extent to which the value has declined over a specific period.
To calculate the percentage loss, you need two values: the initial value (before the decline)
and the final value (after the decline). The formula to calculate the percentage loss is as
follows:
Assume an investor initially invested ₹50,000 in a stock and the current value of the
investment has decreased to ₹40,000.
36
Code:
return profit
return Loss
# Driver code
if __name__ == "__main__" :
if sellingPrice == costPrice :
print("No profit nor Loss")
else :
print(Loss(costPrice,
sellingPrice), "Loss")
Output:
500 profit.
37
Conclusion
In conclusion, mathematics plays a significant role in the stock market. It provides essential
tools and concepts for analysing and understanding the dynamics of stock prices, risk
management, portfolio optimization, and option pricing. Here are some key points to
consider:
1.Data Analysis: Mathematics helps in analysing historical stock price data, identifying
patterns, and extracting meaningful insights. Statistical techniques, such as regression
analysis, correlation, and time series analysis, can be applied to uncover relationships and
trends in the market.
3.Option Pricing: Mathematical models, such as the Black-Scholes model, are used to
price options and derivatives. These models take into account factors such as the underlying
stock price, strike price, time to expiration, interest rates, and volatility to determine the fair
value of options.
Mathematics provides a quantitative framework for investors and traders to make informed
decisions based on data-driven analysis and calculations.
38