SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

25
SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN l 0 -TRADING CONSTRAINT ALEX FURGER AND DANIEL JIANG Abstract. Given a set of assets, Markowitz Portfolio Theory [5] devel- ops the idea of a minimum variance portfolio, also called the “Markowitz” portolio. We consider the point of view of a retail, individual investor who wishes to hold a low-risk portfolio, rebalanced weekly. Such an investor suffers from certain limitations that large companies (banks, hedge funds, etc.) do not have. These limitations include small initial capital and limited computing resources. Consequently, sparsity of the portfolio and limited trading during each rebalance become attractive features. We formulate an optimization model for this problem using quadratic and mixed-integer programming, We then demonstrate, us- ing a simulation, that trading strategies, realizable under our investor’s limitations attain near minimal risk. 1. Introduction 1.1. The Markowitz Portfolio. Markowitz Portfolio Theory [5] uses mean- variance analysis on the return vector of a set of assets to construct a port- folio that achieves a given expected return while minimizing the variance, or risk, of the portfolio. As in [3], due to the difficulty of correctly estimating the expected return, we consider the overall minimal risk portfolio with no expected return constraints. We represent a portfolio by identifying the weight, or fraction, of each asset contained in the portfolio. Denote w R n (a vector of n asset weights) as the Markowitz Portfolio if it satisfies the following minimization: (1.1) minimize w w | Cw subject to w | 1 =1 where C = Var(r) denotes the covariance matrix of the asset returns vector r. Hence, the variance of the portfolio can be written as Var(w | r)= w | Cw. 1.2. Limitations of a Retail Investor. We consider the point of view of a retail, or individual, investor who wishes to hold a low risk portfolio, rebalanced weekly. We assume that the investor is subject to a fixed trading cost per transaction, regardless of the number of shares traded. A retail investor using one of several popular online brokers, such as E*TRADE ® or Ameritrade ® , would likely be subjected to a similar fixed trading cost regime rather than be charged per share of stock traded. 1

description

Given a set of assets, Markowitz Portfolio Theory [5] devel- ops the idea of a minimum variance portfolio, also called the “Markowitz” portolio. We consider the point of view of a retail, individual investor who wishes to hold a low-risk portfolio, rebalanced weekly. Such an investor suffers from certain limitations that large companies (banks, hedge funds, etc.) do not have. These limitations include small initial capital and limited computing resources. Consequently, sparsity of the portfolio and limited trading during each rebalance become attractive features. We formulate an optimization model for this problem using quadratic and mixed-integer programming, We then demonstrate, us- ing a simulation, that trading strategies, realizable under our investor’s limitations attain near minimal risk.

Transcript of SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

Page 1: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

SPARSE, MINIMAL VARIANCE PORTFOLIO

REBALANCED WITH AN l0-TRADING CONSTRAINT

ALEX FURGER AND DANIEL JIANG

Abstract. Given a set of assets, Markowitz Portfolio Theory [5] devel-ops the idea of a minimum variance portfolio, also called the “Markowitz”portolio. We consider the point of view of a retail, individual investorwho wishes to hold a low-risk portfolio, rebalanced weekly. Such aninvestor suffers from certain limitations that large companies (banks,hedge funds, etc.) do not have. These limitations include small initialcapital and limited computing resources. Consequently, sparsity of theportfolio and limited trading during each rebalance become attractivefeatures. We formulate an optimization model for this problem usingquadratic and mixed-integer programming, We then demonstrate, us-ing a simulation, that trading strategies, realizable under our investor’slimitations attain near minimal risk.

1. Introduction

1.1. The Markowitz Portfolio. Markowitz Portfolio Theory [5] uses mean-variance analysis on the return vector of a set of assets to construct a port-folio that achieves a given expected return while minimizing the variance, orrisk, of the portfolio. As in [3], due to the difficulty of correctly estimatingthe expected return, we consider the overall minimal risk portfolio with noexpected return constraints.

We represent a portfolio by identifying the weight, or fraction, of eachasset contained in the portfolio. Denote w ∈ Rn (a vector of n asset weights)as the Markowitz Portfolio if it satisfies the following minimization:

(1.1)minimize

wwᵀCw

subject to wᵀ1 = 1

where C = Var(r) denotes the covariance matrix of the asset returns vectorr. Hence, the variance of the portfolio can be written as Var(wᵀr) = wᵀCw.

1.2. Limitations of a Retail Investor. We consider the point of viewof a retail, or individual, investor who wishes to hold a low risk portfolio,rebalanced weekly. We assume that the investor is subject to a fixed tradingcost per transaction, regardless of the number of shares traded. A retailinvestor using one of several popular online brokers, such as E*TRADE®

or Ameritrade®, would likely be subjected to a similar fixed trading costregime rather than be charged per share of stock traded.

1

Page 2: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

Because a retail investor trades on a relatively small scale (compared tolarger companies like banks or hedge funds), there are several limitationsthat we need to consider in the formulation of our problem. They are asfollows:

– Small initial capital. This implies, in particular, that trading costscannot be considered negligible for a retail trader. In fact, we mustpay particular attention to the number of trades that are madeduring the weekly rebalance and reflect it in our model. For ex-ample, consider a retail investor who wishes to hold the weekly-rebalanced Markowitz Portfolio wMK for a set of 50 stocks. Assum-ing wWK has all non-zero components and each rebalance requiresa change in position for 20% of the stocks (a conservative assump-tion), then for a fixed trading cost of $15 per trade over 52 weeks,$15 · 50 · 0.2 · 52 = $7800 needs to be allotted for trading costs alone.For a retail investor with under $100,000, this is a significant amountof money. Therefore, we must penalize the number of trades madewhile controlling the risk.

