Ai trading

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

ALGORITHMIC TRADING USING ARTIFICIAL INTELLEGENCE

Aunsh Gupta MR. Girdhari lal


(Student) Computer Science and Engineering (AI) (Assistant Professor) Artificial Intelligence and Data Science
Poornima Institute of Engineering and Technology, Science Poornima Institute of Engineering and Technology,
Jaipur Jaipur

Email id- [email protected] Email id- [email protected]

---------------------------------------------------------------------***----------------------------------------------------------------------
Abstract- Stock markets are very important for a country's With less data and testing, the main goal is to find the best
economic growth in today's world. Since these markets are design for the machine learning model to perform better
very active, many studies have shown that traditional trading than others. This paper will focus on solving this problem
methods face several challenges. Therefore, in this paper, we and exploring different techniques to handle the specific
introduce a framework that uses various trading strategies to trading task. We aim to find an algorithm that uses fewer
predict stock market trends. Artificial intelligence is often resources but still provides the most accurate results
used to reduce risks and maximize net profit through possible.
different trading algorithms. Different methods, such as
Neural Networks, XGBoost, and SVM, are used in algorithmic Many methods have been used in the past to predict stock
trading to predict stock prices in the future. This paper prices, but we will focus on those based on artificial
explains how the data is collected, analyzed, and how these intelligence. The main contribution here is proposing the
techniques work, along with some examples. The results are XGBoost method for stock trading instead of more traditional
significant, showing which technique works best for machine learning methods.
algorithmic trading using machine learning algorithms to
achieve the highest returns. 2. LITERATURE SURVEY

Keywords: Artificial Intelligence, Stock Trading, SVM – There are several methods for predicting the future price of
support verctor machine, Machine Learning stocks over a specific time frame. We are using three
different methods: Neural Network, Support Vector Machine,
1. INTRODUCTION and XG Boost. After applying these methods, we compare
them to find the most effective one that provides the highest
Traditionally, methodologies used for forecasting the stock net profit.
price relied solely on technical indicators that generate
trading signals based on profit generation. We have used the
trading strategies to which we have applied the 2.1 Neural Network
methodologies of artificial intelligence in association with
technical analysis indicators combined with real-time price Neural Networks are often used to reduce various risks and
information. increase net profits in different types of algorithmic trading
strategies. Simple neural network models can predict future
The resulting AI-based prediction models are intended to be stock market price movements [3].
used by an automated trader to buy and sell stocks on a
stock market. Artificial Intelligence has become very Definitions related to stock trading in Neural Networks:
important in predicting stock trends. Techniques in AI, such Logreturn:
as neural networks, are used to identify correlations,
relationships, and market changes based on historical data, Let cp be the current closing price and cp−1 be the previous
and to predict future trends of a stock. closing price.

One of the major challenges in modeling financial market R = loge(cp/cp−1)*100 %


movements is the vast amount of data coming from many
sources. From the various AI models developed in this = (loge (cp) – loge (cp−1) )*100 % Pseudo log-return:
field, we decided to adopt a method that uses the
Pseudo log return is the logarithmic difference between
available data and information.
average prices for consecutive minutes.
ALet's say cp is the average price over the last From Fig1, we can see how the neural network method
minute, and cp−1 is the average price from the minute works for stock trading. If the previous minute's closing
before that. price plus the spread is less than the prediction, we buy
the stock. If it's greater, we sell.

R = loge( cp/cp−1)*100 %
= (loge (cp) – loge (cp−1) )*100 % One-minute
Trend Indicator :-
This is a measurable indicator that shows how the
price is changing over time. It uses a simple line (cost =
at+b) to fit the price data for a specific moment, where t is
the time in milliseconds within that minute [4].

A small slope for the next minute suggests the


price will stay the same.
If the result is positive, it means the price will go
up in the next minute.
If the result is negative, it means the price will go
down in the next minute.

