Online Portfolio Selection Based on Adaptive Kalman Filter through Fuzzy Approach ()
1. Introduction
The portfolio selection problem is a process for finding the optimal portfolio that provides the highest return with the lowest risk. In order to maximize long-term return, a portfolio manager often properly modifies a portfolio and its proportion. Thus, portfolio selection is considered as an online problem.
Online portfolio selection algorithms are constructed based on various principles such as cross rate principle and mean reversion principle. The cross rate principle proposed by Albeverio et al. in 2001 [1] and is adjusted by Ren and Wu in 2016 [2] and 2017 [3] . This principle regards the order of the asset returns rather than the returns of asset themselves. The concept of this principle is replacing lower performance asset by a better one into a portfolio. However, the cross rate method is effective when we consider only two assets. For a mean reversion principle, an online portfolio selection strategy has been proposed by many researchers (see, [4] [5] [6] and [7] ). In this principle, it is assumed that the stock price will tend to move back to the mean price or inherent value over time. From this point, the investor may get more capital gain in the future from lower-performance stocks than the higher ones at the current time due to a more reasonable cost. Nevertheless, these strategies did not pay much attention to the noise of price data leading to an inaccurate estimation.
Borodin, El-Yaniv and Gogan [8] proposed an online portfolio strategy, named anticor (AC) strategy, with an assumption that a market follows the mean reversion principle. In the mechanism of AC, the statistical relationship and the cross-correlation matrix are used to determine a change of the next period price from the previous one. By the mean reversion principle and this mechanism of AC, the AC algorithm is able to transfer the wealth by moving the proportions of good performing stocks to poor performing ones, and the corresponding amount of proportions is adjusted according to the cross-correlation matrix. However, the AC uses the relative price as a ratio of the current price and the last previous price. This relative price is called a raw relative price. Therefore, the AC considers a price movement from one period to the next one, but it does not focus on a price movement from one period to the true value or its inherent value. However, it is hard to find the inherent value of a stock price because of the complex market noise. This leads to inaccurate predictions.
To eliminate the impact of market noise and accurately describe the asset’s inherent trend price, Raphael and Alain [9] used the Kalman filter algorithm (KF) to reduce noise in the stock price. They proposed a new relative price, called a cyclically adjusted price relative (CAPR), by replacing the last price in an original relative price by the inherent value via the Kalman filter algorithm. Based on the CAPR, they propose the K-AC algorithm, which is proved to be more efficient than AC.
However, there are some important limits of KF. For example, an initial value of noise covariance is completely assumed in the KF system by a fixed number. The covariance has an effect on the Kalman gain, which is used to control the filter bandwidth of the algorithm [10] . However, these values are unknown in most practical applications. The problem here is that the quality of these a priori noise statistics affects the optimality of the KF. Moreover, it has been shown that uncertain noise may provoke the divergence of the filter [11] [12] . From this point of view, Escamilla-Ambrosio and Mort [13] proposed a fuzzy inference system (FIS) based adaptive Kalman filtering. Also, they applied their system to a tracking model in logistics. Their adaptive process is concerned with a prescription of conditions under which the noise covariance is adaptively tuned via a fuzzy inference system. In their numerical study, the result reveals that the adaptation of the Kalman filter performs well when it is compared to KF. With this idea, we provide a new way to estimate the inherent price, given in [13] , by using the adaptive Kalman filter.
In this work, the adaptive Kalman filtering through fuzzy approach is applied to an online portfolio selection to predict a new inherent value for adjusting a raw relative price. Furthermore, comparing and analyzing the results from our approach with traditional methods in real datasets are provided. This paper is organized into five sections. In Section 2, the problem setting in a financial market and the academic background are described. The new online portfolio selection algorithms consisting of three steps are presented in Section 3. The first step is computing an inherent stock price from adaptive Kalman filtering through fuzzy approach. It is followed by constructing an adjusted relative price by using an inherent stock price from the first step. The last step is modifying an AC algorithm and computing a portfolio via adaptive AC with the adjusted relative price. The numerical results and discussions are described in Section 4. Finally, the conclusions of this work are given in Section 5.
2. Academic Background and Problem Setting
In this section, we introduce the problem setting in a financial market for defining variables utilized in this work. Moreover, the basic knowledge, being the anticor algorithm, Kalman filter, and fuzzy inference system, is also presented. The algorithms will be used to setup portfolio selection algorithms in the next section.
2.1. Problem Setting
Consider m stocks in a financial market. The relative price of stock i at the tth period
is the ratio of the closing price of the stock i at the tth period to the
closing price stock at the (t − 1)th period. That is
. Let
and
where n is the number of period invested. The vectors
and
are known as the market vector and the market sequence. Let
be a portfolio vector, where
represents the weightage of the investor’s capital invested in the jth stock on the tth period. In this paper, the self-financing portfolio is assumed and margin and short selling are not allowed. Thus,
and
for all t and i. For trading period
, the cumulative wealth of a portfolio strategy
after n trading periods is as follows:
(1)
where the initial wealth is denoted by
.
In addition, some assumptions on market and trading are assumed as follows:
1) There are no transaction costs and taxes on trading.
2) Investors can trade in a liquid market. Therefore, investors can buy and sell any number of stocks at closing prices.
3) The market behavior cannot influence any portfolio selection strategy.
The simplest portfolio selection strategy is called a buy and hold strategy (BH), which the investors buy stocks using the initial portfolio
and hold all stocks
until the end of investing period. For a portfolio
for all t,
the BH strategy is referred to as the uniform buy and hold strategy (U-BH), which treats the trend in the market. However, the proportion of each stock in a portfolio may not be equal. In this point, the initial proportion setting with a single index model proposed [14] . We purpose the new method that can adjust the next period trading portfolio according to the value assessment of each stock.
2.2. The Anticor Algorithm
In 2004 Borodin et al. [8] proposed an anticor (AC) algorithm. The AC updates a portfolio for the next trading period by adopting the mean reversion theory. The idea of this principle is that whatever the stock price rises or falls, it must revert to the inherent value. Therefore, the algorithm determines an instrument to transfer the wealth from higher-performance stocks to lower-performance ones. To evaluate the performance of the stocks, the AC partitions historical trading days into a number of equal-sized periods called windows size (w), which w is an integer greater than one. Moreover, the AC requires three assumptions as follows:
1) The growth rate of stock i exceeds that of stock j in the current window.
2) Stock j in the next window follows the same performance of stock i in the past window.
3) There is a positive correlation between stock i over the second last window and stock j over the last window.
Let
and
be two
matrices defined as
(2)
where
denotes
. The
and
are two
matrices constructed by taking the logarithm over two consecutive corresponding to time windows
and
. Let
be the jth column of
and
and
be the mean and the standard deviation of
, respectively. The cross-correlation matrix between the column vectors in
is defined as follows:
(3)
The
measures the correlation between the log-relative prices of stock i over the second last window and stock j over the last window. If
and
, the AC computes an updated portfolio in the next trading day by considering these two transferring functions:
#Math_39# (4)
(5)
The updated investment proportion
is computed by
(6)
where
(7)
2.3. Kalman Filter
The Kalman filter (KF) is considered as the optimal recursive data processing algorithm [15] that produces an estimation of unobservable variables
at each instant
. Also, the KF provides a prediction of the future system state based on past estimations. The state equation of the time series of unobservable variables is as follows:
(8)
where
is an
state vector at time t,
is an
control variable at time t,
is an
noise vector at time t assumed to be zero-mean Gaussian white noise with the covariance
. The matrix
is an
transition matrix and
is an
matrix. The observation equation
is given by
(9)
where
is an
observation at time t,
is an
observation noise at time t that are assumed to be zero-mean Gaussian white noise with the covariance
and
is an
measurement matrix.
The KF algorithm consists of prediction state and update state as follows [16] :
1) Prediction state (time update equations):
(10)
(11)
2) Update state (measurement update equations):
(12)
(13)
(14)
In addition, the covariance matrices
and
in KF display the statistics of the noises. In many practical applications, we don’t know the true value or Gaussianity of it. Thus,
and
are used as tuning parameters in general, the user can adjust to get the desired performance.
2.4. Fuzzy Inference System
A fuzzy inference system (FIS) is a system that uses fuzzy set theory to map inputs to outputs. The work of the FIS consists of the following three steps:
1) Fuzzification transforms the crisp values into fuzzy values, it maps actual input values into fuzzy membership functions and evaluates each input’s grade of membership in each membership function. The membership function of a fuzzy set A is denoted by
where
and it represents the degree of membership of x to the fuzzy set A [17] . The triangular membership function, which is used in this paper, is characterized by a mathematical simplicity. It is specified by three parameters
. For each value x, the triangular membership function
is defined as follows:
2) Fuzzy rules are a set of rules that make an association between typical input and output data, sometimes in an intuitive way, or, on other occasions, in a data driven way. The fuzzy IF-THEN rule is used in our work is in the following form:
IF x is A THEN y is B,
where A is a condition in a form of a fuzzy set of input and B is a conclusion in a form of a fuzzy set of output.
3) The defuzzification is finally converted into real output or crisp output. The centre of gravity method (COG) is used as a defuzzification method in this research. Let
be the membership value for point
in the universe of discourse. Then, COG of a tuning factor
is defined by
(15)
3. Computing an Online Portfolio Selection Based on Adaptive Kalman Filtering through Fuzzy Approach
In this research, we adapted AC by adjusting the relative price. The adjusted relative price is defined as a ratio of the current price over the inherent price which is computed through KF and fuzzy approach. There are three steps for constructing the new algorithm. First, we compute an inherent stock price from adaptive KF through fuzzy approach. After that, an adjusted relative price is constructed by using the current price and the inherent stock price that derives from the first step. The last step is computing a portfolio via adaptive AC with the adjusted relative price obtained from the second step.
3.1. Computing an Inherent Stock Price
Previously, the raw relative price is adjusted by the traditional KF formulation which already assumes entire a priori noise statistics. The quality of these prior affects on the optimality of the KF and may provoke the divergence of the filter. Therefore, an adaptive Kalman filtering through fuzzy approach is developed [13] . This adaptation improves the KF performance and prevents filter divergence when
or
in (11) and (12) are uncertain.
3.1.1. Residual Value and Variance Setting
In this work, the KF algorithm is applied for predicting the inherent value of a stock price on the next trading day by using the current observation. Thus, the linear KF is optimal and we will set the variables in KF accord with the financial market. That is, the dimension of all variables is an
matrix. The A, B, and H are assumed to be 1. In fact, we don’t know the control variable in the market, so the
is assumed to be zero.
Therefore, we defined variables for finding the inherent value of stock prices in KF as follows:
1) Prediction state (time update equations):
(16)
(17)
2) Update state (measurement update equations):
(18)
(19)
(20)
where
is an observation price,
is an unobservation price obtained from KF algorithm,
is an estimation of
,
is an prediction of
and the variance corresponding to the state estimation error defined by:
(21)
The weighted residual with Kalman gain,
, performs as a correction to the predicted estimate
. The actual variance #Math_103#, is approximated by its sample variance [18] through averaging inside a moving estimation window of size N. That is,
(22)
where
is the residual and
is the first sample inside the estimation window. This means that its variance is estimated by using only the last N samples of
.
3.1.2. Adaptive Observation Noise through Fuzzy Inference System
The purpose of adaptive observation noise through FIS in this research is to improve the performance of KF and prevent filter divergence when
or
are uncertain. The observation noise
in KF represents the accuracy of the measurement instrument. A larger
of measured data implies that we trust the observed data less and take more importance on the predicted data.
In order to adjust
, the
is assumed to the variance of training data and the noise variance
in Equation (17) is assumed to be known and be a constant value for all t. Thus, we replace
with Q. This adaptive noise is able to reasonably correct the mismatch of the actual variance
in Equation (22) and its theoretical variance
in Equation (18). Now, the discrepancy between
and
, called the degree of matching (
) [13] , is defined as:
(23)
Based on knowledge of the size of the discrepancy between
and
, an FIS is used to derive a tuning factor
.
As mentioned above, FIS consists of three steps, namely, fuzzification, fuzzy rule base, and defuzzification.
Fuzzification: To simplify our idea, we divide the fuzzification step into 3 steps as follows:
1) Determining input and output for which the input is an error
and actual output is a tuning factor
of
.
2) Choosing an appropriate membership function for determining input and output fuzzy sets. Because of the linearity of the Kalman equation, the performance of a triangular membership function is accepted in this research [19] .
3) Choosing the correct labels for each fuzzy set which, in this research, named as a linguistic variable. Based on experience knowledge, the linguistic variables for error (
) are set as negative big (NB), negative medium (NM), negative small (NS), zero (ZE), positive Small (PS), positive medium (PM) and positive big (PB). Also, based on [20] and experience knowledge, it is quantized into equal sizes. The linguistic variables for change of error (
) are defined as decrease large (DL), decrease medium (DM), decrease small (DS), maintain (M), increase small (IS), increase medium (IM) and increase large (IL), and all values are quantized with equal size.
Here, we use the membership function for the error
in Figure 1,
is a scale,
represents crisp input; seven memberships are used to describe
Figure 1. Membership functions used to translate crisp input into fuzzy. This type of membership is constructed by modifying a membership function in [19] .
the input. The input boundary of a triangular membership function is defined by the maximum and minimum of
in KF. The membership functions for
can be expressed similarly, b is a scale, and the output boundary is defined by the maximum and minimum of
in KF.
Fuzzy rule base: The fuzzy rule base in this research based on Escamilla-Ambrosio and Mort [13] . The rules of adaptation are defined as follows:
1) If
is negative big (NB) then increase
large (IL).
2) If
is negative Medium (NM) then increase
medium (IM).
3) If
is negative small (NS) then increase
small (IS).
4) If
is zero (ZE) then maintain (M)
unchanged.
5) If
is positive small (PS) then decrease
small (DS).
6) If
is positive medium (PM) then decrease
medium (DM).
7) If
is positive big (PB) then decrease
large (DL).
Defuzzification: The last step to design FIS in defuzzification. In this part, a fuzzy set is transformed into a crisp set. Therefore, the input for defuzzification is an aggregate output and the output of this step is a crisp number. Based on (15), the center of gravity method (COG) is used as a defuzzification method in this research. Thus, FIS generates the tuning factor
, and the correction is made in this way:
(24)
The
in the above equation is used as an updated value in (18). We now adjust the observation noise variance of
in the KF by using the fuzzy approach to prevent the divergence of KF. Consequently, the observation price
in (16) is added as an updated variable of the adaptive KF through fuzzy approach. Then, we observe a new inherent value of stock prices, denoted by
. The computation procedure of the development of the KF by using the fuzzy approach is shown in Figure 2.
3.2. Constructing an Adjusted Relative Prices
Since the raw relative price from the original AC can only measure how much the price moves from one period to the next one, it cannot measure how far the
Figure 2. The computation procedure of an improvement of KF via FIS.
stock price is different from its inherent value. Therefore, the adjusted relative price is proposed to measure this difference. The adjusted relative price of stock i for tth trading period is shown as follows:
(25)
3.3. Computing a Portfolio via Adaptive Online Portfolio Selection
In this research, we modify an AC algorithm by applying the adjusted relative price via adaptive Kalman filtering through fuzzy approach. In this step, the updated portfolio for the next trading day is obtained. The algorithm for AC based on adaptive Kalman filtering through fuzzy approach (FK-AC) is shown in Table 1.
4. Numerical Results and Discussions
In this part, we will study the construction of an online trading portfolio with three algorithms, that is AC, K-AC, and FK-AC, and compare their performance by considering wealth and the reward-to-variability (RV) ratio of portfolios. In this research, we will use the real data from the SET50 market consisting of the top 50 listed companies in the Stock Exchange of Thailand in terms of large market capitalization and high liquidity. The daily price of SET50 over 10 months from 1 July 2020 to 1 April 2021 is considered as observation data.
For computing a portfolio, we divide this data into two groups. The first group, the data from 1 July 2020 to 31 August 2020, is used to compute initial parameters in each method. In this step, data window sizes are set to be 10, 20,
and 30. The second group, the data from 1 September 2020 to 30 April 2021, is considered as data for constructing a daily portfolio for each algorithm. In this work, the initial parameters in each method, the covariance R and the error covariance V (or P), are obtained by using the first two months of the data. These initial parameters are only used for constructing the updated portfolio for the first trading day. After that, the two parameters are updated by a mechanism of each algorithm and then used for constructing the next trading day portfolio. In this step, the two month data is assumed to have a sufficient amount for computing initial parameters. Moreover, it reflects the movement of the stock price better than using a long period of time. For an investment period, the data for seven months is considered as data for constructing a daily portfolio obtained from each algorithm. This data group depends on how long you want to invest. In this research, we study an investment for seven months.
For numerical study, an initial portfolio may affect numerical results. In this work, two ways of initial portfolio setting are assumed. Firstly, the initial proportion for each stock is assumed to be equal. We will call this initial portfolio as the basic method. Apart from equally proportion setting, we also use the single index model (SIM) [14] to set up an initial portfolio. In this way, the initial weight for each stock may be different. After that, the portfolios obtained by these two initial setting approaches with AC, K-AC and FK-AC algorithms are compared. Moreover, the following three different ways for selecting stocks into a portfolio are applied:
1) Selecting all stocks in SET50 market
2) Random selecting 10 stocks from SET50
3) Random selecting 2 stocks from each industrial sector in SET50
In the second and the third ways of selecting stocks, twenty cases of randomly selected in each way are used to study the performance of trading algorithms with data window size 10 days, 20 days, and 30 days.
The results are compared by considering wealth and RV ratio of portfolios. The RV ratio indicates investment excess return per unit of risk. The annualized RV ratio is defined as [21] :
(26)
where APY is annual percentage yield, ASTDV is the annualized standard deviation of the daily logarithmic returns. This value ASTDV measures an asset’s volatility (risk). The
is risk-free return rate which here is set to be zero. The APY and ASTDV can be computed by using the following formula:
(27)
(28)
where
is the wealth of the last trading day,
is the wealth of the first
trading day, T is the time for investment which is computed as
where n is
the number of the trading day and
is the standard deviation of the daily logarithmic returns. The number 252 is assumed to represent the number of trading days per year in the stock market. The flowchart of computing is shown in Figure 3. Some portfolio’s wealth results are shown in Figure 4. Moreover, the averages of the wealth of all cases obtained from three different ways for selecting stocks into the portfolio are shown in Table 2.
From Table 2, overall, the FK-AC method provides a higher average of wealth than other methods. Considering the window size of 10, the AC gives the higher average of wealth compared to other algorithms. In the case of 20 and 30 window sizes, the FK-AC gives a better wealth. To indicate investment excess return per unit of risk, the average of RV ratio is used to compare the performance of those algorithms. The results are shown in Table 3.
In Table 3, the FK-AC method also provides a higher RV ratio than other methods. We observe that, particularly, our algorithm provides a better portfolio performance than other methods in the case of the window size 20 and 30. However, for the window size of 10, the AC gives a higher average of RV ratio than other algorithms.
Figure 3. Flowchart of computing portfolio and comparing algorithm.
Figure 4. Wealth of portfolio from selecting all stocks in SET50 market.
Table 2. The average wealth of 3 ways of each algorithm.
Table 3. The average RV ratio of 3 ways of each algorithm.
5. Conclusions
In this research, the anticor (AC) is adjusted by replacing the raw relative price with the alternative relative price observed from Kalman filtering through fuzzy approach. This alternative price provides the direction of how far the price moves from the current price to an inherent price while the raw relative price cannot. From this point, the AC mechanism with the alternative relative price is used to transfer the optimal wealth of each stock in the portfolio for the next period.
For numerical studies, the portfolio selection based on adaptive Kalman filtering through fuzzy approach is compared with the anticor (AC) and the anticor based on Kalman filtering (K-AC). The observation data is the SET50 stock prices. The tools which are used to measure the performance of algorithms are portfolio wealth and reward-to-variability (RV) ratio of a portfolio.
The results show that, based on the dataset in this work, our method provides the higher wealth and RV ratio in most window sizes compared with the original anticor method and the anticor method based on KF in overall. Looking at the initial proportion obtained from the single index model approach, the results show that the proposed method gives both the higher wealth and the higher RV ratio at the window size 20 days and 30 days. Moreover, all methods with the single index model provide higher wealth than those with the basic method. There are two aspects of contributions from this paper. Firstly, this provides a new algorithm that considers the noise of the data. For the second aspect, this work may benefit to investors or developers who need to construct a daily speculative portfolio or efficient trading program by implementing this algorithm with a short period of historical data.
Acknowledgements
The authors appreciate the referee(s) for their helpful comments. The first authors would like to thank the Department of Mathematics, Faculty of Science, King Mongkut’s University of Technology Thonburi for financial support and thanks to the Science Achievement Scholarship of Thailand, SAST for the financial support.