– Requirement for a sparse portfolio. From the standpoint of portfoliomanagement, a sparse portfolio is clearly desirable for any investor.More importantly, however, a sparse portfolio is more likely to berealizable for a retail investor with limited capital. For an investorholding initial capital X, we need to invest XwMK

i into stock i. But,for a non-sparse portfolio, wMK

i is small, and maybe so small thatXwMK

i is less than the cost of one share of stock i.– Limited computing resources. Our model must be efficiently solvable

without the need for high computing power.

2. Model

2.1. Overview. Let wt ∈ Rn be the portfolio (of n assets) to be held attime t, rebalanced from wt−1. Note that in the problem formulated above, t

is measured in weeks. Let Ct,m be the estimated covariance matrix at timet using the last m available data points (daily data is used in this example).

The l0-norm of a vector v, denoted by ‖v‖0, is defined as the number ofnon-zero components of v. We use the l0-norm to model both sparsity andthe number of trades made at each rebalance. Therefore, when rebalancingat time t and using a constant m data points for covariance estimation, wewish to minimize the following, subject to wᵀ

t 1 = 1:

— Variance: wᵀt Ct,mwt

— Number of stocks held: ‖wt‖0— Number of trades made: ‖wt −wt−1‖0

We could formulate an optimization problem by minimizing the weightedsum of these terms subject to the constraint wᵀ

t 1 = 1. Because the l0-normcan be modeled using binary variables, the following mixed-integer-quadratic

2

Page 3: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

program (MIQP) would solve our problem. For user-specified weights λ1 andλ2:

(2.1)minimize

wt

wᵀt Ct,mwt + λ1‖wt‖0 + λ2‖wt −wt−1‖0

subject to wᵀt 1 = 1

2.2. Alternative Two-Stage Optimization. Unfortunately, a high di-mensional MIQP program is not easy to solve. When taking into accountthe need for an investor to perform parameter calibration (for λ1 and λ2)computation times of this magnitude are unacceptable. However, separately,quadratic programs (QP) and a mixed-integer programs (MIP) can be muchmore efficiently solved.

Therefore, to address efficiency, we propose a method that solves twoseparate optimization problems instead. First, we compute the MarkowitzPortfolio for the estimated Ct,m, a QP with continuous variables, and callit our “target” portfolio. Now, we can apply a technique used in [1] toconstruct a portfolio using limited number of assets to mimic the behaviorof a target portfolio. We solve a MIP (only linear constraints) that returnsa portfolio that most closely “matches” the target portfolio, in the sensethat l1-norm of the difference is small, while also controlling the sparsityand number-of-trades terms.

This two-stage problem is much more efficiently solved than the combinedMIQP represented by (2.1). The Stage 1 optimization is exactly (1.1) using

the covariance matrix estimation Ct,m. Let wMKt be the optimal solution

to the following QP:

(2.2)minimize

wt

wᵀt Ct,mwt

subject to wᵀt 1 = 1

The Stage 2 optimization problem uses wMKt as its target portfolio and

can be written as:

(2.3)minimize

wt

‖wt −wMKt ‖1 + λ1‖wt‖0 + λ2‖wt −wt−1‖0

subject to wᵀt 1 = 1

2.3. Covariance Estimation using a Factor Model. We hypothesizethat the covariance matrix estimated using more recent data will moreclosely represent the actual covariance for the next week, based on the as-sumption that recent data will more strongly capture the current eventsimpacting the market. We can think of such an estimator as being a good“local” approximation.

The sample covariance estimator requires a large sample size to producea good estimator. In order to use a small but recent set of samples, we applyfactor models as in [2] to estimate C. We apply this technique using Fama-French Three Factor Model, which models the excess returns of an asset

3

Page 4: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

using common factors: the market’s return, asset’s market capitalizations,and asset’s book-to-market ratios [4].

The excess return y of stock i at time t is modeled by yit = bᵀi ft+uit, where

ft are the Fama-French factors at time t, bi are factor loadings determinedby linear regression, and uit is an error term.

Then, the estimator is:

(2.4) C = cov(yt) = Bcov(ft)Bᵀ + cov(ut).

As in [2], cov(ft) is the sample covariance estimator and cov(ut) is a thresh-olded sample covariance estimator whose formula we will omit. Note thatthis estimator can be applied to cases even when the number of data pointsis less than or on the order of the number of assets.

2.4. Adding a Gross Exposure Constraint. Regardless of how C isestimated, it remains true that C is a noisy estimate of C. Thus, we expectwᵀCw to be extremely noisy due to the accumulation of errors. It was shownin [3] that by adding a gross exposure constraint, in the form of ‖w‖1 ≤ c,the accumulation of errors can be avoided. Suppose that:

w∗ = argminwᵀ1=1, ‖w‖1≤cwᵀCw

w∗ = argminwᵀ1=1, ‖w‖1≤cwᵀCw

Then:

|w∗ᵀCw∗ − w∗ᵀCw∗| ≤ amc2

where am is the maximum component wise estimation error. A typical valueof c is 1.6, which means the portfolio will be near 130% long and 30% short.We note that this constraint is realistic in the setting of our problem becausea retail investor is unlikely to take any extreme long or short positions inany one asset. (2.2) and (2.3) can be updated as follows. Let wc

