Business / Financial Problem:
Asset management firms often use the rule-based screening method to assist in short-term
trading and in making their decisions on how to allocate their portfolios. They also use the
rule-based screening method to forecast the likely direction that a stock's price will take in the
next trading day. They do not attempt to forecast the specific price at the end of the trading
day because they believe it would be difficult to accurately forecast due to the uncertainty and
noise of future prices.
In essence, the goal of this project is to see if recent price and volume behavior can be
utilized to predict the upward or downward movement of the stock price. As such, the
problem is defined as a binary classification problem; the model produces a directional signal
from past market data.
Dataset Description and Exploratory Analysis:
This study uses a year’s worth of daily trading information about Reliance Industries Ltd
(Reliance; ticker [Link]) from Yahoo Finance using the yfinance API. This dataset
has all of the standard OHLCV features – Open, High, Low, Close and Volume – and these
have been normalized for corporate events – i.e., for split/consolidation/dividend events so
there are no breaks in the price history.
As an additional note, this dataset only included trading days because exchanges are closed
on weekends and on national holidays. The initial review of the data indicated that most of
the time the data was free from errors, although some missing values appeared due to
indicators created during the data preprocessing phase. These missing values were addressed
properly during preprocessing. After the feature engineering and data cleaning phases the
final modeling dataset contained 236 rows and 15 columns.
Visualizations from exploratory data analysis were performed to assess price behavior,
volatility behavior, correlation between features, and the distribution of the target variable.
All of the plots produced confirmed that the dataset behaved well, without any significant
anomalies or breaks in structure throughout the sample period.
Data Cleaning and Feature Engineering:
The process of data cleaning involved filling missing data , as well as eliminating any row
containing an undefined value created by either the rolling-window calculation, or lagged
variables. Additionally, any infinite values created in the course of feature creation were
replaced with NAN, and then eliminated so as to be compatible with the model.
Feature engineering was conducted to represent important aspects of markets. The Relative
Strength Index (RSI) is used to represent momentum over a 14-day window of price
movements. Trend is represented through the use of the Moving Average Convergence
Divergence (MACD), which is computed as the difference between short-term and long-term
exponential moving averages. Volatility was estimated using the intraday price range
normalized by the opening price.
Additionally, the inclusion of contextual information was done via the incorporation of
lagged daily returns; this will allow the model to capture any short-term momentum or
reversal effect present. Volume change was also included as a way to represent variation in
market participation and trading intensity. The above-mentioned engineered features were
chosen because they have wide use in financial analysis, and represent economically
interpretable signals that are particularly suited for use with tree-based models.
4. Target Variable Definition
The target variable was created as a representation of the price direction of the next trading
day. In other words, the target was established as 1 when the closing price of the next trading
day was greater than the closing price of the current trading day and vice versa for 0. The
purpose of this formulation directly relates to the business objective of predicting the
directional movement of prices on a short-term basis.
An examination of the distribution of the target values revealed that there were approximately
equal numbers of days representing upward and downward movements. Therefore, no class
imbalance existed; therefore, metrics based on the accuracy of the model, such as accuracy,
are valid and do not reflect the potential dominance of one class.
5. Modelling Methodology
Due to the sequential nature of financial time series data, a temporal train-test split was used
to create the training and testing datasets. Approximately 80 percent of the observations were
included in the training set and the remaining 20 percent were included in the testing set.
Using a temporal train-test split avoided introducing a "look ahead" bias into the model and
represented a more realistic method of validating the performance of a model prior to
deployment.
Random Forest Classifier was chosen as the base model, due to its ability to identify complex
non-linear relationships between variables, account for interaction effects among the
predictor variables and minimize the impact of overfitting on the model's performance
through ensemble averaging. A conservative configuration for the model was established,
utilizing shallow decision trees and a requirement for a minimum number of samples per
node to avoid memorization of noise. In addition, the use of out-of-bag (OOB) validation
provided an internal estimate of the model's performance independent of the performance of
the test set.
6. Evaluating the Model and Its Performance
--- Results ---
Accuracy: 52.08%
OOB Score: 44.15%
Classification Report:
precision recall f1-score support
0 0.50 0.74 0.60 23
1 0.57 0.32 0.41 25
accuracy 0.52 48
macro avg 0.54 0.53 0.50 48
weighted avg 0.54 0.52 0.50 48
Evaluating the performance of the model was accomplished through the use of several
metrics, including accuracy, OOB score, a classification report and a confusion matrix.
Accuracy for the model of the test set was found to be approximately 52%, which is
marginally better than randomly selecting a response from the possible two outcomes and the
OOB score was somewhat less, indicating that the underlying predictive signal in the data
was weak, rather than being overly optimistic.
The classification report indicated that the model was able to perform better at detecting
downward or flat price movements, relative to upward price movements. The recall for
upward price movements was relatively low, indicating that the model did not detect a large
number of upward price movements. This conservative behavior is typical of models
attempting to predict short-term financial price movements and is expected since upward
price movements tend to be difficult to predict consistently.
The confusion matrix reinforced this bias, showing that the model made a larger number of
correct predictions for downward price movements and had a tendency to underpredict
upward price movements. The results of the feature importance analysis revealed that the RSI
and lagged returns were the most important predictors, followed closely by volume change
and intraday volatility. These results are consistent with financial theory, as the price and
volume action of the past few days and weeks tend to dominate the behavior of the price of a
security.
7. Testing a Trading Strategy
In order to assess the implications of the model's predictions in terms of developing a simple
trading strategy, a backtesting exercise was performed on the test dataset. The strategy
consisted of purchasing the stock when the model predicted that the price would rise and
holding cash otherwise. The results of the backtesting were then compared to those of a buy-
and-hold strategy. Since no consideration was given to transaction costs, leverage or short
sales, the results of the backtesting were solely based on the model's predictions.
As a result, the cumulative performance of the model-based strategy was found to be inferior
to that of the buy-and-hold strategy over the test period and the returns generated by the
model-based strategy were relatively flat. This indicates the difficulties of generating
economically viable trading profits from the small amount of predictive accuracy that can be
obtained from the model, especially on a daily basis.
8. Summary and Implications of the Study
Overall, this study has highlighted the difficulties of obtaining reliable estimates of short-
term directional price movements from historical price and volume data. Although the model
was implemented appropriately and supported by the application of relevant feature
engineering, the results of the study demonstrate that the predictive performance of the model
was limited and reflective of the high levels of both noise and efficiency present in financial
markets.
Moreover, the study suggests that while short-term momentum and volatility indicators do
appear to possess some information, they are not sufficient on their own to produce strong
and consistent directional signals. It is also important to note that the poor results of the study
do not imply that the methodology applied to the study was flawed, but instead highlight the
inherent difficulties of the problem.
9. Potential Improvements and Extensions
Several areas exist that could potentially enhance future research. One area is the application
of additional technical indicators to the model. Another area of interest includes establishing
alternative target definitions based upon probability thresholds and developing more robust
validation methods, such as walk-forward analysis. Additionally, expanding the size of the
database to include the price history of multiple securities, as well as extending the length of
the time horizon of the data may improve the stability of the model. Lastly, incorporating the
costs of transactions and implementing a more realistic set of constraints on the trading
activity will provide a more complete assessment of the economic viability of the model.