Portfolio Optimization: A Comparative Study

*Jaydip Sen and Subhasis Dasgupta*

#### **Abstract**

Portfolio optimization has been an area that has attracted considerable attention from the financial research community. Designing a profitable portfolio is a challenging task involving precise forecasting of future stock returns and risks. This chapter presents a comparative study of three portfolio design approaches, the mean-variance portfolio (MVP), hierarchical risk parity (HRP)-based portfolio, and autoencoderbased portfolio. These three approaches to portfolio design are applied to the historical prices of stocks chosen from ten thematic sectors listed on the National Stock Exchange (NSE) of India. The portfolios are designed using the stock price data from January 1, 2018, to December 31, 2021, and their performances are tested on the outof-sample data from January 1, 2022, to December 31, 2022. Extensive results are analyzed on the performance of the portfolios. It is observed that the performance of the MVP portfolio is the best on the out-of-sample data for the risk-adjusted returns. However, the autoencoder portfolios outperformed their counterparts on annual returns.

**Keywords:** portfolio optimization, mean-variance portfolio, hierarchical risk parity portfolio, autoencoder portfolio, unsupervised learning, deep learning, return, risk, volatility, sharpe ratio

#### **1. Introduction**

Portfolio Optimization is the task of identifying a set of capital assets and their respective weights of allocation, which optimizes the risk-return pairs. Optimizing a portfolio is a computationally hard problem. The problem gets more complicated if one needs to optimize future return and risk values, as predicting future stock prices is equally challenging. Markowitz proposed the mean-variance optimization approach which is based on the mean and covariance matrix of returns [1]. However, the meanvariance portfolio (MVP) design poses several challenges including the difficulty in estimating future expected returns of the stocks constituting the portfolio.

The hierarchical risk parity (HRP) algorithm proposed by de Prado attempts to address the challenges of the quadratic optimization problem which are relevant to the MVP portfolio design [2]. The HRP approach to portfolio design involves clustering the stocks using an agglomerative clustering method. The weights of the stocks in a cluster are assigned in inverse proportion to the variance of the cluster. The HRP

algorithm is built on the concepts of graph theory and machine learning, and unlike the MVP approach to portfolio optimization, it does not require the invertibility of the covariance matrix of the stock returns [2].

Autoencoders are symmetric networks used for unsupervised learning. The output layer of an autoencoder is of the same size as the input layer because its purpose is to reconstruct its own inputs rather than predict a dependent target value. The goal of these networks is to act as a compression filter via an encoding layer that fits the input vector into a smaller latent representation. A decoding layer reconstructs the input while minimizing the error in reconstruction. Autoencoders can be trained on the historical prices of stocks forming a portfolio, in which the salient features of the stocks are represented in a compact manner at the coding layer, while the final output layer represents the reconstructed features of the stocks.

This work presented in this chapter discusses an algorithmic approach to building optimized portfolios by selecting stocks from ten thematic sectors of the National Stock Exchange (NSE) of India. Based on the report of the NSE on December 31, 2021, ten stocks have been identified which have the highest free-float market capitalization as per their listing in the National Stock Exchange (NSE) [3]. The historical prices of these stocks are scraped from the web using their ticker names. MVP, HRP, and autoencoder-based portfolios are designed and trained using the historical prices of the stocks from January 1, 2018, to December 31, 2021. The testing of the portfolios is done on the stock price data from January 1, 2022, to December 31, 2022. Extensive analysis of the performance of the portfolios is made based on their annual returns, annual volatilities, and Sharpe ratios.

The main contribution of the current work is threefold. First, it presents three different methods of optimizing portfolios, MVP, HRP, and autoencoder-based design. These portfolio design approaches are applied to ten thematic sectors of stocks of the NSE. The results can be used as a guide to investors in the stock market for making profitable investments. Second, a method is presented for evaluating the performance of the portfolios based on their annual returns and risks and Sharpe ratios. Since the evaluation is done both on the training and the test data, the work has identified the most efficient portfolio for all ten sectors on both datasets. Hence, a robust framework for evaluating different portfolios is demonstrated. Third, the returns of the portfolios on the thematic sectors on the test data highlight the current profitability and the volatility of these sectors. This information can be useful for investors.

The chapter is organized as follows. Section 2 briefly discusses some related works in the literature. Section 3 provides a brief theoretical foundation of MVP, HRP, and autoencoder-based portfolio design. Section 4 discusses the data used and the methodology followed in the work. Section 5 presents extensive results of the performance of the portfolios and their analysis. A comparative study of the performance of the portfolios is also made. Section 6 concludes the chapter and identifies some future directions of work.

#### **2. Related work**

Several approaches have been proposed by researchers for accurate prediction of stock prices and robust portfolio optimization. Time series decomposition and econometric approaches like ARIMA, Granger causality, and VAR are extensively used for stock price prediction and portfolio optimization [4–10].

*Portfolio Optimization: A Comparative Study DOI: http://dx.doi.org/10.5772/intechopen.112407*

The use of machine learning, deep learning, and reinforcement learning models for future stock price prediction has been the most popular approach of late [11–23]. Hybrid models are also proposed that utilize the algorithms and architectures of machine learning and deep learning and exploit the sentiments in the textual sources on the social web [24–29].

The use of metaheuristics algorithms in solving multi-objective optimization problems for portfolio management has been proposed in several works [30–32]. The use of fuzzy logic, genetic algorithms (GAs), and algorithms of swarm intelligence (SI), e.g., particle swarm optimization (PSO), are also quite common in portfolio optimization [33–35].

The performances of the mean-variance, Eigen, and HRP portfolios have been compared on different stocks from various sectors of the Indian stock market [36–42]. A pair portfolio design approach using cointegration for the Indian stock market has also been proposed in the literature [43]. The use of generalized autoregressive conditional heteroscedasticity (GARCH) in estimating the future volatility of stocks and portfolios has also been illustrated [44–45].