t be theoptimal solution to (2.5):

(2.5)minimize

wt

wᵀt Ct,mwt

subject to wᵀt 1 = 1, ‖wt‖1 ≤ c

Then, our estimated portfolio is the solution to:

(2.6)minimize

wt

‖wt −wct‖1 + λ1‖wt‖0 + λ2‖wt −wt−1‖0

subject to wᵀt 1 = 1

2.5. Formulation for Optimization Software. We use a nonnegativevector x to represent the l1 constraint and binary vectors y and z along witha large constant M to approximately represent the l0 constraint linearly inthe binary vectors y and z. (2.5) and (2.6) can be formulated explicitly asa QP and MIP. Let wc

t be the optimal solution to (2.7).4

Page 5: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

(2.7)

minimizewt

wᵀt Ct,mwt

subject to wᵀt 1 = 1

xᵀ1 ≤ c− x ≤ wt ≤ x

x ≥ 0

(2.8)

minimizewt

xᵀ1 + λ1yᵀ1 + λ2z

ᵀ1

subject to wᵀt 1 = 1

− x ≤ wt −wct ≤ x

−My ≤ wt ≤My

−Mz ≤ wt −wt−1 ≤Mz

x ≥ 0

y ∈ {0, 1}n

z ∈ {0, 1}n

To see why M is needed, consider ‖v‖0 and a binary vector b. We canconsider the components of b to be indicators for the nonzero componentsof v. Then, minimizing ‖v‖0 is equivalent to minimizing bᵀ1. However, ifwe simply use −b ≤ v ≤ b, then the components of v are forced between−1 and 1 when allowed to be nonzero. Introducing the constant M will thusremedy this problem.

5

Page 6: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

3. Data

3.1. Stock Selection. To attain empirical results, we considered a repre-sentative subset of the S&P500, the top 5 companies of each sector by marketcapitalization, as shown in Figure 1. We use the model described above toexamine the problem where the retail investor is interested in building aportfolio out of these 50 stocks for the year 2011.

Cons. Disc. MCD AMZN DIS HD CMCSA

Cons. Stap. WMT PG KO PM PEP

Energy XOM CVX SLB COP OXY

Financials WFC JPM C BRK.A BAC

Health Care JNJ PFE MRK ABT UNH

Industrials GE UTX CAT MMM BA

IT AAPL MSFT IBM GOOG ORCL

Materials DD MON FCX DOW PX

Telecom T VX CTL CCI S

Utilities SO D DUK EXC NEE

Figure 1. Top 5 companies in the S&P500 of each sectorby market capitalization

3.2. Simulated Stock Data. We first examine simulated data, generatedas in Section 5 of [2] using T data points of daily returns and factor data(yt, ft) from 2011 and a variable “warm-up” period of m days. There aretwo steps to this process: Calibration and Sample Generation. A summaryof the process is described below; for the full technical details, see [2].

3.2.1. Calibration. First, the least squares estimator of the factor loadings Bis determined according to yt = Bft + ut. Then, µB and ΣB are estimated

to create a 3-dimensional normal distribution from the rows of B. Next,a sparse, positive definite estimate of Σu is created, which has the formof a diagonal matrix plus a rank 1 matrix. A VAR(1) model is also fittedaccording to historical factors ft. The model has the form ft = µ+Φft−1+εt.With these components and assuming Gaussian distributions for bi and ut,we have all of the necessary information to generate simulated returns usingthe factor model.

3.2.2. Sample Generation. The following method is used to sample (notethat a single “sample” consists of an entire sample path for each of the 50stocks).

(1) Generate {bi}50i=1 independently fromN3(µB,ΣB). Set B = (b1, . . . ,b50)ᵀ.

6

Page 7: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

(2) Generate {ut}Tt=1 independently from N50(0,Σu).(3) Generate {ft}Tt=1 from the VAR(1) model ft = µ + Φft−1 + εt.(4) Calculate yt = Bft + ut for t = 1, . . . , T .

Figure 2. Single sample of 50 simulated stocks

Figure 3. Actual returns of the 50 stocks

7

Page 8: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

4. Simulation

4.1. Procedure Summary. From the point of view of a retail investorbeginning to trade in January 2011 who wishes to hold a weekly-rebalanced,low variance portfolio, we investigate the performance of our optimizationmodel. We simulate the trading strategy using these assumptions from thefirst trading day of 2011 until the last trading day of 2011. MATLAB andGurobi were used to implement and run the simulation.

The following summarizes our highest level function, which simulatesweekly rebalancing over a year. See the Appendix for source code.

start← Jan 3, 2011, end← Dec 30, 2011m← number of previous data points to use for covariance estimationt← start, wlast ← 0

while t < end doreturns← getPreviousReturns(m)factors← getPreviousFactors(m)

Ct,m ← estimateCov(returns, factors)

wct ← optimizeStageOne(Ct,m)wt ← optimizeStageTwo(wct , wlast)

t← computeWeekLastTradingDay(t)wlast ← wt

end while

4.2. Parameter Selection. Ranges for the two parameters λ1 and λ2 of(2.7) and (2.8) need to be found so that the resulting portfolios exhibit lowvolatility, yet are realizable under the constraints of a retail investor. Weconsidered intervals of the form [0, λMAX

1 ] and [0, λMAX2 ]. If λMAX

1 is toolarge: as λ1 increases toward λMAX