Fig2. This shows the overall stock performance of the


The change in price is related to how far the price neural network model compared to the buy-and-hold
moves. strategy [5].
Spread :- From Fig2, it is clear that the Neural Network provides
Spread = Ask price – Bid Price higher returns than the buy-and-hold strategy, as
mentioned in the reference paper.
A trading strategy is built using predictions from a
neural network. At the start of each minute, it checks if the Advantages:
predicted average price for the next minute is higher than
the closing price of the last minute. If it is, the strategy will Ability to work with incomplete information: After training,
buy the stock. If the stock price reaches the predicted the system can still produce output even if some data is
average price within a specific minute, it will sell the stock. missing. The impact on performance depends on how
If the price doesn't reach the predicted level, it will sell the important the missing data is.
stock at the end of that minute. This is the strategy for
buying and selling stocks using a neural network [4]. Resilience to internal errors: Even if some parts of the system
are damaged, it can still produce output. This makes the
system fault-tolerant.

Parallel processing capability: Artificial neural networks can


handle multiple tasks at the same time due to their
mathematical nature.

Disadvantages:

Dependency on specialized hardware: Artificial neural


networks need powerful processors to work effectively,
which means they rely on specific types of equipment.

No clear guidelines for system design: There isn't a set rule


for designing these systems. Finding the right design often
involves trial and error.
Fig1. Flowchart of the strategy for a neural network
model to buy, sell, or hold stocks based on stock price
predictions [4].
2.2 Support Vector Machine

Support Vector Machines (SVM) is a top-notch tool for


separating data into two groups. It creates a dividing line,
aiming to have the most points from one group on one
side and the most points from the other group on the
other side. After this, the points in one group will have a
total value greater than zero, while the points in the other
group will have a total value less than zero.

For a labeled dataset with an n-dimensional feature vector


x = (X1,… ,Xn), we can define a straight dividing line
(hyperplane) as:

Fig3. Architecture of the support vector machine based


model with step-by-step procedure for stock
prediction[17].
βo + Σ(i=1 to n) βi Xi = y
In above Fig3 figure we can see how the actual process
from data collection to training models to checking
accuracy check takes place
Here, y can be either -1 or 1.

Depending upon y, the prediction about the stock price


will come. If y is 1, then the value is increased; otherwise,
decreased. The best hyperplane is that which maximizes
the distance from this flat surface to any point. This
distance is called the margin. In case of maximum margin,
the best hyperplane has separated the data. However, in
all cases such perfect separation is not possible so we can
introduce an error variable e1 to en keeping their total
under a budget B. The most significant points are those
close to the boundary as they are essential while choosing
the hyperplane. The rest are insignificant. These key
points are called support vectors, and the hyperplane is
named the Support Vector Classifier because it locates Fig4. SVM Classifiers that separate into two groups
each support vector in a particular unit type [18]. using a decision line (Hyperplane).

SVM MODEL: From Figure 4, we can see how the classifier decides
The kernel feature we're using here is the radial kernel, between buying and selling.
which is one of the most popular kernel functions
available [13]. FEATURES FOR THE MODEL:

Four elementary factors are used to predict the direction


of a stock's price change: price volatility, price
momentum, sector volatility, and sector momentum.
More specific details about these factors will be stated in
Which is shown above ,in which δ is considered to be band Table [13].
width of the kernel function .The favorable condition is
that it can deal with various different taking in dataset, When we look at the Table, we explain how each feature
because there are some restrictions on the information is calculated by averaging values over the last n days. We
obtained through inputs.. can test our model by changing the value of n to observe
exactly how the features change, both for the index and
for individual stocks. This will help us predict future
stock price changes.
PERFOMANCE: · From our research, we can identify the following
limitations of current methods:
· - Unstable returns and high volatility
· - Longer training times, leading to delayed trades

3. PROPOSED METHOD

Xtreme Gradient Boosting

3.1 Preprocessing