Finally, deep reinforcement learning approaches have been extensively used in portfolio optimization [46–58].

#### **3. Theoretical background**

In this section, some background theories of portfolio design are discussed. The design approaches to MVP, HRP, and autoencoder-based portfolios and their optimization methods are briefly presented in the following.

#### **3.1 Mean-variance portfolio optimization**

The mean-variance portfolio (MVP) design involves the following steps: (a) Computation of returns and volatilities of the stocks, (b) Determination of the covariances and correlations among all pairs of stocks in the portfolio, (c) Derivation of the expected returns and risks of several candidate portfolios, (d) Identifying the portfolio with the maximum risk-adjusted return among all candidate portfolios. In the following, we briefly describe these steps. For further details, interested readers may refer to [36].

#### *3.1.1 Computation of stock returns and volatilities*

Based on the historical values of the stock prices in the portfolio training dataset, the daily return or the log return values of each stock of that sector are computed. The daily return values are the percentage changes in the successive daily stock prices, while the log return values are the logarithms of the percentage changes in the daily stock prices. Based on the daily return values, the daily volatility, and the annual volatility of every stock in a portfolio are computed. The daily volatility is the standard deviation of the daily return values. The daily volatility, on multiplication by a factor of the square root of 250, yields the value of the annual volatility. Here, there is a standard assumption of 250 working days in a year for a stock market. The annual volatility of a stock reflects the risk associated with stock from an investor's point of view. For every stock, the daily return values are also aggregated into their annual return values.

#### *3.1.2 Determination of covariances and correlations of stocks*

After the volatility and return of the stocks are computed based on the historical prices of the stocks, the covariance and the correlation matrices are derived for a portfolio. These matrices depict the strength of association between all pairs of stocks in a portfolio. A good portfolio aims to minimize the risk while maximizing the return. Risk minimization of a portfolio requires identifying stocks that have low correlation among themselves so that a higher diversity can be achieved.

#### *3.1.3 Derivation of portfolio returns and risks*

The expected return *E(R)* of a portfolio containing *n* stocks denoted as *S1*, *S2*,.. … .., *Sn*, and their corresponding associated weights *w1*, *w2*, … … ,*wn* is given by (1):

$$E(R) = \mathcal{w}\_1 E(R\_{\mathbb{S}\_1}) + \mathcal{w}\_2 E(R\_{\mathbb{S}\_2}) + \dots + \mathcal{w}\_n E(R\_{\mathbb{S}\_n}) \tag{1}$$

The variance of a portfolio is computed using the variances of the individual stocks constituting the portfolio, and the covariances between every pair of stocks in the portfolio. The variance of a portfolio, *Var(P)* is computed using (2):

$$Var(P) = \sum\_{i=1}^{n} w\_i \sigma\_i^2 + 2 \ast \sum\_{i,j} w\_i \ast w\_j \ast Cov(i, j) \tag{2}$$

In (2), *wi* and σ<sup>i</sup> represent the weight associated with stock *i* and the standard deviation of the historical prices of stock *i*. The covariance between the historical prices of stock *i* and stock *j* is denoted as *Cov*(*i*, *j*).

Once the return and the volatility (i.e., risk) for a portfolio are computed using the stock price data of all its constituent stocks, the portfolio is optimized so that its risk-adjusted return is the maximum. This optimization is carried out in the next step.

#### *3.1.4 Portfolio with maximum risk-adjusted return*

To understand how the portfolio with the maximum-risk-adjusted return (i.e., the optimum portfolio) is identified, two concepts are important to know, (i) Sharpe ratio and (ii) efficient frontier of portfolios. In the following, these two terms are explained first.

The Sharpe ratio (SR) of a portfolio is given by (3)

$$SR = \frac{R\_{\varepsilon} - R\_{f}}{\sigma\_{\varepsilon}} \tag{3}$$

In (3), *Rc*, *Rf*, and σ<sup>c</sup> denote the return of the current portfolio, the risk-free portfolio, and the standard deviation of the current portfolio, respectively. Here, the risk-free portfolio is a portfolio with a volatility value of 1%. The optimum portfolio is the one that maximizes the Sharpe Ratio for a set of stocks.

The question that remains to be addressed is how to identify the portfolio with the maximum Sharpe ratio. To answer this question, the term *efficient frontier* needs to be introduced.

#### **Figure 1.**

*The efficient frontier illustrated with 10,000 candidate portfolios. The portfolio with the minimum risk is represented by the red star, while the green star identifies the portfolio with the maximum Sharpe ratio (i.e., it is the optimum portfolio).*

For a given portfolio of stocks, the *efficient frontier* is the contour with the returns plotted along the *y*-axis and the volatility (i.e., risk) on the *x*-axis. The points of an efficient frontier indicate the portfolios with the maximum return for a given value of volatility, or those with the minimum value of volatility for a given value of the return. Since, for an efficient frontier, the volatility is plotted along the *x*-axis, the minimum risk portfolio is identified by the leftmost point on the efficient frontier. Since the optimum portfolio is the one that maximizes the Sharpe ratio, this portfolio is identified by the point on the efficient frontier, that yields that maximum value of the return/risk ratio. **Figure 1** depicts the efficient frontier for many candidate portfolios, wherein the portfolio with the minimum risk and the one with the maximum Sharpe ratio are identified.

#### **3.2 Hierarchical risk parity-based portfolio optimization**

The execution of the hierarchical risk parity (HRP) approach to portfolio optimization involves three steps: (a) Formation of clusters, (b) Quasi-diagonalization, and (c) Recursive Bisection. These steps are briefly described below. For more details, the readers may refer to [2, 59].