1 the optimal portfolios tend toward aportfolio that is 100% invested in a single stock because sparsity becomesheavily rewarded. On the other hand, if λMAX

2 is too large, then no tradeswill occur after the first week because trading becomes too heavily penalized.

We found that in general, λ1 and λ2 values beyond λMAX1 = 0.15 and

λMAX2 = 0.05 exhibit these undesired behaviors. Hence, we consider λ1 ∈

[0, 0.15] and λ2 ∈ [0, 0.05]. In general, these ranges need to be user-calibratedand one should not expect these ranges to be appropriate for any tradingperiod.

In addition, we must choose the number of data points to use for co-variance matrix estimation. Using fewer than m = 100 points producescovariance matrices that are not positive definite, which we cannot havebecause positive definiteness implies convexity in the QP (Gurobi will notoptimize otherwise) and we expect the true covariance matrix to be positivedefinite (all covariance matrices are positive semi-definite).

8

Page 9: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

Since we are aiming to use data for covariance matrix estimation that isas recent as possible, m = 100 is used for the simulation.

5. Results

5.1. Example of Optimal Portfolios. In this subsection, we show an ex-ample that visualizes the evolution of a portfolio as it is rebalanced weeklythroughout a year. Figure 4 shows a sequence of portfolios generated by theoptimization model using moderate levels of both λ1 and λ2. The verticalaxis represents stocks and the horizontal axis represents time, with the hor-izontal grid being measured in weeks. Trades (a change in the weight of aparticular stock from one week to the next) are illustrated by color changes.

We note that out of 50 stocks, these portfolios rarely consist of more than15 stocks and hold from 10-15 the large majority of the time. Moreover, wecan see that often, positions are held constant for weeks at a time, due to thepenalized trading term of the objective function. At least qualitatively, wecan see that the portfolios represented in this figure constitute a realizablestrategy under the limitations of a retail investor.

Figure 4. Weekly optimal portfolios for λ1 = 0.03 and λ2 = 0.03

9

Page 10: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

5.2. Detailed Simulation Results. A simulation was ran for 36 pairs of(λ1, λ2) in the ranges specified above on both real data and 50 samples ofsimulated data for the year 2011.

5.2.1. Tables and Plots. The following tables and plots summarize the re-sults of the simulation by examining annualized volatility of the returns for2011, the total number of trades in 2011, and the starting portfolio size foreach trading strategy (i.e., each parameter pair).

λ1, λ2 0.00 0.01 0.02 0.03 0.04 0.05

0.00 8.02± (0.97) 8.01± (0.98) 8.01± (0.97) 8.04± (0.97) 8.06± (1.08) 8.08± (1.04)

0.03 8.45± (1.03) 8.54± (0.99) 8.66± (1.04) 8.77± (1.04) 8.87± (1.02) 8.96± (1.10)

0.06 9.66± (1.21) 9.76± (1.20) 9.87± (1.22) 10.01± (1.21) 10.05± (1.23) 10.07± (1.20)

0.09 10.75± (1.54) 10.77± (1.57) 10.77± (1.55) 10.78± (1.52) 10.77± (1.50) 10.76± (1.53)

0.12 10.94± (1.55) 10.93± (1.59) 10.94± (1.56) 10.90± (1.53) 11.00± (1.57) 10.94± (1.56)

0.15 11.19± (1.58) 10.98± (1.51) 11.05± (1.58) 11.04± (1.62) 11.09± (1.59) 11.11± (1.67)

Table 1. Mean Annualized Volatility ± (Standard Devia-tion) for 50 samples of Simulated Data with m = 100

Figure 5. Mean Annualized Volatility for 50 Samples ofSimulated Data with m = 100

10

Page 11: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

λ1, λ2 0.00 0.01 0.02 0.03 0.04 0.05

0.00 10.11 10.12 10.00 10.32 10.48 10.30

0.03 10.08 9.76 9.70 9.69 9.82 9.69

0.06 9.85 9.84 9.78 9.75 9.77 9.75

0.09 10.19 10.50 10.88 11.30 11.28 11.43

0.12 11.51 11.31 11.31 11.24 11.29 11.81

0.15 11.59 11.11 11.28 11.35 11.56 11.94

Table 2. Annualized Volatility for Real Data with m = 100

Figure 6. Annualized Volatility for Real Data with m = 100

11

Page 12: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

λ1, λ2 0.00 0.01 0.02 0.03 0.04 0.05

0.00 562.90± (61.93) 577.24± (65.37) 287.92± (31.59) 144.02± (20.17) 81.24± (13.28) 47.32± (10.04)

0.03 496.32± (46.47) 371.60± (46.36) 206.44± (28.28) 112.78± (20.16) 70.22± (13.83) 45.56± (9.64)

0.06 345.24± (48.64) 236.18± (39.98) 135.88± (28.55) 75.94± (17.64) 48.68± (12.35) 33.28± (9.43)

0.09 269.18± (42.91) 169.94± (31.22) 99.88± (23.03) 59.46± (13.63) 37.86± (9.98) 26.40± (8.25)

0.12 243.12± (38.42) 127.46± (28.38) 77.60± (20.06) 46.14± (13.24) 32.52± (9.93) 23.36± (7.28)

0.15 213.84± (34.35) 92.22± (24.71) 56.16± (16.00) 35.08± (10.73) 24.36± (9.03) 18.08± (6.54)

Table 3. Mean Total Trades ± (Standard Deviation) for 50Samples of Simulated Data for m = 100

