0% found this document useful (0 votes)
21 views20 pages

Minor Project 1 Report

Uploaded by

Arijeet ros
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)
21 views20 pages

Minor Project 1 Report

Uploaded by

Arijeet ros
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/ 20

Abstract:

Intraday trading poses challenges for individuals seeking efficient decision-making


amidst market dynamics. This research explores the development of a
groundbreaking algorithmic trading platform, integrating machine learning models
and real-time data fetching. This initiative is for college students and professionals,
the platform empowers users to design and optimize trading algorithms with ease.
The project unfolds in two phases: classical machine learning models and
advanced techniques like ARIMA and deep learning. Offering granular
customization, robust backtesting, and live testing integration with an Indian
brokerage, the platform stands out for its versatility. Comparative analysis
highlights its unique emphasis on user-defined algorithms and the incorporation of
diverse machine learning models, setting it apart from specialized solutions. The
project signifies a leap forward in simplifying intraday trading, presenting a
comprehensive, customizable, and practical solution for strategic decision-making
in dynamic market environments along with full automation in stock trading.

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.

Intraday trading involves swift decision-making and execution, making it


challenging for traders with constrained time resources. The proposed algorithmic
trading platform aims to empower individuals by harnessing the potential of
machine learning models. By automating aspects of trading and leveraging
historical data, the platform seeks to streamline the trading process and enable
users to define, test, and optimize their trading algorithms.

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

This paper introduced us to Genetic Algorithm and quoting the paper:


“Since the genetic algorithm can perform reasonably well in many cases there has
to be a way to predict stock price using GA as well.”
Dataset Used: Five years data of the following companies: Adobe, Apple, Google,
IBM, Microsoft, Oracle, Sony and Symantec
The genetic algorithm worked to create a civilization with the mutation of strongest
genes and produce fit individuals to get a healthy population. This was mapped to
the stock price data. And along with Genetic Algorithms some Evolutionary
Strategies were also used that played with the probability of upcoming generations.
It was found that the genetic algorithm and evolution strategies have performed
almost evenly. The best accuracy found using the genetic algorithm was 73.87%
and using evolutionary strategies was 71.77%. The genetic algorithm was able to
predict better than the evolutionary strategies in five cases. The evolutionary
strategy reached an accuracy of 70% or better in all cases.

4
Methodology:
From our thorough research study and knowledge that we have gathered we want

to propose the following methodology that we want to apply in our algorithmic

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

prediction in an efficient manner.

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

which indirectly helps us to predict the price movement.

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

a human-like taste to it, we implemented a general algorithm to generate what a

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:

Let’s start with collecting all the Python libraries:

```

# Dependencies

import yfinance as yf
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
import seaborn as sb

from sklearn.metrics import accuracy_score, classification_report,


confusion_matrix
```

Step 1:

Collect Stock Data

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:

Create user defined Technical Indicator functions

SMA and EMA functions are implemented and added to the df alongside close and
Volume

7
Step 4:

Add Target/Label to the dataset

```

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:

Visualize the points to focus on.


Red means Market Entry/Buying in
Green means Market Exit/Selling out

9
Step 6:

Split the dataset into training and testing

Training Features: Close, Volume, SMA, EMA

Testing Features: Conditional Target which include the technical indicators


from sklearn.model_selection import train_test_split

X = df[['Close', 'Volume', 'SMA', 'EMA']]

y = df['Label']

# Split the data into training and testing sets

X_train, X_test, y_train, y_test = train_test_split(X, y,


test_size=0.2, random_state=42)

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:

precision recall f1-score support

-1 0.30 0.27 0.28 139

0 0.35 0.42 0.38 194

1 0.30 0.26 0.28 181

accuracy 0.32 514

macro avg 0.31 0.31 0.31 514

weighted avg 0.32 0.32 0.32 514

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:

precision recall f1-score support

-1 0.67 0.65 0.66 139

0 0.56 0.59 0.57 194

1 0.78 0.75 0.76 181

accuracy 0.66 514

macro avg 0.67 0.66 0.67 514

weighted avg 0.67 0.66 0.66 514

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:

precision recall f1-score support

-1 0.78 0.62 0.69 139

0 0.58 0.64 0.61 194

1 0.76 0.78 0.77 181

accuracy 0.69 514

macro avg 0.71 0.68 0.69 514

weighted avg 0.70 0.69 0.69 514

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 .

Despite limitations, the models demonstrate significant improvements


over the base prediction accuracy. Further refinement and feature
engineering may enhance results.

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

You might also like