#### *3.2.1 Formation of clusters*

The tree clustering used in the HRP algorithm is an agglomerative clustering algorithm. A hierarchy class is first created in Python to design the agglomerative clustering algorithm. The hierarchy class contains a dendrogram method that receives the value returned by a method called linkage defined in the same class. The linkage method receives the dataset after pre-processing and transformation and computes the minimum distances between stocks based on their return values. There are several

#### **Figure 2.**

*The dendrogram produced by the agglomerative clustering done by the hierarchical risk parity-based approach to portfolio optimization. The x-axis shows the ten stocks that participated in the clustering process, while the y-axis depicts the ward distance used as the metric in computing the inter-cluster distance.*

options for computing distance. However, the ward distance is a good choice since it minimizes the variances in the distance between two clusters in the presence of high volatility in the stock return values. In this work, the ward distance has been used as a method to compute the distance between two clusters. The linkage method performs the clustering and returns a list of the clusters formed. The computation of linkages is followed by the visualization of the clusters through a dendrogram. In the dendrogram, the leaves represent the individual stocks, while the root depicts the cluster containing all the stocks. The distance between each cluster formed is represented along the y-axis, longer arms indicate less correlated clusters and vice versa. The details of the clustering process are described in [2]. **Figure 2** exhibits a typical dendrogram of the agglomerative clustering used in HRP portfolio optimization.

#### *3.2.2 Quasi-diagonalization*

In this step, the rows and the columns of the covariance matrix of the return values of the stocks are reorganized in such a way that the largest values lie along the diagonal. Without requiring a change in the basis of the covariance matrix, quasidiagonalization yields a very important property of the matrix – the assets (i.e., stocks) with similar return values are placed closer to each other, while disparate assets are put at a far distance. The working principles of the algorithm are as follows. Since each row of the linkage matrix merges two branches into one, the clusters (*CN-1*, 1) and (*CN-2*, 2) are replaced with their constituents recursively, until there are no more clusters to merge. This recursive merging of clusters preserves the original order of the clusters [59]. The output of the algorithm is a sorted list of the original stocks (as they were before the clustering).

#### *3.2.3 Recursive bijection*

The quasi-diagonalization step transforms the covariance matrix into a quasidiagonal form. It is proven mathematically that the allocation of weights to the assets in an inverse ratio to their variance is an optimal allocation for a quasi-diagonal matrix [59]. This allocation may be done in two different ways. In the bottom-up approach, the variance of a contiguous subset of stocks is computed as the variance of an inverse-variance allocation of the composite cluster. In the alternative top-down

*Portfolio Optimization: A Comparative Study DOI: http://dx.doi.org/10.5772/intechopen.112407*

approach, the allocation among two adjacent subsets of stocks is done in inverse proportion to their aggregated variances. In the current implementation, the topdown approach is followed. A Python function *computeIVP* computes the inversevariance portfolio based on the computed variances of two clusters as its given input. The variance of a cluster is computed using another Python function called clusterVar. The output of the *clusterVar* function is used as the input to another Python function called *recBisect* which computes the final weights allocated to the individual stocks based on the recursive bisection algorithm.

#### **3.3 Autoencoder-based portfolio optimization**

Autoencoders are symmetric networks used for unsupervised learning. The output layer is the same size as the input layer because it aims to reconstruct its own inputs rather than predict a dependent target value. The goal of these networks is to act as a compression filter via an encoding layer, Φ that fits the input vector X into a smaller latent representation (the code) *c*, and then a decoding layer, φ tries to reconstruct it back to X'such that (4) holds good:

$$
\phi: X \to \mathfrak{c}, \phi: \mathfrak{c} \to X' \tag{4}
$$

Any reconstruction error is evaluated based on the computation of a loss function. Minimization of the loss function will force the network to find the most efficient compact representation of the training data with minimum information loss. For numerical input, the loss function (LMSE) is the *mean squared error* computed in (5):

$$L\_{\rm MSE} = \left\| X - X' \right\|^2 \tag{5}$$

As depicted in **Figure 3**, central layer (the code) of the network is the compressed representation of the data. We are effectively translating an *n*-dimensional array into a

#### **Figure 3.**

*The schematic representation of an autoencoder with its input layer, encoder network, coding layer, decoding network, and output layer indicated.*

smaller *m*-dimensional array, where *m* ≤ *n*. Since autoencoders can learn new latent representations, combining the previously learned ones so that each hidden level can be seen as some compressed hierarchical representation of the original data, the coding layer or any other intermediate hidden layer in the encoder part of the network can be taken as valid features describing the input vector.

Autoencoders can be trained on the historical prices of stocks forming a portfolio, in which the salient features of the stocks can be represented in a most compact manner at the coding layer, while the final output layer represents the reconstructed features of the stocks. Since for portfolio optimization, we need weights to be allocated to each stock based on the importance of the features, the extracted normalized feature values at the output layer are taken as the weights for the corresponding stocks in the portfolio [60].

#### **4. Data and methodology**

#### **4.1 Choosing the sectors**

The stocks under ten thematic sectors of NSE, India are chosen for the portfolio design. These sectors are: (i) NIFTY commodities, (ii) NIFTY energy, (iii) NIFTY manufacturing, (iv) NIFTY services, (v) NIFTY MNC, (vi) NIFTY transportation & logistics, (vii) NIFTY infrastructure, (viii) NIFTY housing, (ix) NIFTY consumption, and (x) NIFTY 100 ESG (environmental, social and governance). The NIFTY thematic sector indices reflect the performance of stocks that belong to specific investment themes such as manufacturing, services, social, infrastructure, etc. For each sector, ten stocks are identified which have the maximum free-float market capitalization based on the NSE's report of February 29, 2022 [3].