λ1, λ2 0.00 0.01 0.02 0.03 0.04 0.05

0.00 560 564 314 162 97 58

0.03 503 385 230 136 87 54

0.06 393 279 172 92 60 35

0.09 288 191 119 71 39 28

0.12 236 155 93 60 39 20

0.15 234 121 79 41 33 16

Table 4. Total Trades for Real Data for m = 100

λ1, λ2 0.00 0.01 0.02 0.03 0.04 0.05

0.00 19.80± (2.86) 19.80± (2.86) 19.80± (2.86) 19.80± (2.86) 19.80± (2.86) 19.80± (2.86)

0.03 12.62± (2.03) 12.62± (2.03) 12.62± (2.03) 12.62± (2.03) 12.62± (2.03) 12.62± (2.03)

0.06 9.00± (1.68) 9.00± (1.68) 9.00± (1.68) 9.00± (1.68) 9.00± (1.68) 9.00± (1.68)

0.09 7.42± (1.33) 7.42± (1.33) 7.42± (1.33) 7.42± (1.33) 7.42± (1.33) 7.42± (1.33)

0.12 6.60± (1.40) 6.60± (1.40) 6.60± (1.40) 6.60± (1.40) 6.60± (1.40) 6.60± (1.40)

0.15 5.54± (1.18) 5.54± (1.18) 5.54± (1.18) 5.54± (1.18) 5.54± (1.18) 5.54± (1.18)

Table 5. Mean Starting Portfolio Size ± (Standard Devia-tion) for 50 Samples of Simulated Data for m = 100

12

Page 13: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

λ1, λ2 0.00 0.01 0.02 0.03 0.04 0.05

0.00 16 16 16 16 16 16

0.03 10 10 10 10 10 10

0.06 8 8 8 8 8 8

0.09 6 6 6 6 6 6

0.12 6 6 6 6 6 6

0.15 6 6 6 6 6 6

Table 6. Starting Portfolio Size for Real Data for m = 100

5.3. Conclusions. Based on the volatility results for simulated data (Table1 and Figure 5), we can see two general trends. First, increasing λ1 (re-stricting total number of assets) increases volatility. For the retail investor,this means that when selecting λ1, there is a trade-off between a realizable(sparse enough) portfolio vs. volatility. Second, increasing λ2 (restrictingthe number to trades) has little effect on volatility. Therefore, the retailinvestor can heavily penalize trading without suffering a significant increasein risk. In particular, we see from these results that one valid strategy isselecting a low-risk and sparse (realizable) portfolio at the beginning of theyear and holding it for the entire year, unless a significant event occurs.

From the volatility results for real data (Table 2 and Figure 6), we seethat the overall trend for λ2 still holds, but λ1 differs slightly from the simu-lated data results in that the volatilities decrease slightly before increasing.However, the overall shape of Figure 6 still follows that of Figure 5.

Based on the real data, the annualized volatility for the S&P500 during2011 was calculated to be 21.8%. The volatilities of our strategy’s returnsusing both simulated and real data were significantly lower than that of theS&P500. In addition, the volatilities of our strategy’s returns are in linewith annualized volatilities presented in [3].

Tables 3 and 4 show the same trend in number of trades. As one wouldexpect, number of trades decreases with both increasing λ1 and increasingλ2. In the case of increasing λ1, this is expected because more sparsitymeans fewer possibilities of trading.

Tables 5 and 6 also exhibit the expected trend. In both tables, no changesoccur as λ2 increases. This is because λ2 has no effect on the startingportfolio size (the term is ignored in the simulation for the first week). Asexpected, increasing λ1 corresponds to a sparser portfolio.

13

Page 14: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

References

[1] Bertsimas, D., Darnell, C. and Soucy, R. (1999). Portfolio Construction ThroughMixed Integer Programming at Grantham, Mayo, Van Otterloo and Company. Inter-faces 29: 1 January-February 1999 (pp. 49-66).

[2] Fan, J., Liao, Y. and Mincheva, M. (2011). High Dimensional Covariance Matrixestimation in Approximate Factor Models. The Annals of Statistics, 39, 3320-3356.

[3] Fan, J., Zhang, J. and Yu, K. (2012). Asset Allocation and Risk Assessment withGross Exposure Constraints for Vast Portfolios. Journal of Econometrics, 147, 186-197.

[4] Fama, E. F. and French, K. R. (1993). Common risk factors in the returns on stocksand bonds. Journal of Financial Economics, 33 (1993) 3-56.

[5] Markowitz, H. M. (1952). Portfolio selection. Journal of Finance, 7 77-91.

14

Page 15: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

6. Appendix: MATLAB Source Code

1 classdef Simulator2 properties(Constant)3 REG=0; FAMA=1;4 end5

6 properties7 stocks % array of stocks (all data)8 num days % # of days on which to build the cov matrix9 factors

10 rf11 trade cost12 end13

14 methods15 function obj = Simulator(stocks, factors, rf, ...

num days, trade cost)16 obj.stocks = stocks;17 obj.num days = num days;18 obj.factors = factors;19 obj.rf = rf;20 obj.trade cost = trade cost;21 end22

23 function [results opt ports] = simulate(obj, sd, ...ed, cash, args)

24 [timestamps, ret] = unpack stocks(obj.stocks);25

26 %find the array locations for total sim period27 curr ind = sd;28 first week = 1;29 results = [];30 opt ports = [];31 curr port = zeros(size(obj.stocks,2),1);32 %cycle through sim period33 while(curr ind < ed)34 %find last trading day of week35 ntd = next trade date(curr ind, timestamps);36

