Profitable Strategy Design For Trades On Cryptocurrency Markets With Machine Learning Techniques

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

Profitable Strategy Design for Trades on

Cryptocurrency Markets with Machine Learning


Techniques
Mohsen Asgari#1 , Seyed Hossein Khasteh#2
#
Artificial Intelligence Department, Faculty of Computer Engineering, K. N. Toosi University of Technology
Mohsen0Asgari@gmail.com
khasteh@kntu.ac.ir
Abstract— AI and data driven solutions have been applied to (Hileman & Rauchs, 2017, p. 2) ”The findings are
different fields and achieved outperforming and promising
results. In this research work we apply k-Nearest Neighbours, both striking and thought-provoking. First, the user
eXtreme Gradient Boosting and Random Forest classifiers for adoption of various cryptocurrencies has really taken
detecting the trend problem of three cryptocurrency markets. We off, with billions in market cap and millions of
use these classifiers to design a strategy to trade in those markets.
Our input data in the experiments include price data with and wallets estimated to have been ‘active’ in 2016.
without technical indicators in separate tests to see the effect of Second, the cryptocurrency industry is both
using them. Our test results on unseen data are very promising globalised and localised, with borderless exchange
and show a great potential for this approach in helping investors
with an expert system to exploit the market and gain profit. Our operations, as well as geographically clustered
highest profit factor for an unseen 66 day span is 1.60. We also mining activities. Third, the industry is becoming
discuss limitations of these approaches and their potential impact more fluid, as the lines between exchanges and
on Efficient Market Hypothesis.
wallets are increasingly ‘blurred’ and a multitude of
cryptocurrencies, not just bitcoin, are now supported
Keywords— Market Prediction, Financial Decision Making, k-
NN Classifier, Extreme Gradient Boosting, Random Forest, by a growing ecosystem, fulfilling an array of
Quantitative Computation functions.” which has been quoted from a survey by
Cambridge Center for Alternative Finance in 2017, a
I. INT RODUCT ION
year which is not even comparable to what is the
Artificial Intelligence has widely been applied to prevalence of blockchain based technologies now.
different areas in the last decade and there have been As of the time of writing this, only BTC makes a
reported a lot of improvements in results by using its market cap of $1,042,689,199,152 and a 24 hour
applications. One of the very interesting areas of circulating volume of $57,794,818,577 (Today's
application is financial markets. There could be a lot Cryptocurrency Prices by Market Cap, 2021). As the
of improvements in exploiting these markets by dominance of BTC is 50 percent (Today's
means of artificial intelligence and machine learning. Cryptocurrency Prices by Market Cap, 2021) at the
Some cases of these applications include Loan Credit moment, the total market cap of cryptocurrenc ies
Scoring, Credit Evaluation, Sovereign Credit registered in Coin Market Cap database can be
Ratings, Mortgages Choice Decision, Portfolio estimated as about more than 2 thousand billion US
Management, Financial Performance Prediction and Dollars. This impressive amount of money shows a
Market Direction Prediction (Bahrammirzaee, great potential for this innovative use of technology
2010). with increasingly facing new challenges (like
In this paper we focus on the Market Directio n expensive transaction fees) and tackling them over
Prediction problem and we look at it as a data science with innovative solutions (like MicroCache
problem. (Almashaqbeh, Bishop, & Cappos, 2020)).
One of very innovative usages of new technolo gy The main goal of the methods described in this
in finance is cryptocurrencies. As we read in article are to determine if the price of the analysed
cryptocurrencies will move higher or lower in the 2020, p. 10) which has 47 different models compared
coming four hours. To do that we use a data channel with each other. Based on findings of this article the
directed to the Binance cryptocurrency exchange interest in using Market Information and Technica l
free available API and receive the data from the Indicators as inputs to models have increased in the
exchange’s database. Then we run some past few years. It also shows more attention to
preprocessing procedures on them and get them ensemble methods for this topic recently. Another
ready to be used as entry to our machine learning interesting finding in this survey is better accuracy
models. obtained by using Technical Indicator and Social
Three different machine learning methods have Networks data combined together in comparison
been used in this work. The first one is kNN as an with other data sources as input.
example-base learner and the last two ones being Second survey (Obthong, Tantisantiwo ng,
Random Forest and Gradient Boosting methods as Jeamwatthanachai, & Wills, 2020) points out
tree-base learners. These models have been advantages and disadvantages of using 23 differe nt
discussed in the “Methods and Materials” section. machine learning models with each other, which
Data used for these analyses are Open, High, Low, include k-NN and Random Forest. k-NN, described
Close and Volume data from three differe nt as a Classification and Forecasting Algorithm, has
cryptocurrency markets: ETH-USDT, LTC-BTC, been noted to have advantages of being robust to
ZEC-BTC. We have two sets of experiments for each noisy training data and being very efficient if the
model, one with this data being augmented by training datasets are large. It also points to the issue
technical indicators and one without them. of determining the best k for this algorithm and its
After explaining the models and the data, we high complexity in computation and memory
explore the implementation of these models in the limitations as its disadvantages. k-NN can be
“Proposed Method” section. sensitive to the local structure of the data based on
At the “Experimental Results” section we look at the findings in this survey (Archana & Elangova n,
the performance of these models in predicting the 2014) (Jadhav & Channe, 2016). In the same survey,
next four hour movement of the market in the test random forest has been categorized as another
data, which our learned models have not been Classification and Forecasting algorithm and for its
exposed to. advantages we read: “Robust method for forecasting
At the “Discussion” section we look at the and classification problems since its design that is
performance of our models and we discuss some filled with various decision trees, and the feature
different and debatable aspects of these methods and space is modelled randomly, automatically handles
the whole strategy design system and their relation missing values and works well with both discrete and
to Efficient Market Hypothesis. There are some continuous variables”. RF algorithm has been
improvements which can be made to this work and disadvantaged by the following points “Requires
we mention some of them in the “Conclusion and more computational power and resources because it
Future Works” section. creates a lot of trees and requires more time to train
than decision trees” (Obthong, Tantisantiwo ng,
II. RELAT ED WORKS
Jeamwatthanachai, & Wills, 2020, p. 5)
In this section we introduce three different surveys (Pradeepkumar & Ravi, 2017).
done on the topic of market direction prediction and Third survey (Kumar, Jain, & Singh, 2021)
also point to the previous usages of the impleme nted organises core Computational Intellige nce
methods in other studies. approaches for stock market forecasting in three
First Survey (Bustos & Pomares-Quimbaya, 2020, different classes including: Neural Network, Fuzzy
p. 8) shows a comprehensive taxonomy of stock Logic and Genetic Algorithm. It surveys applicatio n
market prediction algorithms based on machine of these models in markets of 19 different countries.
learning and their categories. This survey has also a Mostly used data for training models based on this
performance comparison of the stock market survey are Technical Indicators (Kumar, Jain, &
forecast models (Bustos & Pomares-Quimba ya, Singh, 2021, p. 15). It also shows that more research
has been done for American Markets (NYSE & 2015) known today as Extreme Gradient Boosting
NASDAQ) than other geographical locations. This (XGBoost) algorithm. It has been reported
survey concludes “identification of suitable pre- (Alessandretti, ElBahrawy, Aiello, & Baronchelli,
processing and feature selection techniques helps in 2018, p. 4) this method has been used in a number of
improving the accuracy of stock market forecasting winning Kaggle solutions (17/29 in 2015). XGBoost
models and computational intelligence approaches has been applied to the Bitcoin market in (Chen, Li,
can be effectively used to solve stock market & Sun, 2020, p. 12) and its accuracy has been
forecasting problem with high accuracy. Among reported 0.483. Another experiment on XGB-based
them hybrid models are predominant techniques methods has yielded 1.1 * 103 BTC (for their
applied to forecast stock market due to combined method 1) and ∼ 95 BTC (for their Method 2)
prediction capability of base models”. starting from 1 BTC (Alessandretti, ElBahrawy,
k-Nearest Neighbours algorithm (k-NN) is an Aiello, & Baronchelli, 2018, p. 7)
instance-base learner model first developed by (Fix,
III. M ET HODS AND MAT ERIALS
1985). This model has shown a good performance
regarding returns in financial markets. Applying this In this section we first look at the data used in this
model to Jordanian Stock Market has been reported project, then we get acquainted with three differe nt
to yield Total Squared RMS error of 0.263, RMS methods which have been used to make the models
error of 0.0378 and the average error of -5.434E-09 for the prediction task. We have tested other machine
for “AIEI” symbol (Alkhatib, Najadat, Hmeidi, & learning methods in our settings including: Ridge
Shatnawi, 2013). Another scheme of applying k-NN Classification (Rifkin, Yeo, & Poggio, 2003),
has been reported in (Chen & Hao, 2017) by the Logistic Regression (LaValley, 2008), Stochastic
name of “FWKNN”. It has been concluded in that Gradient Descent (Kabir, Siddique, Alam Kotwal, &
research: “The experiment results clearly show that Nurul Huda, 2015), Multi Layer Perceptron (Pal &
FWSVM-FWKNN stock analysis algorithm where Mitra, 1992), Support Vector Machines (Hearst,
the classification by FWSVM and the prediction by Dumais, Osuna, Platt, & Scholkopf, 1998), Gaussian
FWKNN, is robust, presenting signific a nt Process Classification (Csató, Fokoué, Opper,
improvement and good prediction capability for Schottky, & Winther, 1999), Gaussian Naïve Bayes
Chinese stock market indices over other compared (Webb, Keogh, & Miikkulainen, 2010) and Decision
model”. Trees (Rokach & Maimon, 2005). Our best results
Random Forests have been used since the late 90s were with the following methods, other methods
to overcome the over fitting problem in decision yielded negative profits or lesser profits relative to
trees (Ho, The random subspace method for the following methods (less than half of the profit
constructing decision forests, 1998). A variation of factors on average).
this algorithm has been applied to cryptocurrenc y 1. Used Data
market direction detection problem on 60 minutes Binance is a cryptocurrency exchange that
data in (Akyildirim, Goncu, & Sensoy, 2021). Their provides a platform for trading various
out-of-sample accuracy on BTC, ETH, LTC and cryptocurrencies. As of April 2021, Binance was the
ZEC has been reported 0.52, 0.53, 0.53 and 0.52 largest cryptocurrency exchange in the world in
respectively. They have used mostly OHLC and terms of trading volume (Top Cryptocurrency Spot
indicator-based data for their model training. They Exchanges, 2021).
also have concluded that their used algorithms Binance provides a free to use API for data
“demonstrate the predictability of the upward or gathering. This API is conveniently available to use
downward price moves” (Akyildirim, Goncu, & in python (Patro & Sahu, 2015). We use this API to
Sensoy, 2021, p. 27). gather Time stamp (in second precision), Open,
Gradient Boosting is a relatively old popular High, Low, Close and Volume for a 4 hours period
machine learning method in dealing with non-linear dataframe. This procedure runs for all three differe nt
problems (Friedman, 2001). Later a more efficie nt assets that we study: ETH-USDT, LTC-BTC and
variant of it has been developed by (Chen, et al.,
ZEC-BTC. Data gets gathered from mid-2017 until the Pavement Condition Index, 2019) (Piryonesi &
April 2021. This makes our raw input data. El-Diraby, Role of Data Analytics in Infrastruc ture
Asset Management: Overcoming Data Size and
2. First Classifier: k -Nearest Neighbours Vote
Quality Problems, 2020).
Neighbours-based models are type of instance- The training algorithm for random forests uses the
based learning or non-generalizing learning. They general technique of bootstrap aggregating, or
don’t attempt to construct a general internal model, bagging, to tree learners. Given a training set 𝑋 =
but simply store instances of the training data (hence 𝑥 , . . . , 𝑥 with labels 𝑌 = 𝑦 , . . . , 𝑦
1 𝑛 1 𝑛 bagging
called lazy learners). Classification is computed repeatedly (B times) selects a random sample with
from a sort of majority vote of the nearest neighbours replacement of the training set and fits trees to these
of each point: the point we are trying to classify is
samples:
assigned to the data class which has the most
for b=1, … , B:
representatives within the nearest neighbours of the I. Sample, with replacement, n training
point. Using distance metrics can sometimes
examples from 𝑋,𝑌; call these 𝑋𝑏,𝑌𝑏 .
improve the accuracy of the model. (Pedregosa, et II. Train a classification or regression tree 𝑓𝑏 on
al., 2011) These models are also beneficial for
𝑋𝑏,𝑌𝑏 .
regression problems.
After training, prediction for unseen sample 𝑥 ′can be
Suppose we have pairs (𝑋1 , 𝑌1 ), (𝑋2 , 𝑌2 ),…,
made by averaging the predictions from all the
(𝑋𝑛 , 𝑌𝑛 ) taking values in 𝑅 𝑑 × {1,2}, where Y is the individual regression trees on 𝑥 ′:
class label of X, so that 𝑋|𝑌 = 𝑟 ~𝑃𝑟 for 𝑟 = 1,2 (and 1
probability distributions 𝑃𝑟 ). Given some norm ||. || 𝑓̂ = 𝐵 ∑𝐵𝑏=1 𝑓𝑏 (𝑥 ′)
on 𝑅 𝑑 and a point 𝑥 ∊ 𝑅 𝑑 , let (𝑋(1) , 𝑌(1) ), or by taking the majority vote in the case of
(𝑋(2) , 𝑌(2) ), …, (𝑋(𝑛) , 𝑌(𝑛) ) be a reordering of the classification trees. (Lu, 2014)
training data such that ||𝑋(1) − 𝑥|| ≤. . . ||𝑋(𝑛) − 𝑥||. This bootstrapping procedure results in better
model performance because it decreases the variance
Now, by voting on 𝑋(𝑖) starting from 𝑖 = 1 and going of the model, without increasing the bias. This means
increasingly for 𝑖, we can do the classification task. that while the predictions of a single tree are highly
(Cannings, Berrett, & Samworth, 2020) susceptible to noise in its training set, the average of
We use Scikit-learn implementation (Pedregosa, et many trees is not, as long as the trees are not
al., 2011) of k-NN classifier in this project. correlated. Simply training many trees on a single
3. Second Classifier: Random Forest training set will produce strongly correlated trees (or
Random forests or random decision forests are even the same tree many times, if the training
classified as ensemble learning methods. They can algorithm is deterministic); bootstrap sampling is a
be applied to classification, regression and other way to de-correlate the trees by providing them
tasks that operate by constructing an assembly of different training sets. (Lu, 2014)
decision trees at training time and returning the class The number of samples/trees,𝐵, is a free
that is the mode of the classes (for classification) or parameter. Typically, a few hundred to several
mean/average prediction (for regression) of the thousand trees are used, depending on the size and
individual trees (Ho, Random decision forests, nature of the training set. An optimal number of
1995). “Random decision forests correct for decision trees, 𝐵, can be found using cross-validation, or by
trees' habit of over fitting to their training set” observing the out-of-bag error: the mean prediction
(Hastie, Tibshirani, & Friedman, 2009, pp. 587-588). error on each training sample 𝑥 𝑖, using only the trees
Random forests generally perform better than that did not have 𝑥 𝑖 in their bootstrap sample (James,
individually assisted decision trees, but their Witten, Hastie, & Tibshirani, 2013, pp. 316-321).
accuracy could be lower than gradient boosted trees. We use Scikit-learn implementation (Pedregosa, et
However, data characteristics can affect their al., 2011) of random forest classifier in this project.
performance (Piryonesi & El-Diraby, Data Analytics
in Asset Management: Cost-Effective Prediction of
1
4. Third Classifier: eXtreme Gradient Boosting 𝐿 𝑀𝑆𝐸 = (𝑦 − 𝐹(𝑥))2
2
Gradient boosting is a machine learning techniq ue 𝜕𝐿𝑀𝑆𝐸
for regression and classification problems, which ℎ𝑚 (𝑥) = − = 𝑦 − 𝐹(𝑥).
𝜕𝐹
like random forest, produces a prediction model in So, gradient boosting could be specialized to a
the form of an ensemble of weak prediction models, gradient descent algorithm, and generalizing it
typically decision trees. When a decision tree is the entails "plugging in" a different loss and its gradient
weak learner, the resulting algorithm is called (Li, 2021).
gradient boosted trees, which usually outperforms Now, with having an overview of boosted trees,
random forest (Piryonesi & El-Diraby, Using one may ask what are XGBoost trees? XGBoost is a
Machine Learning to Examine Impact of Type of tool motivated by the formal principle introduced.
Performance Indicator on Flexible Pavement More importantly, “it is developed with both deep
Deterioration Modeling, 2021) (Friedman, consideration in terms of systems optimization and
Tibshirani, & Hastie, 2009). It builds the model in a principles in machine learning”. “The goal of this
stage-wise fashion like other boosting methods do, library is to push the extreme of the computatio n
and it generalizes them by allowing optimization of limits of machines to provide a scalable, portable and
an arbitrary differentiable loss function. accurate library” (Chen & Guestrin, Xgboost: A
Like other boosting methods, gradient boosting scalable tree boosting system, 2016). We use this
combines weak "learners" into a single strong learner library for our implementations of the solution.
in an iterative fashion. It is easiest to explain in the
IV. PROPOSED MET HODS
least-squares regression setting, where the goal is to
"teach" a model 𝐹 to predict values of the form 𝑦̂ = In this section we look at our proposed methods
𝐹(𝑥) by minimizing the mean squared error for market direction problem in cryptocurrenc y
1 markets. First, we fill in details about our raw data
∑𝑖 (𝑦̂𝑖 − 𝑦𝑖 )2 where 𝑖 indexes over some training
𝑛 gathering procedure. Then at the second subsection,
set of size 𝑛 of actual values of the output variable 𝑦. we elaborate on our pre-processing steps for the
So we have following definition: obtained raw financial data. We also explain the
𝑦̂ 𝑖= The Predicted Value 𝐹(𝑥) dataset creation part of the scheme at this subsection.
𝑦𝑖= The Observed Value The third step, sums up the definition of our three
𝑛= The Number of Samples in 𝑦 different models. We also make some concise points
Now, let us consider a gradient boosting algorithm about hyperparameters of each model. Last
with 𝑀 stages. At each stage 𝑚 (1 ≤ 𝑚 ≤ 𝑀) of subsection looks at evaluation of results and
gradient boosting, suppose some imperfect model 𝐹𝑚 concludes the strategy design part of the system.
(for low 𝑚 this model may simply return 𝑦̂𝑖 = 𝑦̅, Figure 1 (look at page 8) shows a comprehens ive
where the right-hand side is the mean of 𝑦). In order view of the whole system, green lines indicate train
to improve 𝐹𝑚 , our algorithm should add some new phase and red lines indicate exertion phase.
estimator, ℎ𝑚 (𝑥). Thus, 1. Raw Data Gathering
𝐹𝑚 +1 (𝑥) = 𝐹𝑚 (𝑥) + ℎ𝑚 (𝑥) = 𝑦
At the time of doing this research, Binance has
or, equivalently,
made available, access to its historical records (for
ℎ𝑚 (𝑥) = 𝑦 − 𝐹𝑚 (𝑥).
Open, High, Low, Close and Volume) through its
Therefore, gradient boosting will fit ℎ to the residual
API for time frames bigger than one minute. We
𝑦 − 𝐹𝑚 (𝑥). As in other boosting variants, each 𝐹𝑚 +1
gather 4 hour period data to a Pandas dataframe since
attempts to correct the errors of its predecessor 𝐹𝑚 . its first available timestamp (which is usually mid
A generalization of this idea to loss functions other 2017). The data includes OHLCV for ETH-USDT,
than squared error, and to classification and ranking LTC-BTC, ZEC-BTC. As cryptocurrency markets
problems, follows from the observation that are very dynamic environments (price and return
residuals ℎ𝑚 (𝑥) for a given model are the negative levels can be changed dramatically just in some
gradients of the mean squared error (MSE) loss months) we opt to have as much as recent data as we
function (with respect to 𝐹(𝑥)):
can for the current state of the market, so we decided original A symbol). So, we define our threshold in
to use 95% of the data for training and the remaining this project as about 0.15 percent of the price
5% to evaluate the models (which makes the test data movement in the 4 hour period. To sum up, if an
time span almost 66 days). In practical application of asset’s value changes more than this threshold in a
this system we can also retrain the models in a period positive direction, we label that as “1” and otherwise
shorter than this 66 days’ time span. we label it as “0”, This way per any label=1 if we
had entered the market at that point we would make
2. Pre Processing and Dataset Creation
profit.
After gathering the data, we make two copies of it.
For one copy, we augment it with some famous 3. Model definition- Model Training
Technical Indicators in finance. Essentially these At this subsection we look at the libraries and
indicators are some mathematical functions which hyperparameters involved in each model. We also
take some arguments from real time or past data and note each model's training time. A more elaborate
they create some insights about “technical” moves of discussion about the hyper parameters is held in the
the market. Name and formula for these technica l Discussion section.
indicators have been reported in the Appendix A. kNN model and random forest have been
The other copy doesn’t include these technica l implemented using open source machine learning
indicators data. library Scikit-learn. Scikit-learn features various
After augmentation part we have two dataframes classification, regression and clustering algorithms
including all relevant data for each record. Now, two including support vector machines, random forests,
things must be done to make our datasets a suitable gradient boosting, k-means and DBSCAN, and is
one for our models: 1- We need to encapsulate all the designed to interoperate with the Python numeric a l
features used for identifying a data point for each one and scientific libraries NumPy and SciPy
of them, 2- We need to label each datapoint. (Pedregosa, et al., 2011). An important design note
For this project we use the last financial records about scikit-learn is its unified interface for its
plus 59 records proceeding it as its features. These models. If user’s data suffices this interface
records are in a 4 hour period and all of the produced requirements, it’s easy to use and change models to
features are numerical. We normalize them by using use for the same data.
the Feature Scaling method (Patro & Sahu, 2015). XGB has been implemented using XGBoost.
Each value gets divided to its maximum value minus XGBoost is an optimized distributed gradient
its minimum. boosting library designed to be highly efficie nt,
To encapsulate the feature data for each datapoint flexible and portable. It implements machine
we take all the 60 rows (and 19 parameters for learning algorithms under the Gradient Boosting
augmented version and 5 parameters for framework. XGBoost provides a parallel tree
unaugmented version at each row) from our boosting (also known as GBDT, GBM) that solve
dataframes and put all those variables inside another many data science problems in a fast and accurate
array named X. So, each 𝑋𝑖 will be a datapoint with way (Chen & Guestrin, Xgboost: A scalable tree
1140 parameters for augmented version and with 300 boosting system, 2016).
parameters for unaugmented version. Hyperparameters involved in kNN classifier are as
To label each datapoint we define a threshold to follows:
determine if retrospectively we would have entered
the market at that timestamp, after 4 hours we would Number of Neighbours: Depended on The Dataset
make profit or loss? This threshold gets defined (5 for ETHUSDT, 20 for LTCBTC, 100 for
using the fees per each cryptocurrency exchanger. At ZECBTC)
the time of doing this research the least possible fee Weight Function Used in Prediction: Distance
to exchange in the market in Binance was 0.15
percent (0.075 percent to exchange from A symbol Algorithm Used to Compute The Nearest
to B symbol and 0.075 to exchange from B to Neighbours: Auto: will attempt to decide the most
appropriate algorithm between BallTree, KDTree Alpha (L1 regularization term on weights.
and Brute Force based on the values passed to fit Increasing this value will make model more
method. conservative.): 0

Leaf Size: 30 Training and evaluation of the models in this


project has been done using Colab virtual machines
The Distance Metric to Use for The Tree: by google. Training time takes the most for Random
Minkowski Forest with an average of 167.97 seconds. Second
place goes to XGB with an average of 46.85 seconds
Power Parameter for The Minkowski Metric: 2 and finally kNN takes only 1.06 seconds on average
to be trained for these datasets.
Hyperparameters involved in Random Forest 4. Evaluation and Strategy Design
classifier are as follows:
To evaluate each model in this project we use two
The number of trees in the forest: Depended on The different methods: Accuracy of The Model and The
Profit Obtained by The Model. By accuracy in this
Dataset (700 for ETHUSDT and ZECBTC, 1000 for
LTCBTC) context, we mean how many times the predicted
label for the market direction matches with the real
The Function to Measure The Quality of A Split: direction of the market. To discuss how we calculate
gini the obtained profit, we need to understand how we
use the models to create the strategy.
The Maximum Depth of The Tree: Nodes are Strategy Design procedure is pretty
expanded until all leaves are pure or until all leaves straightforward. We took 60 rows of records from
contain less than the minimum number of samples now and past data and then we decide if the price will
required to split an internal node samples. go up enough to cover the exchange’s fee? If we
predict it will, we enter the market and after 4 hours
The minimum number of samples required to split we retry this operation to decide for the next 4 hours.
an internal node: 2 If the next 4 hours still shows an adequate positive
movement, we keep the buy position and if it does
Hyperparameters involved in XGB classifier are not, we sell what we have bought. Now, our profit is
as follows: the difference between the values of bought and sold
assets. It will accumulate this positive or negative
Booster: gbtree profit through the test span. Notice that our position
size stays the same at each buying or selling trade.
Eta (alias: Learning Rate): 0.3 At the final step of the strategy we sell whatever we
have. Another evaluative indicator for strategy
Minimum Loss Reduction Required to Make A assessments in financial markets is Profit Factor,
Further Partition on A Leaf Node of The Tree (The which is defined as: “The gross profit divided by the
larger gamma is, the more conservative the gross loss (including commissions) for the entire
algorithm will be.): 0 trading period”. We calculate this metric for each
Maximum Depth of A Tree: 6 model and each asset. In the next section we look at
the results of our experiments with our models.
Lambda (L2 regularization term on weights.
Increasing this value will make model more
V. EXPERIMENT AL RESULT S
conservative.): 1
Here we look at three different cryptocurrenc ie s
that we study, separately. This section has three
subsections relative to each cryptocurrency pair. At
each subsection, first, we have a graph of the pair’s
price movements through the time span that we
scrutinize it. Then, we have a graph that shows the
normalized returns of that pair through the time. The
mentioned graph shows what we are trying to
predict. The third graph is the pair's price movements
through its test phase. After that, we have
performance graphs for both augmented and origina l
input data. Performance is assessed with a
cumulative reward graph which shows how much
money we have earned with a fixed position at each
time we entered or exited the market. Finally, we
have some information regarding the test of models
and a distribution graph of each model’s (positive or
negative) profits. For the sake of concision, for the
unaugmented experiments we just report the
performance graphs.

Figure 1. Overall Structure of The Proposed Expert System. Green lines indicate train phase and red lines
indicate exertion phase
ETH-USDT:

Figure 2. Close Price for ETH-USDT from 2017-07 to 2021-05

Figure 3. Normalized Return for ETH-USDT from 2017-07 to 2021-07


Figure 3. Normalized Close Price for ETH-USDT in Test Data

Figure 4. Performance of The k-NN Model for ETH-USDT in Unaugmented Test Data

Figure 5. Performance of The k-NN Model for ETH-USDT in Augmented Test Data
Figure 6. Performance of The RF Model for ETH-USDT in Unaugmented Test Data

Figure 7. Performance of The RF Model for ETH-USDT in Augmented Test Data

Figure 8. Performance of The XGB Model for ETH-USDT in Unaugmented Test Data
Figure 9. Performance of The XGB Model for ETH-USDT in Augmented Test Data

Testing Accuracy 0.519900 Testing Accuracy 0.562189

Net Profit 575.810 Net Profit 672.80

Number of Winning Trades 105 Number of Winning Trades 166

Number of Losing Trades 82 Number of Losing Trades 125

Total Days in Test 66 Total Days in Test 66

Percent of Profitable Trades 56.15% Percent of Profitable Trades 57.04%

Avg Win Trade 29.680 Avg Win Trade 29.782

Avg Los Trade -30.983 Avg Los Trade -34.168

Largest Win Trade 177.820 Largest Win Trade 135.050

Largest Los Trade -161.700 Largest Los Trade -158.100

Profit Factor 1.23 Profit Factor 1.16

Table 1. Information Regarding k-NN Test on ETH-USDT Table 2. Information Regarding RFTest on ETH-USDT
Testing Accuracy 0.547264

Net Profit 860.940

Number of Winning Trades 120

Number of Losing Trades 90

Total Days in Test 66

Percent of Profitable Trades 57.14%

Avg Win Trade 36.302

Avg Los Trade -38.836

Largest Win Trade 174.820

Largest Los Trade -158.100


Figure 10. Distribution of Profits for k-NN in ETH-USDT
Profit Factor 1.25

Table 3. Information Regarding XGB Test on ETH-USDT

Figure 11. Distribution of Profits for RF in ETH-USDT Figure 12. Distribution of Profits for XGB in ETH-USDT
LTC-BTC:

Figure 13. Close Price for LTC-BTC from 2017-07 to 2021-07

Figure 14. Normalized Return for LTC-BTC from 2017-07 to 2021-07


Figure 15. Normalized Close Price for LTC-BTC in Test Data

Figure 16. Performance of The k-NN Model for LTC-BTC in Unaugmented Test Data

Figure 17. Performance of The k-NN Model for LTC-BTC in Augmented Test Data
Figure 18. Performance of The RF Model for LTC-BTC in Unaugmented Test Data

Figure 19. Performance of The RF Model for LTC-BTC in Augmented Test Data

Figure 20. Performance of The XGB Model for LTC-BTC in Unaugmented Test Data
Figure 21. Performance of The XGB Model for LTC-BTC in Augmented Test Data

Testing Accuracy 0.585956 Testing Accuracy 0.467312


Net Profit 0.0005090 Net Profit 0.0004430
Number of Winning Trades 46 Number of Winning Trades 71
Number of Losing Trades 40 Number of Losing Trades 65
Total Days in Test 66 Total Days in Test 66
Percent of Profitable Trades 53.49% Percent of Profitable Trades 52.21%
Avg Win Trade 0.00006 Avg Win Trade 0.00006
Avg Los Trade -0.00005 Avg Los Trade -0.00006
Largest Win Trade 0.00024 Largest Win Trade 0.00027
Largest Los Trade -0.00019 Largest Los Trade -0.00029
Profit Factor 1.24 Profit Factor 1.12

Table 4. Information Regarding k-NN Test on LTC-BTC Table 5. Information Regarding RF Test on LTC-BTC
Testing Accuracy 0.520581

Net Profit 0.0006720

Number of Winning Trades 88

Number of Losing Trades 91

Total Days in Test 66

Percent of Profitable Trades 49.16%

Avg Win Trade 0.00004

Avg Los Trade -0.00003

Largest Win Trade 0.00024


Figure 22. Distribution of Profits for k-NN in LTC-BTC
Largest Los Trade -0.00024

Profit Factor 1.22

Table 6. Information Regarding XGB Test on LTC-BTC

Figure 23. Distribution of Profits for RF in LTC-BTC Figure 24. Distribution of Profits for XGB in LTC-BTC
ZEC-BTC:

Figure 25. Close Price for ZEC-BTC from 2017-07 to 2021-07

Figure 26. Normalized Close Price for ZEC-BTC in Test Data


Figure 27. Normalized Close Price for ZEC-BTC in Test Data

Figure 28. Performance of The k-NN Model for ZEC-BTC in Unaugmented Test Data

Figure 29. Performance of The k-NN Model for ZEC-BTC in Augmented Test Data
Figure 30. Performance of The RF Model for ZEC-BTC in Unaugmented Test Data

Figure 31. Performance of The RF Model for ZEC-BTC in Augmented Test Data

Figure 32. Performance of The XGB Model for ZEC-BTC in Unaugmented Test Data
Figure 33. Performance of The XGB Model for ZEC-BTC in Augmented Test Data

Testing Accuracy 0.521277 Testing Accuracy 0.510638

Net Profit 0.0003430 Net Profit 0.0007550

Number of Winning Trades 21 Number of Winning Trades 87

Number of Losing Trades 22 Number of Losing Trades 85

Total Days in Test 66 Total Days in Test 66

Percent of Profitable Trades 48.84% Percent of Profitable Trades 50.58%

Avg Win Trade 0.00004 Avg Win Trade 0.00004

Avg Los Trade -0.00002 Avg Los Trade -0.00004

Largest Win Trade 0.00015 Largest Win Trade 0.00020

Largest Los Trade -0.00010 Largest Los Trade -0.00014

Profit Factor 1.63 Profit Factor 1.25

Table 7. Information Regarding k-NN Test on ZEC-BTC Table 8. Information Regarding RF Test on ZEC-BTC
Testing Accuracy 0.518617

Net Profit 0.000293

Number of Winning Trades 46

Number of Losing Trades 49

Total Days in Test 66

Percent of Profitable Trades 48.42%

Avg Win Trade 0.00005

Avg Los Trade -0.00004

Largest Win Trade 0.00045 Figure 34. Distribution of Profits for k-NN on ZEC-BTC

Largest Los Trade -0.00021

Profit Factor 1.14

Table 9. Information Regarding XGB Test on ZEC-BTC

Figure 36. Distribution of Profits for XGB on ZEC-BTC


Figure 35. Distribution of Profits for RF on ZEC-BTC
VI. DISCUSSION intelligence based systems? If that would be the case,
In this section we discuss how our models have it’s obvious that our formulation of EMH should
been performing through different market change accordingly. Maybe the hidden patterns
conditions. We also talk about how these results inside a market can be exploited to some extent and
challenge the Efficient Market Hypothesis (EMH) in this extent is determined by the behaviour of the
the context of cryptocurrency markets and how one exploiters. But of course due to the laws of
can implement practically these models and exploit thermodynamics there will be a limit for this exploit.
the market. We also note the limitations and It can be definitely said due to the second law of
differences between response times of our models. thermodynamics, a system’s entropy increases and
All our three studied cryptocurrency pairs show this eventually makes that system unstable for
different market conditions through our models train exploitation. So, in this regard different algorithms
phases (i.e. all of them have bullish, bearish and can exist which compete with each other in differe nt
range movements), although frequency of these market dynamics and some of the times some of
moves are not equal and this could make effects on them can be superior to others and create profit.
the results. Let’s compare test results on late April These algorithms efficiency can be related to their
2021 fall of ETH-USDT. By comparing figure 3 and “intelligence” level in choosing the proper action in
figure 4 we see k-NN based strategy has not fallen in the market and also on how other participants in the
equity during that span, but figures 5 and 6 show that market are behaving.
XGB and Random Forest have fallen there, although There were two important factors of tuning our
the overall smoothness of the last two models is studied models: Hyperparameters and Labelling
better. Again, if we take figure 11 as a reference and Sensitivity Threshold. Each discussed model has its
compare figures 12 and 14 with it, we see how own hyperparameters and changing them affected
models have avoided bearish markets. Figure 14 the results significantly. Labelling Sensitivity
shows a model which, although being positive in the Threshold was another consequential parameter in
final returns, does not look good for practical usage. our experiments. This parameter defines to which
Cumulative results in 66 days for all models show a extent the return should be, to be considered a
positive return. positive return for the model. Usually, it should be at
Based on the obtained results in this study it can least greater than the exchange’s fee to denote a
easily be seen that augmenting the input data with profitable trade, but tweaking with it yields differe nt
technical indicators has a significant positive effect results. One can use grid searching in availab le
on the final returns for these models. The extent of values for these tunings. There may be a need to
this effect can be moving from a negative return to a reconfigure them from time to time.
positive one. As it has been shown in this project, models
“The efficient market hypothesis (EMH) is a back- perform differently in different markets. Beside the
breaker for forecasters. In its crudest form it generated profit, each machine learning model can
effectively says that the series we would very much have its own pros and cons. For example, in our
like to forecast, the returns from speculative assets, experiments, k-NN usually took about 7.5 seconds to
are unforecastable. The EMH was proposed based on predict the label where Random Forest took about
the overpowering logic that if returns were 0.13 seconds and XGB took only 0.008 seconds.
forecastable, many investors would use them to These differences will make each of them preferable
generate unlimited profits. The behaviour of market to another based on the contexts.
participants induce returns that obey the EMH, All of what has been discussed till now are
otherwise there would exist a ‘money-machine’ theoretical arguments, implications of these models
producing unlimited wealth, which cannot occur in a look very attractive but it definitely will bring up
stable economy.” (Timmermann & Granger, 2004) new issues and more research needs to be done.
The point here is, what if some patterns exist in the Many exchanges nowadays allow automatic traders
market dynamics but are not visible to ordinary users to act in their provided markets. One can use these
and they could only be discovered through artific ia l exchanges data and process them inside the
introduced schemes and decides and trades based on 5. Using Deep Reinforcement Learning to
them in hope of profit. As cryptocurrency markets design sophisticated strategies directly with
are almost always available (i.e. 24/7) using a the aim of enhancing performance
dedicated server can find trade opportunities and acts 6. Using machine learning approaches for risk
on them automatically. management in a collateral system to
decision making
VII. CONCLUSIONS AND FUT URE WORKS
Besides what we have discussed about financ ia l
The impact of artificial intelligence’s applicatio ns markets, it seems machine learning models can be
in many areas are promising for a more efficient and used in many other chaotic natured problems which
prosperous future. In this study we looked at three share some of their data characteristics with financ ia l
different machine learning approaches to help data. These fields could include supply chain
investors to make their decisions in some new support, Business affairs with public opinions,
emerging international markets in a more data driven public views on political issues and many other use
and autonomous manner. We showed how using cases.
technical indicators can improve the results of the
prediction system. We also addressed a simple
strategy design framework to use these models.
Although all of our models showed positive returns
and a maximum of 1.60 profit factor for ZEC-BTC
by k-NN in 66 days and a minimum profit factor of
1.12 for LTC-BTC by Random Forest, it’s obvious
more research needs to be done in this area. The
resulting strategies still lack “smoothness” in their
equity graphs and hence showing large potential
risks to be implemented. Designing a full
autonomous trading system surely involves more
concerns than the ones we had simplified in this
research work, like market liquidity issues. We also
discussed how these new and uprising technologic a l
advancements can cast a shadow on some long
lasting hypothesis in finance like Efficient Market
Hypothesis.
As we can see, there seems a predictability
potential in a highly complex system like financ ia l
markets by means of machine learning. For future
works, our suggestions include:
1. Combining Fundamental Information with
Technicals to improve the accuracy
2. Ensembling different approaches in machine
learning to decrease the bias of the whole
system
3. Using social networks data streams to obtain
an accumulated view on public opinion on
different assets
4. Using Deep neural networks to feature
extraction from raw data
VIII. REFERENCES Chen, Y., & Hao, Y. (2017). A feature weighted
support vector machine and K-nearest
neighbor algorithm for stock market indices
Akyildirim, E., Goncu, A., & Sensoy, A. (2021). prediction. Expert Systems with
Prediction of cryptocurrency returns using Applications, 80, 340-355.
machine learning. Annals of Operations Chen, Z., Li, C., & Sun, W. (2020). Bitcoin price
Research, 297, 3-36. prediction using machine learning: An
Alessandretti, L., ElBahrawy, A., Aiello, L. M., & approach to sample dimension engineering.
Baronchelli, A. (2018). Anticipating Journal of Computational and Applied
cryptocurrency prices using machine Mathematics, 365.
learning. Complexity. Csató, L., Fokoué, E., Opper, M., Schottky, B., &
Alkhatib, K., Najadat, H., Hmeidi, I., & Shatnawi, Winther, O. (1999). Efficient approaches to
M. (2013). Stock price prediction using k- Gaussian process classification. Advances in
nearest neighbor (kNN) algorithm. neural information processing systems, 12.
International Journal of Business, Fix, E. (1985). Discriminatory analysis:
Humanities and Technology, 3(3), 32-44. nonparametric discrimination, consistency
Almashaqbeh, G., Bishop, A., & Cappos, J. (2020). properties (Vol. 1).
MicroCash: Practical Concurrent Processing Friedman, J. (2001). Greedy function
of Micropayments. Lecture Notes in approximation: a gradient boosting machine.
Computer Science, 12059. Annals of statistics, 29(5), 1189-1232.
Archana, S., & Elangovan, K. (2014). Survey of Friedman, J. H., Tibshirani, R., & Hastie, T. (2009).
classification techniques in data mining. 10. Boosting and Additive Trees. In The
International Journal of Computer Science Elements of Statistical Learning (2nd ed.,
and Mobile Applications, 2(2), 65-71. pp. 337–384). Springer.
Bahrammirzaee, A. (2010). A comparative survey Hastie, T., Tibshirani, R., & Friedman, J. (2009).
of artificial intelligence applications in The Elements of Statistical Learning: Data
finance: artificial neural networks, expert Mining, Inference, and Prediction (2nd ed.,
system and hybrid intelligent systems. Vol. 1). Stanford, CA: Springer.
Neural Computing and Applications, 19(8), Hearst, M. A., Dumais, S. T., Osuna, E., Platt, J., &
1165-1195. Scholkopf, B. (1998). Support vector
Bustos, O., & Pomares-Quimbaya, A. (2020). Stock machines. IEEE Intelligent Systems and
market movement forecast: A Systematic their applications, 13(4), 18-28.
review. Expert Systems with Applications, Hileman, G., & Rauchs, M. (2017). Global
156. cryptocurrency benchmarking study (Vol.
Cannings, T. I., Berrett, T. B., & Samworth, R. J. 33). Cambridge Centre for Alternative
(2020). Local nearest neighbour Finance.
classification with applications to semi- Ho, T. K. (1995). Random decision forests.
supervised learning. The Annals of Proceedings of 3rd international conference
Statistics, 1789-1814. on document analysis and recognition, 1,
Chen, T., & Guestrin, C. (2016). Xgboost: A 278-282.
scalable tree boosting system. Proceedings Ho, T. K. (1998). The random subspace method for
of the 22nd acm sigkdd international constructing decision forests. IEEE
conference on knowledge discovery and transactions on pattern analysis and
data mining. machine intelligence, 20(8), 832-844.
Chen, T., He, T., Benesty, M., Khotilovich, V., Jadhav, S., & Channe, H. (2016). Comparative
Tang, Y., & Cho, H. (2015). Xgboost: Study of K-NN, Naive Bayes and Decision
extreme gradient boosting. Tree Classification Techniques.
International Journal of Science and Learning in Python. the Journal of machine
Research (IJSR), 5(1), 1842 - 1845. Learning research, 12, 2825-2830.
James, G., Witten, D., Hastie, T., & Tibshirani, R. Piryonesi, S., & El-Diraby, T. (2019). Data
(2013). An Introduction to Statistical Analytics in Asset Management: Cost-
Learning with Applications in R. New York, Effective Prediction of the Pavement
NY: Springer. Condition Index. Journal of Infrastructure
Kabir, F., Siddique, S., Alam Kotwal, M. R., & Systems, 26(1).
Nurul Huda, M. (2015). Bangla text Piryonesi, S., & El-Diraby, T. (2020). Role of Data
document categorization using stochastic Analytics in Infrastructure Asset
gradient descent (sgd) classifier. 2015 Management: Overcoming Data Size and
International Conference on Cognitive Quality Problems. Journal of
Computing and Information Processing Transportation Engineering, 146(2).
(CCIP), 1-4. Piryonesi, S., & El-Diraby, T. (2021). Using
Kumar, G., Jain, S., & Singh, U. P. (2021). Stock Machine Learning to Examine Impact of
Market Forecasting Using Computational Type of Performance Indicator on Flexible
Intelligence: A Survey. Archives of Pavement Deterioration Modeling. Journal
Computational Methods in Engineering, 28, of Infrastructure Systems, 27(2).
1069–1101. Pradeepkumar, D., & Ravi, V. (2017). Forecasting
LaValley, M. P. (2008). Logistic regression. financial time series volatility using particle
Circulation, 117(18), 2395-2399. swarm optimization trained quantile
Li, C. (2021). A Gentle Introduction to Gradient regression neural network. Applied Soft
Boosting. College of Computer and Computing, 58, 35-52.
Information Science, Northeastern Rifkin, R., Yeo, G., & Poggio, T. (2003).
University. Retrieved 4 24, 2021, from Regularized least-squares classification.
http://www.chengli.io/tutorials/gradient_boo Nato Science Series Sub Series III Computer
sting.pdf and Systems Sciences, 131-154.
Lu, H. (2014, December 2). Intro to Random Rokach, L., & Maimon, O. (2005). Decision trees.
Forest. Retrieved from Houliang | Coding In Data mining and knowledge discovery
and Learning: handbook (pp. 165-192). Boston: Springer.
http://houlianglv.github.io/archives/2014/12 Timmermann, A., & Granger, C. (2004). Efficient
/ market hypothesis and forecasting.
Obthong, M., Tantisantiwong, N., International Journal of Forecasting, 20,
Jeamwatthanachai, W., & Wills, G. (2020). 15-27.
A Survey on Machine Learning for Stock Today's Cryptocurrency Prices by Market Cap.
Price Prediction: Algorithms and (2021, 4 21). Retrieved from Coin Market
Techniques. Proceedings of the 2nd Cap: https://coinmarketcap.com/
International Conference on Finance, Top Cryptocurrency Spot Exchanges. (2021, 4 24).
Economics, Management and IT Business. Retrieved from Coin Market Cap:
Pal, S. K., & Mitra, S. (1992). Multilayer https://coinmarketcap.com/rankings/exchan
perceptron, fuzzy sets, and classification. ges/
IEEE Transactions on Neural Networks, Webb, G. I., Keogh, E., & Miikkulainen, R. (2010).
3(5), 683-697. Naïve Bayes. In Encyclopedia of machine
Patro, S., & Sahu, K. K. (2015). Normalization: A learning (pp. 713-714).
preprocessing stage. arXiv preprint,
arXiv:1503.06462.
Pedregosa, F., Varoquaux, G., Gramfort, A.,
Michel, V., Thirion, B., Grisel, O., . . .
Vanderplas, J. (2011). Scikit-learn: Machine
APPENDIX A: USED TECHNICAL We have used this indicator in 14 and 30 periods
in this project.
INDICATORS AND THEIR FORMULAS

In this appendix we introduce the technica l Directional Movement Index (DMI):


indicators used in this project and their respective
formulas. |𝐷𝐼 + − 𝐷𝐼 − |
𝐷𝑋 = ( + ) ∗ 100
|𝐷𝐼 + 𝐷𝐼 − |
where:
𝑆𝑚𝑜𝑜𝑡ℎ𝑒𝑑 (𝐷𝑀+ )
Commodity Channel Index (CCI): 𝐷𝐼 + = ( ) ∗ 100
𝐴𝑇𝑅

𝑆𝑚𝑜𝑜𝑡ℎ𝑒𝑑 (𝐷𝑀− )
𝑇𝑦𝑝𝑖𝑐𝑎𝑙 𝑃𝑟𝑖𝑐𝑒 − 𝑀𝐴 𝐷𝐼 = ( ) ∗ 100
𝐶𝐶𝐼 = 𝐴𝑇𝑅
0.015 ∗ 𝑀𝑒𝑎𝑛 𝐷𝑒𝑣𝑖𝑎𝑡𝑖𝑜𝑛 𝐷𝑀+ (𝐷𝑖𝑟𝑒𝑐𝑡𝑖𝑜𝑛𝑎𝑙 𝑀𝑜𝑣𝑒𝑚𝑒𝑛𝑡) = 𝐶𝑢𝑟𝑟𝑒𝑛𝑡 𝐻𝑖𝑔ℎ − 𝑃𝑟𝑒𝑣𝑖𝑜𝑢𝑠 𝐻𝑖𝑔ℎ
where: 𝐷𝑀−(𝐷𝑖𝑟𝑒𝑐𝑡𝑖𝑜𝑛𝑎𝑙 𝑀𝑜𝑣𝑒𝑚𝑒𝑛𝑡) = 𝑃𝑟𝑒𝑣𝑖𝑜𝑢𝑠 𝐿𝑜𝑤 − 𝐶𝑢𝑟𝑟𝑒𝑛𝑡 𝐿𝑜𝑤
𝑃 𝐴𝑇𝑅 = 𝐴𝑣𝑒𝑟𝑎𝑔𝑒 𝑇𝑟𝑢𝑒 𝑅𝑎𝑛𝑔𝑒
𝑃𝑒𝑟𝑖𝑜𝑑
𝑇𝑦𝑝𝑖𝑐𝑎𝑙 𝑃𝑟𝑖𝑐𝑒 = ∑((𝐻𝑖𝑔ℎ + 𝐿𝑜𝑤 + 𝐶𝑙𝑜𝑠𝑒)/3) ∑𝑃𝑒𝑟𝑖𝑜𝑑 𝑥
𝑡=1
𝑖=1 𝑆𝑚𝑜𝑜𝑡ℎ𝑒𝑑 (𝑥) = ∑ 𝑥 − + 𝐶𝐷𝑀
𝑃 = 𝑁𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑃𝑒𝑟𝑖𝑜𝑑𝑠 𝑃𝑒𝑟𝑖𝑜𝑑
𝑡 =1
𝑀𝐴 = 𝑀𝑜𝑣𝑖𝑛𝑔 𝐴𝑣𝑒𝑟𝑎𝑔𝑒 𝐶𝐷𝑀 = 𝐶𝑢𝑟𝑟𝑒𝑛𝑡 𝐷𝑀
𝑃
We have used this indicator with period=14 in this
𝑀𝑜𝑣𝑖𝑛𝑔 𝐴𝑣𝑒𝑟𝑎𝑔𝑒 = (∑ 𝑇𝑦𝑝𝑖𝑐𝑎𝑙 𝑃𝑟𝑖𝑐𝑒)/𝑃 project.
𝑖=1
𝑃

𝑀𝑒𝑎𝑛 𝐷𝑒𝑣𝑖𝑎𝑡𝑖𝑜𝑛 = (∑ |𝑇𝑦𝑝𝑖𝑐𝑎𝑙 𝑃𝑟𝑖𝑐𝑒 − 𝑀𝐴| )/𝑃


𝑖 =1
We have used this indicator in 14 and 30 periods Moving Average Convergence Divergence
in this project. (MACD):

𝑀𝐴𝐶𝐷 = 𝐸𝑀𝐴12 𝑃𝑒𝑟𝑖𝑜𝑑 − 𝐸𝑀𝐴26 𝑃𝑒𝑟𝑖𝑜𝑑

Relative Strength Index (RSI):


Bollinger Band®:
100
𝑅𝑆𝐼𝑆𝑡𝑒𝑝 𝑂𝑛𝑒 = 100 − [ ] 𝐵𝑜𝑙𝑙𝑈 + 𝐵𝑜𝑙𝑙𝐷
𝐴𝑣𝑒𝑟𝑎𝑔𝑒 𝐺𝑎𝑖𝑛 𝐵𝑜𝑙𝑙 =
1+
𝐴𝑣𝑒𝑟𝑎𝑔𝑒 𝐿𝑜𝑠𝑠 2
The average gain or loss used in the calculation is 𝐵𝑜𝑙𝑙𝑈 = 𝑀𝐴(𝑇𝑃, 𝑛) + 𝑚 ∗ 𝜎[𝑇𝑃, 𝑛]
the average percentage gain or loss during a look- 𝐵𝑜𝑙𝑙𝐷 = 𝑀𝐴(𝑇𝑃, 𝑛) − 𝑚 ∗ 𝜎[𝑇𝑃, 𝑛]
back period. The formula uses a positive value for where:
the average loss. 𝐵𝑜𝑙𝑙𝑈 = 𝑈𝑝𝑝𝑒𝑟 𝐵𝑜𝑙𝑙𝑖𝑛𝑔𝑒𝑟 𝐵𝑎𝑛𝑑
Once there is first step data available, the second 𝐵𝑜𝑙𝑙𝐷 = 𝐿𝑜𝑤𝑒𝑟 𝐵𝑜𝑙𝑙𝑖𝑛𝑔𝑒𝑟 𝐵𝑎𝑛𝑑
part of the RSI formula can be calculated. The 𝑀𝐴 = 𝑀𝑜𝑣𝑖𝑛𝑔 𝐴𝑣𝑒𝑟𝑎𝑔𝑒
second step of the calculation smooths the results: 𝑇𝑃 (𝑇𝑦𝑝𝑖𝑐𝑎𝑙 𝑃𝑟𝑖𝑐𝑒) = (𝐻𝑖𝑔ℎ + 𝐿𝑜𝑤 + 𝐶𝑙𝑜𝑠𝑒)/3
𝑛 = 𝑁𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝐷𝑎𝑦𝑠 𝑖𝑛 𝑆𝑚𝑜𝑜𝑡ℎ𝑖𝑛𝑔 𝑃𝑒𝑟𝑖𝑜𝑑 (𝑇𝑦𝑝𝑖𝑐𝑎𝑙𝑙𝑦 20)
𝑚 = 𝑁𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑆𝑡𝑎𝑛𝑑𝑎𝑟𝑑 𝐷𝑒𝑣𝑖𝑎𝑡𝑖𝑜𝑛𝑠 (𝑇𝑦𝑝𝑖𝑐𝑎𝑙𝑙𝑦 2)
𝑅𝑆𝐼𝑆𝑡𝑒𝑝 𝑇𝑤𝑜 𝜎 [𝑇𝑃, 𝑛] = 𝑆𝑡𝑎𝑛𝑑𝑎𝑟𝑑 𝐷𝑒𝑣𝑖𝑎𝑡𝑖𝑜𝑛 𝑜𝑣𝑒𝑟 𝐿𝑎𝑠𝑡 𝑛 𝑃𝑒𝑟𝑖𝑜𝑑𝑠 𝑜𝑓 𝑇𝑃
100
= 100 − [ (𝑃𝑟𝑒𝑣𝑖𝑜𝑢𝑠 𝐴𝑣𝑒𝑟𝑎𝑔𝑒 𝐺𝑎𝑖𝑛 ∗ (𝑃𝑒𝑟𝑖𝑜𝑑 − 1)) + 𝐶𝑢𝑟𝑟𝑒𝑛𝑡 𝐺𝑎𝑖𝑛
]
1+
−((𝑃𝑟𝑒𝑣𝑖𝑜𝑢𝑠 𝐴𝑣𝑒𝑟𝑎 𝑔𝑒 𝐿𝑜𝑠𝑠 ∗ (𝑃𝑒𝑟𝑖𝑜𝑑 − 1)) + 𝐶𝑢𝑟𝑟𝑒𝑛𝑡 𝐿𝑜𝑠𝑠)

You might also like