Data Pre-processing - This data is very critical for the


.end result.

We shall collect the stock market price data from our source.

Fig6 .preprocessing model [1].

In Figure 6, we can observe the path data takes through the


entire model and how it eventually reaches the execution
model to make trades. We will remove any outliers from
Fig5. Collective stock performance of SVM based model the data because they can lead to unstable results.
against buy and hold strategy [5].
Then, let's name the features of the data correctly. Then,
From Figure 5, it is clear that the SVM method provides we need to confirm whether the returns are independently
higher returns compared to the buy-and-hold strategy, and identically distributed.
as mentioned in the reference paper.
And in cases where some labels reveal a strong
Advantages: interdependence, we erase the redundant data.

SVM works well when there is a clear separation


between different categories.

SVM can effectively manage unaligned data using the


kernel trick, making it a powerful tool. With the right
kernel function, we can handle complex problems.

Unlike neural networks, SVM does not get stuck in local


optima; it finds the global optimum. This makes it a
convex optimization problem.

Small changes in the data do not significantly affect the


hyperplane, so the SVM model is stable. This leads to
better results compared to other models.

Disadvantages:-

· The kernel trick is a key feature of SVM, but choosing


the right kernel function is very challenging.
· SVM, or Support Vector Machine, is not a
3.2 Methodology
probabilistic model, so we can't clearly define its
characteristics. The support vector classifier works 3.2.1 Decision Tree
by focusing on data points above and below the
classification boundary. Tree boosting uses Decision tree as a classifier. CART also
· SVM models are harder to understand and interpret known as output function of eXtreme gradient boosting is
compared to Decision Trees because they are more regression tress linear superposition.
complex.
Decision trees are the building blocks of the XGBoost
Algorithm. XGBoost iterates over this and improves the
performance.

Fig 7. example of decision tree

Above figure7, explains how decision tree works. If P.B. < Fig 8. trading performance of decision tree [5].
1.5 and vol < 0.8 then strong returns are expected.
Likewise other combinations are described Figure 8 helps us understand how decision trees work,
which gives us clues about how XGBoost might perform.
3.2.2 Tree Boosting XGBoost uses multiple decision trees in its approach.
During the tree boosting process, we focus on multiple As we can see, the initial loss was quite high, so it's not very
decision trees, each of which is refined based on the suitable for our needs due to its poor performance.
previous ones.
Now, we will apply the XGBoost algorithm to these decision
Tree boosting allows us to make complex decisions by using trees and observe its performance.
decision trees as basic building blocks.
After applying XGBoost, we can see a significant
An ensemble technique employs a tree ensemble model, improvement in the algorithm's performance. It is making
which consists of regression and classification trees (CART). profits more predictably, and even when the market goes
The predictions from multiple trees are combined using down, it continues to make profits, which is what we need.
CART.
XGBoost is more optimized and requires fewer resources to
By enhancing previous methods and merging their results, run. This makes it faster and more efficient in terms of
new models are developed to reach the final prediction. This resource usage.
method is called Gradient Boosting.
ADVANTAGES OF XGBOOST:
The objective function for the eXtreme Gradient Boost model
is: Objective = Loss_func + regular_comp · Speeding up parallel learning with Block structure:
· To handle large and fast calculations, eXtreme
Loss_func measures the accuracy of predictions, while Gradient Boosting uses all the cores in the processor.
regular_comp helps prevent overfitting and keeps the model This is possible due to a special design in XGBoost
simple. called the block structure. Data is organized and
stored in different parts of the memory called blocks.
In the beginning, we have to process through a bunch of
Unlike other algorithms, this setup allows data to
processing of data and tuning of model. The algorithm for
be reused in future iterations and processes
grid search is used for tuning various values for eXtreme
without needing to recalculate it.
gradient boosting.