37 last returns = ...38 ret(curr ind−obj.num days:curr ind−1,:);39 last factors = obj.factors(...40 curr ind−obj.num days:curr ind−1,:);41 last rf = ...

obj.rf(curr ind−obj.num days:curr ind−1, :);42

43 cov = calc cov(args.('cov type'),...44 last returns,last factors, last rf);45

15

Page 16: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

46 %simulate period only cares about the total ...returns over

47 %period, normalize by adding one to each ...return, then prod

48 period returns = ret(curr ind:ntd,:);49 period returns norm = ...50 period returns+ones(size(period returns));51 period returns norm = ...

prod(period returns norm,1);52

53 args.('first week') = first week;54

55 [curr port, trade ret, cash,num trades] = ...56 simulate period(cov, cash, curr port, ...57 period returns norm, obj.trade cost, args);58

59 results = [results,[trade ret;cash;num trades]];60 opt ports = [opt ports, curr port];61 curr ind = ntd + 1;62 first week = 0;63 end64 end65 end66 end67

68 function [curr port, trade ret, cash,num trades] = ...69 simulate period(cov, cash, past port, period returns, ...

trade cost, args)70

71 %find portfolio72 curr port = optimize(cov, past port, args);73

74 %calculate returns for this period75 trade ret = (period returns)*curr port;76

77 %minus trading costs78 num trades = size(find(abs(curr port − past port)>0.01),1);79 cash = trade ret*cash − trade cost*num trades;80 end81

82 function ntd = next trade date(sd, timestamps)83 today = datenum(int2str(timestamps(sd)), 'yyyymmdd');84 i = 0;85 tmmrw = addtodate(today, 1, 'day');86 while isbusday(tmmrw)87 today = tmmrw;88 tmmrw = addtodate(today, 1, 'day');89 i=i+1;90 end91 ntd = sd + i;92 end

16

Page 17: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

1 function [ w ] = optimize(cov, past port, args)2 M = size(cov, 1);3

4 if exist('gurobi mex','file') 6= 35 error('please compile gurobi mex.c first.');6 end7

8 cov = cov(1:m,1:m);9 cov = cov/(sum(sum(cov)));

10

11 if args.('mode') == 112 [ c objtype A b lb ub contypes vtypes qrow qcol ...

qval ] = ...13 generate gurobi qp lambda(cov, past port, args);14

15 elseif args.('mode') == 216 [ c objtype A b lb ub contypes vtypes qrow qcol ...

qval ] = ...17 generate gurobi qp markowitz(cov, args);18

19 QP.qrow = qrow;20 QP.qcol = qcol;21 QP.qval = qval;22

23 clear opts24 opts.IterationLimit = 2000000;25 opts.FeasibilityTol = 1e−8;26 opts.IntFeasTol = 1e−5;27 opts.OptimalityTol = 1e−8;28 opts.Method = 1; % 0 − primal, 1 − dual29 opts.Presolve = −1; % −1 − auto, 0 − no, 1 − ...

conserv, 2 − aggressive30 opts.Display = 0; % no Gurobi Mex display31 opts.DisplayInterval = 0; % no Gurobi display32 opts.OutputFlag = 0;33 opts.QP = QP; % assign QP constraints34

35 %%%% Solve markowitz36 [x,val,exitflag,output,lambda] = gurobi mex(...37 c,objtype,A,b,contypes,lb,ub,vtypes,opts);38

39 w target = x(1:size(x,1)/2);40

41 %%%%%%42 clear opts43

44 [ c objtype A b lb ub contypes vtypes ] = ...45 generate gurobi lp( w target, past port, args );46

47 opts.IterationLimit = 2000000;48 opts.FeasibilityTol = 1e−6;49 opts.IntFeasTol = 1e−5;

17

Page 18: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

50 opts.OptimalityTol = 1e−6;51 opts.Method = 1; % 0 − primal, 1 − dual52 opts.Presolve = −1; % −1 − auto, 0 − no, 1 − ...

conserv, 2 − aggressive53 opts.Display = 0; % no Gurobi Mex display54 opts.DisplayInterval = 0; % no Gurobi display55 opts.OutputFlag =0 ;56

57 [x,val,exitflag,output,lambda] = gurobi mex(...58 c,objtype,A,b,contypes,lb,ub,vtypes,opts);59