#### **4.2 Acquiring the data**

The *DataReader* function defined in the *pandas* library of Python is used for scraping the historical prices of the stocks of the ten thematic sectors from the Yahoo Finance website. The stock price records for the period January 1, 2018, to December 31, 2021, are used to build the portfolios for the sectors, while the portfolios are tested on the stock records for the period January 1, 2022, to December 31, 2022. Since the current work is based on a univariate analysis, only the *close* prices of the stocks are used for computing the portfolio return and risk.

#### **4.3 Designing the MVP portfolios**

For designing the MVP portfolio for each sector, the daily returns of the stocks are computed using the *pct\_change* function in Python. The annual return of each stock is then computed from the daily return values. The daily volatility of the stocks is computed using the *std* function in Python. The annual volatility is derived by multiplying the daily volatility by a factor of the square root of 250 assuming that there are 250 working days in a calendar year. Python functions *cov* and *corr* are used for computing the covariance and correlation matrices, respectively for each portfolio. Based on the return and the volatility of individual stocks, the annual return and risk for the portfolios are computed. Finally, For plotting the contour of the efficient frontier, the weights are assigned randomly to the ten stocks in a portfolio in a loop

and iterate the loop 10,000 times in a Python program. The iteration produces 10,000 points, each point representing a portfolio. The optimum portfolio is identified as the portfolio yielding the highest value of the Sharpe ratio on the efficient frontier.

#### **4.4 Designing the HRP portfolios**

For the ten sectors, the HRP portfolios are designed following the three steps, agglomerative clustering, quasi-diagonalization, and recursive bijection. The procedural and implementation details of HRP portfolios have been discussed in Section 3.2.

#### **4.5 Designing the autoencoder portfolios**

The fundamentals of autoencoder portfolios have been presented in Section 3.3. Here, we discuss some implementation details of the autoencoder portfolios. The model architecture of the autoencoder portfolio as produced by the *plot\_model* function in the *keras* library is exhibited in **Figure 4**. The model has one coding layer that extracts 5 features from the 10 features supplied in the input layer. The data shape (None, 10) at the input layer represents the *close* prices of the ten stocks of the portfolio. The data shape (None, 10) at the output of the final layer corresponds to the *weights* assigned by the portfolio to the ten stocks. While the *ReLU activation* has been used at the coding layer, at the output layer, *linear activation* is used. Adam optimizer is used in model training to ensure faster convergence. The model is trained over 500 epochs using a batch size of 10. The number of layers in the autoencoder model is determined using the grid search method.


**Figure 4.** *Architecture of the autoencoder model for portfolio optimization.*

#### **4.6 Evaluating the portfolio performance**

Finally, the performances of the three portfolios for each of the ten sectors are evaluated on the training and test data. The metrics used for evaluation are the annual return, annual volatility, and the Sharpe ratio. For each sector, the portfolio yielding the best results on the training and test data are identified. From the point of view of the investors, the portfolio performing the best on the test data is the one that should be followed.

#### **5. Performance results**

This section presents the performance results of the portfolios. The portfolios are implemented using the Python language and its libraries. All experiments are carried out on a system with an Intel i7 CPU with a clock frequency in the range of 2.60– 2.56 GHz and 16GB RAM. There are 1236 records in total, out of which 988 records are in the training dataset. The remaining 248 records are used as the test samples.

#### **5.1 NIFTY commodities sector**

The ten stocks from the auto sector with the maximum free-float market capitalization and their respective contributions to the computation of the NIFTY commodities sector index according to the report published by the NSE on Dec 31, 2021, are as follows: Reliance Industries (RELIANCE): 10.13, UltraTech Cement (ULTRACEMCO): 7.52, Tata Steel (TATASTEEL): 7.52, NTPC (NTPC): 7.26, JSW Steel (JSWSTEEL): 5.64, Oil & Natural Gas Corporation (ONGC): 5.32, Grasim Industries (GRASIM): 5.31, Hindalco Industries (HINDALCO): 5.23, Coal India (COALINDIA): 4.05, and UPL (UPL): 3.32 [3]. The figures mentioned along with the names of the stocks represent the respective weights (in percent) of the stocks used in computing the sectoral index of the commodities sector. The ticker names of the stocks are mentioned within parentheses in upper case.


#### **Table 1.**

*NIFTY commodities sector portfolio weights allocation.*

*Portfolio Optimization: A Comparative Study DOI: http://dx.doi.org/10.5772/intechopen.112407*

The weights assigned by the MVP, HRP, and the autoencoder (ENC) portfolio based on the training data (January 1, 2018–December 31, 2021) are presented in **Table 1**. **Figure 5** depicts the portfolio weights allocated by the portfolios in the form of pie charts. NTPC received the maximum weights from the MVP and the HRP portfolios. The ENC portfolio assigned the maximum weight to JSWSTEEL.

**Figures 6** and **7** show the cumulative daily returns of the portfolios over the training and the test periods, respectively. These plots depict the cumulative daily returns of the portfolios. The portfolio yielding a higher cumulative return is more profitable for the investors. However, the returns need to be adjusted by their associated risks. Hence, the portfolio risks and the values of their Sharpe ratios are computed so that the performances of the portfolios can be compared based on their respective Sharpe ratios.

In **Table 2**, the summary of the performances of the two portfolios of the au-to sector is presented for the training and the test periods. For both training and test periods, the annual returns, annual volatilities (i.e., standard deviations), and the max Sharpe ratio are tabulated in **Table 2**. The RL portfolio has yielded the highest Sharpe ratios for both training and test data for the auto sector.

**Figure 5.**

*Weight allocation to the stocks of the NIFTY commodity sector by the MVP, HRP and autoencoder (ENC) portfolios.*

#### **Figure 6.**

