Minor Project 1 Report
Minor Project 1 Report
The study begins by reviewing some existing work in this field and proceeds by
testing our understanding from those studies. Subsequently, we start to formulate
our own methods to get some satisfiable output of our customized requirements. A
diverse set of features, technical indicators, fundamentals, and macroeconomic
factors are carefully considered.
1
Introduction:
This report delves into the creation of an innovative algorithmic trading platform
designed to make trading accessible and efficient. Intraday trading is a dynamic
and time-consuming endeavor, posing challenges for individuals with limited time
resources. The introduced algorithmic trading platform seeks to bridge this gap by
the power of machine learning models. The overarching goal is to create a
customizable and user-friendly solution that allows individuals to define, test, and
optimize their trading algorithms on historical data.
2
Related Work:
1.
Automated Stock Price Prediction and Trading Framework for Nifty Intraday
Trading
By Aparna Anant Bhat and Sowmya Kamath S.
Data Used: NSE Stock Data [2 years historical data of Closing price and Volume]
They have performed Technical Analysis using Technical Indicators like:
● MACD - Moving Average Convergence/Divergence indicator
● EMA - Exponential Moving Average
● RSI - Relative Strength Index
And the predictions were made upon their cumulative trends, movements, and
directions, and it was used for the next couple of days. Usually the identification
was boolean like increase or decrease.
Neural Network Prediction also assisted their decision.
Activation functions used - Sigmoid and Hyperbolic tangent function
Initial weights used - 0.5
The neural networks had a backpropagation method that updated the weights to fit
accurate predictions. To be specific the algorithm used is named as Levenberg
Marquardt Backpropagation Algorithm.
Training validation testing data - 70% 15% 15%
Even Sentiment analysis was done on the stock reviews over the internet.
The analysis was concluded after a total of 100 days with all the documentation.
Their combination of the three mostly used methods, ie, Technical Analysis,
Neural Networks and Sentiment Analysis increased their results to give better
performance
3
2.
Stock price prediction using genetic algorithms and evolution strategies
By Ganesh Bonde and Rasheed Khaled
4
Methodology:
From our thorough research study and knowledge that we have gathered we want
platform as a starter that can be modified further in the future. Currently classical
machine learning algorithms are being used. Further in the future we’ll be
concentrating in the Deep Learning Neural Networks that can enhance the
So what we know is that the base prediction accuracy is about 49%-51% more or
less. We want to add some tweakings to the features by using technical indicators
For the features we will use Stock Price, Stock Volumes, and the Technical
indicators that will be used [in our case Simple Moving Average or SMA and
Exponential Moving Average or EMA]. And for the target/label we wanted to add
human will do in a given Stock Price using technical indicators. Current Logic is if
our price is below the EMA and SMA as well as EMA is below SMA then it is a
good point to enter the market, the opposite of this is our exiting condition.
So finally we train our model with the above conditions using Classification
Machine Learning Algorithms like K-Nearest Neighbours, Support Vector
Classification, and Logistic Regression. We also want to apply Ensemble Learning
techniques to get the best results.
5
Discussion:
Step 0:
```
# Dependencies
import yfinance as yf
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
import seaborn as sb
Step 1:
We are using Yahoo Finance API to get the Stock data of AXIS BANK of past
week 1 minute interval data. We will be using this data for Intraday purposes.
```
# Stock data
t = input("Input Ticker: ")
data = yf.Ticker(t)
df = data.history(period="7d", interval="1m") # Intraday of past 7 days
6
```
Step 2:
As we can see the Data API shares the columns 'Dividends', 'Stock
Splits', 'Open', 'High', 'Low', 'Close', and 'Volume'
We only want 'Close', and 'Volume' and the remaining are removed.
Step 3:
SMA and EMA functions are implemented and added to the df alongside close and
Volume
7
Step 4:
```
l = []
for i in range(len(df['Close'])):
if df['EMA'][i] < df['SMA'][i] and df['Close'][i] < df['EMA'][i] and df['Close'][i]
< df['SMA'][i]: # Buying Condition
l.append(-1)
elif df['EMA'][i] > df['SMA'][i] and df['Close'][i] > df['EMA'][i]:# Selling Cond
l.append(1)
else:
l.append(0)
df['Label'] = l
```
8
Step 5:
9
Step 6:
y = df['Label']
Step 7:
Train Machine Learning Algorithms and fit it into a model and use it
10
Comparison:
Output:
KNN Model [k=11]:
k-Nearest Neighbour can capture complex patterns in the data without
assuming a specific underlying model.
Accuracy: 0.321011673151751
Classification Report:
Confusion Matrix:
[[37 60 42]
[43 81 70]
[44 90 47]]
KNN may not be the first choice for all stock price prediction tasks
11
SVC Model:
Support Vector Machine (SVM) is a powerful classification algorithm
commonly used in machine learning. SVM, in this context, is more commonly
used for classification tasks related to stocks, such as predicting
whether the stock will go up or down.
Accuracy: 0.6614785992217899
Classification Report:
Confusion Matrix:
[[ 91 48 0]
[ 42 114 38]
[ 3 43 135]]
12
LR Model:
Though this values are not promising but with proper coding techniques it
can be useful since our goal is to beat that 51% base prediction and given
68% accuracy we have improved over 17%
Accuracy: 0.6867704280155642
Classification Report:
Confusion Matrix:
[[ 86 53 0]
[ 24 125 45]
[ 0 39 142]]
13
System Analysis:
By systematically analyzing these aspects, you can ensure that your
Stock Price Prediction Machine Learning project is well-designed,
robust, and aligned with its objectives. This approach also facilitates
ongoing improvements and adaptability in response to changing market
conditions.
14
1. Project Objectives:
The system aims to predict stock price movements using a
combination of classical machine learning algorithms and, in the
future, transitioning to deep learning neural networks. The primary
goal is to enhance prediction accuracy beyond the base level of
49%-51%.
2. Data Collection and Preprocessing:
The system utilizes the Yahoo Finance API to collect intraday
stock data for AXIS BANK over the past 7 days at a 1-minute
interval. This data serves as the foundation for the prediction
models.
3. Feature Selection:
Features include 'Close' and 'Volume,' and technical indicators such
as Simple Moving Average (SMA) and Exponential Moving
Average (EMA) are computed and added to the dataset.
4. Model Selection:
A label is generated based on predefined conditions involving
EMA, SMA, and Close prices to determine whether to enter the
market (buying), exit the market (selling), or take no action.
5. Visualization:
The system visualizes entry and exit points in the stock data,
providing a clear representation of the algorithm's
decision-making.
6. Data Splitting:
The dataset is split into training and testing sets in the ratio 80-20,
with features including Close, Volume, SMA, and EMA.
15
7. Model Training:
Classification machine learning algorithms, including K-Nearest
Neighbours, Support Vector Classification, and Logistic
Regression, are trained on the training dataset. The models aim to
learn patterns in the data to make predictions.
8. Evaluation Metrics:
- K-Nearest Neighbours (KNN), Support Vector Classification
(SVC), and Logistic Regression (LR) are evaluated for their
accuracy in predicting stock price movements.
- SVC and LR show promising results, with LR achieving the
highest accuracy of 68.7%.
9. Scalability and Performance:
Continuously evaluate the performance and wherever needed add
upgrades and optimize the system .
16
Software and Hardware Requirements:
Software Requirements:
1. Programming Language:
Python is a widely used language for machine learning. Ensure Python is
installed, and consider installing required libraries such as NumPy,
pandas, scikit-learn, TensorFlow, or PyTorch.
2. Integrated Development Environment (IDE):
Choose an IDE for development. VSCode is preferable.
3. Data Visualization:
Visualization libraries like Matplotlib and Seaborn for exploratory data
analysis are used.
4. Text Editors:
Have a text editor such as VS Code.
5. Virtual Environment:
Set up virtual environments to manage dependencies and isolate project
requirements.
17
Hardware Requirements:
1. Computing Resources:
Ensure access to a computer with sufficient processing power for data
preprocessing, model training, and testing.
Consider using cloud computing services (e.g Google Colab) for
scalable resources.
2. Memory (RAM):
Have enough RAM to handle large datasets and complex machine
learning models efficiently.
3. Storage Space:
Sufficient storage space for storing datasets, model checkpoints, and
other project-related files.
4. Graphics Processing Unit (GPU):
For faster model training, consider using a GPU, especially when
working with deep learning models.
5. Internet Connectivity:
A stable internet connection is necessary for accessing online data
sources, APIs, and collaborative tools.
18
Conclusion & Limitations:
In conclusion, the project represents a significant leap forward in
streamlining intraday trading for individuals with limited time. By
synergizing user-defined algorithms with a diverse array of machine
learning models, the platform offers a unique and versatile solution. The
emphasis on customization, comprehensive backtesting, and integration
with live trading scenarios positions the project as an indispensable tool
for those seeking to optimize their trading strategies. As the project
evolves, continuous refinement and user feedback will contribute to its
effectiveness in navigating the ever-changing landscape of algorithmic
trading.
Limitations:
1. Assumption of Technical Indicators:
The accuracy of predictions heavily relies on the assumptions
made about technical indicators such as EMA and SMA. If market
conditions change, these assumptions might become less accurate.
2. Sensitivity to Market Conditions:
The model's performance may be sensitive to specific market
conditions during the training period. It might not generalize well
to different market scenarios, especially during periods of high
volatility or unforeseen events.
3. Static Features:
The use of fixed features like Close, Volume, SMA, and EMA may
not capture all relevant information. Financial markets are
dynamic, and incorporating additional features or alternative data
sources might improve predictive capabilities.
4. Limited to Historical Patterns:
The model primarily relies on historical patterns and may not adapt
quickly to sudden changes or black swan events, which are
inherent risks in financial markets.
19
Reference/Bibliography:
● Bhat, A.A. and Kamath, S.S., 2013, July. Automated stock price
prediction and trading framework for Nifty intraday trading. In
2013 Fourth International Conference on Computing,
Communications and Networking Technologies (ICCCNT) (pp.
1-6). IEEE.
● Bonde, G. and Khaled, R., 2012. Stock price prediction using
genetic algorithms and evolution strategies. In Proceedings of the
International Conference on Genetic and Evolutionary Methods
(GEM) (p. 1). The Steering Committee of The World Congress in
Computer Science, Computer Engineering and Applied Computing
(WorldComp).
● Hands-On Machine Learning with Scikit-Learn and TensorFlow:
Concepts, Tools, and Techniques to Build Intelligent Systems
Book by Geron Aurelien
● Investopedia Website: https://www.investopedia.com
20