60 if ¬args.('first week')61 w =[ x(1:size(x,1)/4 ];62 w(x(m*2+1:m*3,:)==0) = ...

past port(x(m*2+1:m*3,:)==0);63 w(x(m+1:m*2,:)==0) = 0;64 else65 w =[ x(1:size(x,1)/3) ];66 w(x(m+1:m*2,:)==0) = 0;67 end68 if abs((sum(w)−1))> .00169 error('Something Wrong!');70 end71 end72

73

74

75 end

18

Page 19: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

1 function C = calc cov(cov type, period returns, ...period factors, period Rf)

2

3 [m n] = size(period returns);4 [r q] = size(period factors);5 l = length(period Rf);6 if (m 6= r | | m 6= l | | r 6=l)7 error('Period length mismatch.');8 end9

10 T = m; % # of times11 K = q; % # of factors12 p = n; % # of stocks13

14 if cov type == Simulator.REG15 C = cov(period returns);16 return;17 end18

19 % cov type is FAMA20 % Regress21 B = zeros(p, K);22 U = zeros(p, T);23 for i = 1:p24 y = 100*(period returns(:,i)−period Rf); % turn ...

into percentages25 beta = period factors\y; % beta least squares soln26 u = y−period factors*beta;27 U(i,:) = transpose(u);28 B(i,:) = transpose(beta);29 end30

31 % Covariance matrix estimation as described in Fan et ...al, 2011

32 C u hat = cov(U');33 Theta hat = 1/T*(U.ˆ2*(transpose(U)).ˆ2)−...34 (2/T*(U*transpose(U))).*C u hat+C u hat.ˆ2;35

36 omega = .1*K*sqrt(log(p)/T);37

38 C thresh = zeros(p,p);39 C thresh(C u hat ≥ omega*sqrt(Theta hat)) =...40 C u hat(C u hat ≥ omega*sqrt(Theta hat));41

42 C f = cov(period factors);43

44 C = B*C f*B' + C thresh;45 C PD = min( eig( C ) ) > 0;46 if ¬C PD47 fprintf('C not positive definite...\n');48 end49 end

19

Page 20: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

1 function [ c objtype A b lb ub contypes vtypes ] = ...2 generate gurobi lp( w target, w last, args )3 % Stage 2 Optimization4 % Corresponds to equation (2.8)5

6 M = 100;7 lambda 1 = args.('lambda 1');8 lambda 2 = args.('lambda 2');9 lambda 1 first week = args.('lambda 1 first week');

10 first week = args.('first week');11

12 m = size(w target,1);13 %objtype (minimization)14 objtype = 1;15

16 if first week == 117 c = [zeros(1,m) lambda 1 first week*ones(1,m) ...

ones(1,m)];18 contypes = '<'; %applied uniformly to all constraints19 lb = [−inf*ones(1, m) zeros(1,m) zeros(1,m)]; %w i ...

have no lower bound, rest nonneg20 ub = []; %no upper bound for any variables21

22 vtypes = char(['C'*ones(1,m) 'B'*ones(1,m) ...'C'*ones(1,m)]); %

23 A = zeros(4*m+2, 3*m); %4m+2 constraints, 3m variables24 b = zeros(4*m+2, 1);25

26 for i = 0:m−127 A(4*i+1,i+1) = 1;28 A(4*i+1,i+1+m) = −1*M;29 A(4*i+2,i+1) = −1;30 A(4*i+2,i+1+m) = −1*M;31

32 A(4*i+3, i+1) = 1;33 A(4*i+3, i+1+2*m) = −1;34 b(4*i+3) = w target(i+1);35

36 A(4*i+4, i+1) = −1;37 A(4*i+4, i+1+2*m) = −1;38 b(4*i+4) = −w target(i+1);39 end40

41 A(4*m+1,:) = [ones(1,m) zeros(1,m) zeros(1,m)]; ...%sum(w) ≤ 1

42 b(4*m+1) = 1;43

44 A(4*m+2,:) = [−1*ones(1,m) zeros(1,m) zeros(1,m)]; ...%−sum(w) ≤ −1

45 b(4*m+2) = −1;46 A = sparse(A);47 else

20

Page 21: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

48 c = [zeros(1,m) lambda 1*ones(1,m) ...lambda 2*ones(1,m) ones(1,m)];

49 contypes = '<'; %applied uniformly to all constraints50 lb = [−inf*ones(1, m) zeros(1,m) zeros(1,m) ...

zeros(1,m)]; %w i have no lower bound, x i nonneg51 ub = []; %no upper bound for any variables52

53 vtypes = char(['C'*ones(1,m) 'B'*ones(1,m) ...'B'*ones(1,m) 'C'*ones(1,m)]); %w cont; y,z ...binary; x cont

54 A = zeros(6*m+2, 4*m); %6m+2 constraints, 4m variables55 b = zeros(6*m+2, 1);56

57 for i = 0:m−158 A(6*i+1,i+1) = 1;59 A(6*i+1,i+1+m) = −1*M;60 A(6*i+2,i+1) = −1;61 A(6*i+2,i+1+m) = −1*M;62

63 A(6*i+3,i+1) = 1;64 A(6*i+3,i+1+2*m) = −1*M;65 b(6*i+3) = w last(i+1);66

67 A(6*i+4,i+1) = −1;68 A(6*i+4,i+1+2*m) = −1*M;69 b(6*i+4) = −w last(i+1);70

71 A(6*i+5, i+1) = 1;72 A(6*i+5, i+1+3*m) = −1;73 b(6*i+5) = w target(i+1);74

75 A(6*i+6, i+1) = −1;76 A(6*i+6, i+1+3*m) = −1;77 b(6*i+6) = −w target(i+1);78 end79

80 A(6*m+1,:) = [ones(1,m) zeros(1,m) zeros(1,m) ...zeros(1,m)]; %sum(w) ≤ 1

81 b(6*m+1) = 1;82

83 A(6*m+2,:) = [−1*ones(1,m) zeros(1,m) zeros(1,m) ...zeros(1,m)]; %−sum(w) ≤ −1

84 b(6*m+2) = −1;85

86 A = sparse(A);87 end88

89 end

21

Page 22: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

1 function [ c objtype A b lb ub contypes vtypes qrow qcol ...qval ] = generate gurobi qp markowitz( C, args )

2 %Stage 1 Optimization3 %Corresponds to equation (2.7)4 %QP Example:5 % if w is 3−dim: qrow = 0 0 0 1 1 1 2 2 26 % qcol = 0 1 2 0 1 2 0 1 27

8 d = args.('d');9

10 [m n] = size(C);11 if m 6= n12 error('C not a square matrix.');13 end14 %objtype (minimization)15 objtype = 1;16

17 %c (no linear terms in objective)18 c = 0;19

20 %qrow, qcol, and qval (w'Cw, w are variables 0 thru m−1)21 temp col = [0:m−1];22 qcol = repmat(temp col, 1, m);23

24 qrow = zeros(1, mˆ2);25 for i = 0:m−126 temp row = repmat(i, 1, m); %i*ones(1, m);27 qrow([m*i+1:m*(i+1)]) = temp row;28 qval([m*i+1:m*(i+1)]) = C(i+1,:);29 end30

31 %CONSTRAINTS (A, b, lb, ub, contypes, vtypes)32 %variables are (w 0,..., w m−1, x 0,..., x m−1)33 %so variables m thru 2m−1 represent x34 A = zeros(2*m+3, 2*m); %2m+3 constraints, 2m variables35 b = zeros(2*m+3, 1);36

37 contypes = '<'; %applied uniformly to all constraints38 lb = [−inf*ones(1, m) zeros(1,m)]; %w i have no lower ...

bound, x i nonneg39 ub = []; %no upper bound for any variables40

41 %constraint: L1(w) ≤ d, sum(w) = 1 will be represented as42 % −x i ≤ w i ≤ x i, sum(x) ≤ d, sum(w) = 143 % x i ≥ 044 M = 1;45 vtypes = 'C'; %all variables continuous46

47 A = zeros(2*m+3, 2*m); %2m+3 constraints, 2m variables48 b = zeros(2*m+3, 1);49

50 for i = 0:m−1

22

Page 23: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

51 A(2*i+1,i+1) = 1; %w i − x i ≤ 052 A(2*i+1,i+1+m) = −1;53 A(2*i+2,i+1) = −1; %−w i − x i ≤ 054 A(2*i+2,i+1+m) = −1;55 end56 A(2*m+1,:) = [ones(1,m) zeros(1,m)]; %sum(w) ≤ 157 b(2*m+1) = 1;58

59 A(2*m+2,:) = [−1*ones(1,m) zeros(1,m)]; %−sum(w) ≤ −160 b(2*m+2) = −1;61

62 A(2*m+3,:) = [zeros(1,m) ones(1,m)]; %sum(x) ≤ d63 b(2*m+3) = d;64 A = sparse(A);65 qrow = int32(qrow);66 qcol = int32(qcol);67 end

23

Page 24: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

1 function [sim stocks, sim factors] = simulate stocks(...2 p, T, factors, returns, seed)3 %Set random seed4 s = RandStream('mt19937ar','Seed',seed);5 RandStream.setGlobalStream(s);6

7 %step 18 % indust returns must be 30xT, factors must be 3xT9 B = (100*returns')/factors'; %Px3

10

11 sigma B = cov(B); % covariance treating rows as samples12 mu B = mean(B); % mean treating rows as samples13

14 %step 215 U = returns − factors*B';16 sigma = std(U,0,1); % find standard deviation along the ...

columns17 large = max(sigma);18 small = min(sigma);19 sigma sigma = std(sigma);20 mean sigma = mean(sigma);21

22 %generate p volatility draws for our p assets23 %find alpha and beta24 %define in−line function to solve25 F = @(x) [x(1)*x(2)−mean sigma; ...

sqrt(x(1))*x(2)−sigma sigma];26 InitialGuess = [1;1];27 x = fsolve(F, InitialGuess); % x(1) = alpha, x(2) = beta28 alpha = x(1);29 beta = x(2);30

31 done = 0;32 while ¬done33 % loop until simga u is PD34 sigma p = zeros(1,p);35 numAccepted = 0;36 while numAccepted < p37 %loop until we have p values that are in the ...

accepted range38 draw = gamrnd(alpha, beta, 1);39 if draw ≥ small && draw ≤ large40 numAccepted = numAccepted + 1;41 sigma p(numAccepted) = drawˆ2;42 end43 end44

45 mask = binornd(1,.2/(sqrt(p)*log(p)), p, 1);46 s = randn(p,1);47 s(mask == 0) = 0;48

49 sigma u = diag(sigma p) + s*s' − diag(s.ˆ2);

24

Page 25: SPARSE, MINIMAL VARIANCE PORTFOLIO REBALANCED WITH AN L0-TRADING CONSTRAINT

50 if isPD(sigma u)51 done = 1;52 end53 end54

55 %step 356 % fit a VAR(1) model to the 3x1 vectors of factors57 [mu f, Phi, sigma error] = arfit(factors, 1, 1);58

59 %step 460 %simulate the p assets for T time points61

62 %generate p factor loading draws63 B = mvnrnd(mu B, sigma B, p); % rows are draws, p rows64

65 %generate T noise terms66 U = mvnrnd(zeros(p,1), sigma u, T);67

68 %generate T factors according to the fitted model69 sim factors = arsim(mu f, Phi, sigma error, [T, 1]);70

71 %calculate the stocks returns72 sim stocks = (sim factors*B' + U)/100;73 end74

75 function is = isPD(A)76 eigs = eig(A);77

78 if min(eigs) > 079 is=1;80 else81 is=0;82 end83 end

Operations Research and Financial Engineering, Princeton UniversityE-mail address: [email protected]

Operations Research and Financial Engineering, Princeton UniversityE-mail address: [email protected]

25