*Cumulative daily returns yielded by the NIFTY commodities sector portfolios for the training period from January 1, 2018, to December 31, 2021.*

#### **Figure 7.**

*Cumulative daily returns yielded by the NIFTY commodities sector portfolios for the test period from January 1, 2022, to December 31, 2022.*


**Table 2.**

*Portfolio performance on the NIFTY commodities sector.*

#### **5.2 NIFTY energy sector**

The ten stocks from the NIFTY Energy sector with the maximum free-float market capitalization and their respective contributions to the computation of the NIFTY commodities sector index according to the report published by the NSE on Dec 31, 2021, are as follows: Reliance Industries (RELIANCE): 35.92, NTPC (NTPC): 13.92, Power Grid Corporation of India (POWERGRID): 13.05, Oil & Natural Gas Corporation (ONGC): 10.19, Tata Power Company (TATAPOWER): 5.89, Bharat Petroleum Corporation (BPCL): 5.32, Indian Oil Corporation (IOC): 4.98, GAIL India (GAIL): 4.75, Adani Transmission (ADANITRANS): 3.08, and Adani Green Energy (ADANIGREEN): 2.90 [3]. The figures mentioned along with the names of the stocks represent the respective weights (in percent) of the stocks used in computing the sectoral index of the commodities sector. The ticker names of the stocks are mentioned within parentheses in upper case.

The weights assigned by the MVP, HRP, and the autoencoder (ENC) portfolio based on the training data (January 1, 2018–December 31, 2021) are presented in **Table 3**. **Figure 8** depicts the portfolio weights allocated by the portfolios in the form of pie charts. POWERGRID received the maximum weights from all three portfolios, MVP, HRP, and ENC.

#### *Portfolio Optimization: A Comparative Study DOI: http://dx.doi.org/10.5772/intechopen.112407*


*NIFTY energy sector portfolio weights allocation.*

**Figure 8.**

*Weight allocation to the stocks of the NIFTY energy sector by the MVP, HRP and autoencoder (ENC) portfolios.*

#### **Figure 9.**

*Cumulative daily returns yielded by the NIFTY energy sector portfolios for the training period from January 1, 2018, to December 31, 2021.*

#### **Figure 10.**

*Cumulative daily returns yielded by the NIFTY energy sector portfolios for the test period from January 1, 2022, to December 31, 2022.*


#### **Table 4.**

*Portfolio performance in the NIFTY energy sector.*

**Figures 9** and **10** show the cumulative returns of the portfolios over the training and the test periods, respectively. In **Table 4**, the summary of the performances of the three portfolios of the NIFTY energy sector is presented for the training and the test periods, in which the annual returns, annual volatilities (i.e., standard deviations), and the max Sharpe ratio are tabulated.

#### **5.3 NIFTY manufacturing sector**

The ten stocks from the NIFTY manufacturing sector with the maximum free-float market capitalization and their respective contributions to the computation of the overall sectoral index according to the report published by the NSE on Dec 31, 2021, are as follows: Sun Pharmaceuticals Industries (SUNPHARMA): 4.96, Reliance Industries (RELIANCE): 4.73, Mahindra & Mahindra (M&M): 4.59, Tata Steel (TATASTEEL): 4.55, Maruti Suzuki (MARUTI): 4.33, JSW Steel (JSWSTEEL): 3.41, Hindalco Industries (HINDALCO): 3.16, Tata Motors (TATAMOTORS): 2.85, Dr. Reddy's Laboratories (DRREDDY): 2.85, and Cipla (CIPLA): 2.66 [3]. The figures mentioned along with the names of the stocks represent the respective weights (in percent) of the stocks used in computing the sectoral index of the manufacturing sector. The ticker names of the stocks are mentioned within parentheses in upper case.

#### *Portfolio Optimization: A Comparative Study DOI: http://dx.doi.org/10.5772/intechopen.112407*


#### **Table 5.**

*NIFTY manufacturing sector portfolio weights allocation.*

**Figure 11.**

*Weight allocation to the stocks of the NIFTY manufacturing sector by the MVP, HRP, and autoencoder (ENC) portfolios.*

The weights assigned by the MVP, HRP, and autoencoder (ENC) portfolio based on the training data (January 1, 2018 – December 31, 2021) are presented in **Table 5**. **Figure 11** depicts the portfolio weights allocated by the portfolios in the form of pie charts. DRREDDY, CIPLA, and SUNPHARMA received the highest allocation by the MVP, HRP, and ENC portfolios.

**Figures 12** and **13** show the cumulative returns of the portfolios over the training and the test periods, respectively. In **Table 6**, the summary of the performances of the three portfolios of the NIFTY manufacturing sector is presented for the training and the test periods, in which the annual returns, annual volatilities (i.e., standard deviations), and the max Sharpe ratio are tabulated.

#### **5.4 NIFTY services sector**

The ten stocks from the NIFTY services sector with the maximum free-float market capitalization and their respective contributions to the computation of the overall sectoral index according to the report published by the NSE on Dec 31, 2021,

#### **Figure 12.**

*Cumulative daily returns yielded by the NIFT manufacturing sector portfolios for the training period from January 1, 2018, to December 31, 2021.*

#### **Figure 13.**

*Cumulative daily returns yielded by the NIFTY manufacturing sector portfolios for the test period from January 1, 2022, to December 31, 2022.*


#### **Table 6.**

*Portfolio performance in the NIFTY manufacturing sector.*

are as follows: HDFC Bank (HDFCBANK): 15.11, ICICI Bank (ICICIBANK): 12.78, Infosys (INFY): 4.59, Housing Development Finance Corporation (HDFC): 10.09, Tata Consultancy Services (TCS): 7.28, Kotak Mahindra Bank (KOTAKBANK): 5.37, Axis Bank (AXISBANK): 4.90, State Bank of India (SBIN): 4.30, Bharti Airtel (BHARTIARTL): 3.98, and Bajaj Finance (BAJFINANCE): 3.49 [3]. The figures mentioned along with the names of the stocks represent the respective weights (in percent) of the stocks used in computing the sectoral index of the NIFTY services sector.