Reciver operating characteristics curve is a plot of FPR vs · Self-awareness of cache: In the eXtreme Gradient
TPR that explains binary classifier model diagnostic abilityas Boosting algorithm, gradient statistics are stored by row
variation of discrimination threshold occurs. index within non-continuous
memory. Because of this, the design of XGBoost is cache-
aware.
Efficient use of available hardware is achieved by dividing 4. Machine Learning: Automatic Trading Using
memory into sections for each thread, allowing gradient Event-Driven Data by Jason W. Leung, pages
statistics to be stored in memory. 24, 25, 39-42.

Out-of-core computing: It makes the most of memory and 5. "Using a Group of Neural Networks to Trade
optimizes disk space when working with very large datasets Stocks: A Study in North American and
that can't fit into memory all at once. Brazilian Markets" (2015), published by IEEE.

6. "Forecasting Stock Market Prices Using Support


Vector Regression" by Department of Computer
Science and Engineering, University of Chittagong,
in IEEE.
7. "Forecasting Profits in Stock Trading Using
Random Forest, Support Vector Machine, and
XGBoost" by Ritesh Ghosh (Engineer at Cisco
Video Technologies India Pvt Ltd)
8. "From Forecasting to Classification: Predicting the
Movement of Stock Prices Using Xtreme Gradient
Boosting" by Shubharthi Dey and Yash Kumar.
Fig 9. trading performance of decision tree [5].
9. Zhang, X., & Chen, W. (2019). "Selecting Stocks
Fig9, givens clear comparison between various machine Using Extreme Gradient Boosting," published by
learning algorithms and clearly denotes that XGBoost IEEE.
outperforms other algorithms in both predictive power 10. [Link to a textbook on using XGBoost for
and training time. trading](http://www.statsoft.com/textbook/XGB
oost-for-trading)
4. CONCLUSION 11. [Blog post on forecasting markets using Extreme
Gradient Boosting
We explored three commonly used AI methods applied (XGBoost)](https://blog.quantinsti.com/forecasti
to stock price data and other relevant information to ng-markets-using-extreme-gradient-boosting-
create effective trading systems. We evaluated the xgboost)
performance of these models using available datasets, 12. K. Jae Kim, “Using support vector machines for
and our findings showed that, although the forecasting financial time series forecasting,”
accuracy was low, the resulting trading strategies Neurocomputing, vol. 55, 2003.
outperformed the market during this period. The 13. M. Halls-Moore, “Support vector machines: A
XGBoost algorithm provided the highest returns and beginner’s guide,” September 2014. [Available
required fewer training resources, leading to faster online].
processing times. Considering these results and other 14. Application of Support Vector Machine in Algorithmic
benefits, 1) We conclude that XGBoost is the best Trading, by Szklarz J1., Rosillo R2., Alvarez N2.,
artificial intelligence model for stock selection. 2) Fernández I2., and Garcia N2. Programmer,
XGBoost is the most suitable method for Izertis S.L, Gijón, Asturias, Spain. Business
implementation. Management Department, University of Oviedo,
Gijón, Asturias, Spain.
REFERENCES 15. D.d.l.F. Rosillo, J. Giner. "Support Vector Machines
applied to the Simulation of Stock Market." Journal
1. "Stock Trading Model Utilizing Opening Range of Forecasting, vol. 33, pp. 488–500, July 2014.
Breakouts," International Journal on Cybernetics 16. Machine Learning Approach for Stock Market
& Informatics (IJCI), Volume 5, Issue 1, February Prediction, by Raut Sushrut Deepak, Shinde Isha
2016. Uday, and Dr. D. Malathi, International Journal of
Pure and Applied Mathematics, Volume 115.
2. Brandao, Humberto. "Applying Neural Networks
for Improving High Frequency Trading
Strategies." 978-1-4799-1484-5/14 ©2014 IEEE.

3. "Algorithmic Trading with Deep Neural Networks


on High-Frequency Data," Springer Internal
Publication AG 2017.

You might also like