In this module, I'm going to walk you through how to set up this optimization problem that involves a mean term, a variance term, and a liquidity cost term, and compute portfolios or positions that optimize mean variance and a cost term. So here's a fictitious example that has been created. I have 10 different assets. Here are the mean returns for these assets. Here's the variance, covariance matrix for these assets. And then I also computed the volatilities by simply taking the square root of these quantities and multiplying them by 100. Then I define something called volume. I'm not particular about what the units are. So in, in whatever are the base units, the volume is 10, 0.1, .01, and so on. So, the first asset is very liquid, and the third asset is very illiquid according to these units. The other assets are somewhere in the middle and asset number nine is the most liquid, it's about 100 units of volume per day. And the tension I'm trying to build up here in this example, is that the illiquid stocks, so this one for example, has high returns, so 7.17% return. And it's liquidity is 0.1, 6.75 return it's liquidity is 0.01. So, if we include, exclude concerns about liquidity, you should expect that you would want to hold asset three and four. Asset six which has medium It has 6.289, so about 6.3% return and its liquidity is around three. So, this one asset six is a good trade off between both return and liquidity. And we would want to see how things change. Five point, asset nine, which is very liquid, doesn't have very high returns from someone. So, here's the risk aversion parameter that I'm going to be using for my portfolio selection, which is ten, it's arbitrarily chosen. Here are the trading cost parameters. So, in my notes, I'm calling them a1, a2, a3. Here, I'm calling them alpha one, alpha two, alpha three, just because then, I can name them appropriately. Alpha one is the factor that hits the normalized paid volume, divided by the average beta volume, alpha two is a volatility term, and alpha three is just a interceptor. Beta is the power to which the percentage, of order to volume is raised, and it's typically around 0.65. So here's my initial portfolio. It's all ten units on all of these assets. And these are in the same units in which the volume has been quoted, so it's across the board uniform, and just to make things interesting I'm going to clear this. And keep it as the initial run. What about the trading costs? I'm going to use a formula. It's alpha one times 100 divided by b15, which is the average daily volume, and the volume here I'm quoting not in per share, but in the total dollar amounts traded because I want to keep the units of the portfolio and the units of the volume the same. So it's 100, divided by the daily volume in dollar terms, raised to the power beta, plus the absolute value of the difference between the initial position and the final position, raised to the power 1 plus beta. Alpha 2 times the volatility divided by 100 plus alpha 3 times the absolute value of the difference in the two assets. The difference is, just to be very clear here, I'm looking at positions and not at portfolio, so I'm just going to change these names back to. All right. So, now I'm setting up the optimization problem. The mean return is the just a product of the final positions and the mean return vector up there. The variance, take the final position, multiply it by the covariance matrix, and multiply the, the final positions once again and that will give you the variance. The trading cost is just the sum of the trading cost across various assets because I've assumed that the trading costs are going to be separable across assets. What about the objective? The objective is b31 which is the mean, minus lambda times b32, which is the variance, minus eta times b33 which is the trading cost. So the first thing I'm going to do is I'm going to set trading cost parameter to zero. This eta to be zero. And what does that mean? It means that I'm going to ignore liquidity constraints and I want to see where does the portfolio selection move the asset. So we should typically see if I just look at returns, we should start seeing more of an investment in asset three and asset four. Because they have high returns, but maybe not completely because of the covariance matrices and so on. So let's run the solver to try to get what it is, and what is solver going to do, it's going to maximize my objective subject to the constraint that the sum of the final position must equal the sum of the initial positions and I'm only allowing long positions here so, I'm going to make the variables non-negative. So I solve it. And you end up getting that basically the portfolio gets concentrated in asset three about 22% there, 32% in asset four. 14% in asset six which is so this medium one, 16% in asset seven, which has low liquidity and so on. So, this is the final position when I don't take liquidity into consideration. Now, let's put eta to be 0.1. So I have medium amount of liquidity constraints in place, and I want to see what happens to the final portfolio. So, let's again ask for our solver to solve it. Once again, the, the problem remains the same except now my objective function has changed because eta has been increased. So now, asset number four, which is not so liquid, but it still has a very high return, you end up still putting about 30% there but it is much smaller. Whereas asset number three which has lower return and much lower liquidity, now you start reducing the amount that you're going to put in there. Asset number one, which didn't have much of an investment before, but it has a pretty high liquidity, numbers about 10, ends up getting a good proportion. And the last one, asset number nine, which still, which has a liquidity of about 100 ends up getting a little bit more position. Let's increase this to 0.5 and run it again. And again, what it should intuitively happen is happening. Six and seven, which have high returns, their money is being pulled out, and it's being spread across other assets which have high liquidity. And that's pretty much what I wanted to show you in this module. You can take the approach that was by Andy Low and others and also set up an optimization problem which is very similar to this one.