The weights assigned by the MVP, HRP, and the autoencoder (ENC) portfolio based on the training data (January 1, 2018 – December 31, 2021) are presented in **Table 7**. **Figure 14** depicts the portfolio weights allocated by the portfolios in the form of pie charts. TCS received the maximum weights from the MVP and HRP portfolios. The ENC portfolio assigned the highest weight to KOTAKBANK.

**Figures 15** and **16** show the cumulative returns of the portfolios over the training and the test periods, respectively. In **Table 8**, the summary of the performances of the three portfolios of the NIFTY services sector is presented for the training and the test periods, in which the annual returns, annual volatilities (i.e., standard deviations), and the max Sharpe ratio are tabulated.


#### **Table 7.**

*NIFTY services sector portfolio weights allocation.*

#### **Figure 15.**

*Cumulative daily returns yielded by the NIFTY services sector portfolios for the training period from January 1, 2018, to December 31, 2021.*

#### **Figure 16.**

*Cumulative daily returns yielded by the NIFTY services sector portfolios for the test period from January 1, 2022, to December 31, 2022.*


#### **Table 8.**

*Portfolio performance in the NIFTY services sector.*

#### **5.5 NIFTY MNC sector**

The ten stocks from the NIFTY MNC sector with the maximum free-float market capitalization and their respective contributions to the computation of the overall sectoral index according to the report published by the NSE on Dec 31, 2021, are as follows: Maruti Suzuki (MARUTI): 10.82, Hindustan Unilever (HINDUNILVR): 9.88, Nestle India (NESTLEIND): 9.83, Britannia Industries (BRITANNIA): 9.12, Vedanta (VEDL): 5.18, Siemens (SIEMNS): 5.00, Ambuja Cements (AMBUJACEM): 4.35, United Spirits (MCDOWELL-N): 3.82, Cummins India (CUMMINSIND): 3.69, and Ashok Leyland (ASHOKLEY): 3.62 [3]. The figures mentioned along with the names of the stocks represent the respective weights (in percent) of the stocks used in computing the sectoral index of the NIFTY MNC sector.

The weights assigned by the MVP, HRP, and the autoencoder (ENC) portfolio based on the training data (January 1, 2018 – December 31, 2021) are presented in **Table 9**. **Figure 17** depicts the portfolio weights allocated by the portfolios in the form of pie charts. HINDUNILVR, NESTLEIND, and VEDL received the maximum weights from the MVP, HRP, and ENC portfolios, respectively.

**Figures 18** and **19** show the cumulative returns of the portfolios over the training and the test periods, respectively. In **Table 10**, the summary of the performances of


#### **Table 9.**

*NIFTY MNC sector portfolio weights allocation.*

**Figure 17.**

*Weight allocation to the stocks of the NIFTY MNC sector by the MVP, HRP and autoencoder (ENC) portfolios.*

#### **Figure 18.**

*Cumulative daily returns yielded by the NIFTY MNC sector portfolios for the training period from January 1, 2018, to December 31, 2021.*

#### **Figure 19.**

*Cumulative daily returns yielded by the NIFTY MNC sector portfolios for the test period from January 1, 2022, to December 31, 2022.*


#### **Table 10.**

*Portfolio performance on the NIFTY MNC sector.*

the three portfolios of the NIFTY MNC sector is presented for the training and the test periods, in which the annual returns, annual volatilities (i.e., standard deviations), and the max Sharpe ratio are tabulated.

#### **5.6 NIFTY transportation and logistics sector**

The ten stocks from the NIFTY transportation and logistics sector with the maximum free-float market capitalization and their respective contributions to the computation of the overall sectoral index according to the report published by the NSE on Dec 31, 2021, are as follows: Mahindra & Mahindra (M&M): 14.73, Maruti Suzuki (MARUTI): 13.89, Tata Motors (TATAMOTORS): 9.14, Adani Ports and Special Economic Zone (ADANI PORTS): 5.43, Eicher Motors (EICHERMOT): 5.25, Bajaj Auto (BAJAJ-AUTO): 5.02, Hero MotoCorp (HEROMOTOCO): 3.81, Tube Investments of India (TIINDIA): 3.50, TVS Motor Company (TVSMOTOR): 3.05, and Ashok Leyland (ASHOKLEY): 2.54 [3]. The figures mentioned along with the names of the stocks represent the respective weights (in percent) of the stocks used in computing the sectoral index of the NIFTY transportation and logistics sector.

The weights assigned by the MVP, HRP, and the autoencoder (ENC) portfolio based on the training data (January 1, 2018–December 31, 2021) are presented in **Table 11**. **Figure 20** depicts the portfolio weights allocated by the portfolios in the form of pie charts. BAJAJ-AUTO received the maximum weights from all three portfolios, MVP, HRP, and ENC.


**Table 11.**

*NIFTY transport & logistics sector portfolio weights allocation.*

#### **Figure 20.**

*Weight allocation to the stocks of the NIFTY transportation and logistics sector by the MVP, HRP, and autoencoder (ENC) portfolios.*

**Figures 21** and **22** show the cumulative returns of the portfolios over the training and the test periods, respectively. In **Table 12**, the summary of the performances of the three portfolios of the NIFTY transportation and logistics sector is presented for

#### **Figure 21.**

*Cumulative daily returns yielded by the NIFTY transportation & logistics sector portfolios for the training period from January 1, 2018, to December 31, 2021.*

#### **Figure 22.**

