You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -291,8 +267,6 @@ The covariance matrix encodes not just the volatility of an asset, but also how
291
267
292
268
- Long/short: by default all of the mean-variance optimization methods in PyPortfolioOpt are long-only, but they can be initialised to allow for short positions by changing the weight bounds:
293
269
294
-
<!--pytest-codeblocks:cont-->
295
-
296
270
```python
297
271
ef = EfficientFrontier(mu, S, weight_bounds=(-1, 1))
298
272
```
@@ -302,8 +276,6 @@ ef = EfficientFrontier(mu, S, weight_bounds=(-1, 1))
302
276
303
277
- Market neutrality: for the `efficient_risk` and `efficient_return` methods, PyPortfolioOpt provides an option to form a market-neutral portfolio (i.e weights sum to zero). This is not possible for the max Sharpe portfolio and the min volatility portfolio because in those cases because they are not invariant with respect to leverage. Market neutrality requires negative weights:
304
278
305
-
<!--pytest-codeblocks:cont-->
306
-
307
279
```python
308
280
ef = EfficientFrontier(mu, S, weight_bounds=(-1, 1))
309
281
for name, value in ef.efficient_return(target_return=0.2, market_neutral=True).items():
@@ -335,21 +307,18 @@ SBUX: 0.0330
335
307
336
308
- Minimum/maximum position size: it may be the case that you want no security to form more than 10% of your portfolio. This is easy to encode:
337
309
338
-
<!--pytest-codeblocks:cont-->
339
-
340
310
```python
341
311
ef = EfficientFrontier(mu, S, weight_bounds=(0, 0.1))
342
312
```
343
313
344
314
```result
345
315
```
316
+
346
317
One issue with mean-variance optimization is that it leads to many zero-weights. While these are
347
318
"optimal" in-sample, there is a large body of research showing that this characteristic leads
348
319
mean-variance portfolios to underperform out-of-sample. To that end, I have introduced an
349
320
objective function that can reduce the number of negligible weights for any of the objective functions. Essentially, it adds a penalty (parameterised by `gamma`) on small weights, with a term that looks just like L2 regularisation in machine learning. It may be necessary to try several `gamma` values to achieve the desired number of non-negligible weights. For the test portfolio of 20 securities, `gamma ~ 1` is sufficient
350
321
351
-
<!--pytest-codeblocks:cont-->
352
-
353
322
```python
354
323
from pypfopt import objective_functions
355
324
ef = EfficientFrontier(mu, S)
@@ -389,8 +358,6 @@ posterior estimate. This results in much better estimates of expected returns th
389
358
the mean historical return. Check out the [docs](https://pyportfolioopt.readthedocs.io/en/latest/BlackLitterman.html) for a discussion of the theory, as well as advice
390
359
on formatting inputs.
391
360
392
-
<!--pytest-codeblocks:cont-->
393
-
394
361
```python
395
362
from pypfopt import risk_models, BlackLittermanModel
0 commit comments