*Cumulative daily returns yielded by the NIFTY transportation & logistics sector portfolios for the test period from January 1, 2022, to December 31, 2022.*


#### **Table 12.**

*Portfolio performance on the NIFTY transport & logistics sector.*

the training and the test periods, in which the annual returns, annual volatilities (i.e., standard deviations), and the max Sharpe ratio are tabulated.

#### **5.7 NIFTY infrastructure sector**

The ten stocks from the NIFTY infrastructure sector with the maximum free-float market capitalization and their respective contributions to the computation of the overall sectoral index according to the report published by the NSE on Dec 31, 2021, are as follows: Reliance Industries (RELIANCE): 19.25, Larsen & Toubro (LT): 15.47, Bharti Airtel (BHARTIARTL): 11.28, UltraTech Cement (ULTRACEMCO): 11.28, NTPC (NTPC): 4.92, Power Grid Corporation of India (POWERGRID): 4.61, Oil & Natural Corporation (ONGC): 3.60, Grasim Industries (GRASIM): 3.59, Apollo Hospitals Enterprise (APOLLOHOSP): 2.73, and Adani Ports and Special Economic Zone (ADANIPORTS): 2.72 [3]. The figures mentioned along with the names of the stocks represent the respective weights (in percent) of the stocks used in computing the sectoral index of the NIFTY infrastructure sector.

The weights assigned by the MVP, HRP, and the autoencoder (ENC) portfolio based on the training data (January 1, 2018 – December 31, 2021) are presented in **Table 13**. **Figure 23** depicts the portfolio weights allocated by the portfolios in the form of pie charts. POWERGRID received the maximum weights from all three portfolios, MVP, HRP, and ENC.

**Figures 24** and **25** show the cumulative returns of the portfolios over the training and the test periods, respectively. In **Table 14**, the summary of the performances of the three portfolios of the NIFTY infrastructure sector is presented for the training and the test periods, in which the annual returns, annual volatilities (i.e., standard deviations), and the max Sharpe ratio are tabulated.

#### **5.8 NIFTY housing sector**


The ten stocks from the NIFTY housing sector with the maximum free-float market capitalization and their respective contributions to the computation of the

#### **Table 13.**

*NIFTY infrastructure sector portfolio weights allocation.*

**Figure 23.**

*Weight allocation to the stocks of the NIFTY infrastructure sector by the MVP, HRP and autoencoder (ENC) portfolios.*

**Figure 24.**

*Cumulative daily returns yielded by the NIFTY infrastructure sector portfolios for the training period from January 1, 2018, to December 31, 2021.*

**Figure 25.**

*Cumulative daily returns yielded by the NIFTY infrastructure sector portfolios for the test period from January 1, 2022, to December 31, 2022.*


#### **Table 14.**

*Portfolio performance on the NIFTY infrastructure sector.*

overall sectoral index according to the report published by the NSE on Dec 31, 2021, are as follows: Larsen & Toubro (LT): 11.25, Asian Paints (ASIANPAINT): 8.59, HDFC Bank (HDFCBANK): 6.99, ICICI Bank (ICICIBANK): 5.92, UltraTech Cement (ULTRACEMCO): 5.65, Tata Steel (TATASTEEL): 5.65, NTPC (NTPC): 5.46, Housing Development Finance Corporation (HDFC): 4.67, JSW Steel (JSWSTEEL): 4.24, and Grasim Industries (GRASIM): 3.99 [3]. The figures mentioned along with the names of the stocks represent the respective weights (in percent) of the stocks used in computing the sectoral index of the NIFTY infrastructure sector.

The weights assigned by the MVP, HRP, and the autoencoder (ENC) portfolio based on the training data (January 1, 2018 – December 31, 2021) are presented in **Table 15**. **Figure 26** depicts the portfolio weights allocated by the portfolios in the form of pie charts. ASIANPAINT received the maximum weights from the MVP and HRP portfolios. The ENC portfolio assigned the highest weight to NTPC.

**Figures 27** and **28** show the cumulative returns of the portfolios over the training and the test periods, respectively. In **Table 16**, the summary of the performances of the three portfolios of the NIFTY housing sector is presented for the training and the test periods, in which the annual returns, annual volatilities (i.e., standard deviations), and the max Sharpe ratio are tabulated.


#### **Table 15.**

*NIFTY housing sector portfolio weights allocation.*

**Figure 26.**

*Weight allocation to the stocks of the NIFTY housing sector by the MVP, HRP and autoencoder (ENC) portfolios.*

#### **Figure 27.**

*Cumulative daily returns yielded by the NIFTY housing sector portfolios for the training period from January 1, 2018, to December 31, 2021.*

#### **Figure 28.**

*Cumulative daily returns yielded by the NIFTY housing sector portfolios for the test period from January 1, 2022, to December 31, 2022.*


#### **Table 16.**

*Portfolio performance on the NIFTY housing sector.*

#### **5.9 NIFTY consumption sector**

The ten stocks from the NIFTY consumption sector with the maximum free-float market capitalization and their respective contributions to the computation of the overall sectoral index according to the report published by the NSE on Dec 31, 2021, are as follows: ITC (ITC): 11.25, Hindustan Unilever (HINDUNILVR): 10.08, Bharti Airtel (BHARTIARTL): 9.69, Asian Paints (ASIANPAINT): 7.35, Mahindra & Mahindra (M&M): 7.01, Maruti Suzuki (MARUTI): 6.61, Titan Company (TITAN): 5.71, Nestle India (NESTLEIND): 3.84, Britannia Industries (BRITANNIA): 3.04, and Avenue Supermarts (DMART): 2.81 [3]. The figures mentioned along with the names of the stocks represent the respective weights (in percent) of the stocks used in computing the sectoral index of the NIFTY consumption sector.

The weights assigned by the MVP, HRP, and the autoencoder (ENC) portfolio based on the training data (January 1, 2018 – December 31, 2021) are presented in **Table 17**. **Figure 29** depicts the portfolio weights allocated by the portfolios in the form of pie charts. ITC received the maximum weight from the MVP and HRP portfolios. The ENC portfolio assigned the highest weight to TITAN.

**Figures 30** and **31** show the cumulative returns of the portfolios over the training and the test periods, respectively. In **Table 18**, the summary of the performances of


#### **Table 17.**

*NIFTY consumption sector portfolio weights allocation.*

**Figure 29.**

*Weight allocation to the stocks of the NIFTY consumption sector by the MVP, HRP, and autoencoder (ENC) portfolios.*

#### **Figure 30.**

*Cumulative daily returns yielded by the NIFTY consumption sector portfolios for the training period from January 1, 2018, to December 31, 2021.*

**Figure 31.**

*Cumulative daily returns yielded by the NIFTY consumption sector portfolios for the test period from January 1, 2022, to December 31, 2022.*


#### **Table 18.**

*Portfolio performance on the NIFTY consumption sector.*

the three portfolios of the NIFTY consumption sector is presented for the training and the test periods, in which the annual returns, annual volatilities (i.e., standard deviations), and the max Sharpe ratio are tabulated.

#### **5.10 NIFTY 100 ESG sector**

The ten stocks from the NIFTY 100 ESG sector with the maximum free-float market capitalization and their respective contributions to the computation of the overall sectoral index according to the report published by the NSE on Dec 31, 2021, are as follows: Infosys (INFY): 6.36, Tata Consultancy Services (TCS): 5.99, Housing Development Finance Corporation (HDFC): 4.82, HCL Technologies (HCLTECH): 3.30, ICICI Bank (ICICIBANK): 2.92, Bharti Airtel (BHARTIARTL): 2.81, Tech Mahindra (TECHM): 2.76, Kotak Mahindra Bank (KOTAKBANK): 2.69, Bajaj Finance (BAJFINANCE): 2.69, and Titan Company (TITAN): 2.69 [3]. The figures mentioned along with the names of the stocks represent the respective weights (in percent) of the stocks used in computing the sectoral index of the NIFTY 100 ESG sector.

The weights assigned by the MVP, HRP, and the autoencoder (ENC) portfolio based on the training data (January 1, 2018 – December 31, 2021) are presented in **Table 19**. **Figure 32** depicts the portfolio weights allocated by the portfolios in the


#### **Table 19.**

*NIFTY 100 ESG sector portfolio weights allocation.*

**Figure 32.** *Weight allocation to the stocks of the NIFTY 100 ESG sector by the MVP, HRP and autoencoder (ENC) portfolios.*

form of pie charts. TCS received the maximum weight from the MVP and HRP portfolios. The ENC portfolio assigned the highest weight to BHARTIARTL.

**Figures 33** and **34** show the cumulative returns of the portfolios over the training and the test periods, respectively. In **Table 20**, the summary of the performances of the three portfolios of the NIFTY 100 ESG sector is presented for the training and the test periods, in which the annual returns, annual volatilities (i.e., standard deviations), and the max Sharpe ratio are tabulated.

A summary of the results of the performance of the portfolios on the training data for the ten sectors is exhibited in **Table 21**. In **Table 21**, for each sector, the maximum return and Sharpe ratio, and minimum volatility values are presented in bold case. It is observed that the ENC portfolio produced the highest returns for five sectors, while the highest values of the Sharpe ratio were yielded by the MVP portfolio for six sectors. However, the MVP portfolio produced the minimum values of volatility for all ten sectors. Hence, it is concluded that on the training data, the ENC portfolio has exhibited the best performance on the metric annual return, while on the metrics Sharpe ratio and volatility, the MVP portfolio has performed the best among the three portfolios.

The summary of the results of the performance of the portfolios on the test data is exhibited in **Table 22**, in which, for each sector, the maximum return and Sharpe

#### **Figure 33.**

*Cumulative daily returns yielded by the NIFTY 100 ESG sector portfolios for the training period from January 1, 2018, to December 31, 2021.*

#### **Figure 34.**

*Cumulative daily returns yielded by the NIFTY 100 ESG sector portfolios for the test period from January 1, 2022, to December 31, 2022.*


#### **Table 20.**

*Portfolio performance on the NIFTY 100 ESG sector.*

ratio, and minimum volatility values are presented in bold case. It is observed that the ENC portfolio produced the highest returns for five sectors, while the highest values of the Sharpe ratio were yielded by the MVP portfolio for six sectors. However, the MVP portfolio produced the minimum values of volatility for all eight sectors. Hence, it is concluded that on the test data, the ENC portfolio has exhibited the best performance on the metric annual return, while on the metrics Sharpe ratio and volatility, the MVP portfolio has performed the best among the three portfolios.

It is interesting to note that the ENC portfolio has yielded the maximum return for the majority of the sectors both on the training and the test data. Hence, for investors looking for higher returns, the best option is to follow the autoencoder-based (ENC) portfolio. However, for those investors who also take into account the risk associated with investments, the MVP portfolio is the best option as this portfolio has yielded the highest risk-adjusted returns for most of the sectors.

It also noted that the transportation sector has produced the highest annual return of 25.73% (which is yielded by the HRP portfolio) among the ten sectors on the test data. The transportation sector has also produced the highest Sharpe ratio (and hence, the highest risk-adjusted return) of 1.2081 (which is yielded by the MVP portfolio) on the test data. The consumption sector exhibited the lowest annual volatility value of 15.57 (which is yielded by the MVP portfolio) among the ten sectors.


**Table** 

*Summary of portfolio performance*

 *on the training data.*
