Skip to content

Commit 2e27a00

Browse files
committed
one result per python block
1 parent b7b311c commit 2e27a00

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ The covariance matrix encodes not just the volatility of an asset, but also how
297297
ef = EfficientFrontier(mu, S, weight_bounds=(-1, 1))
298298
```
299299

300+
```result
301+
```
302+
300303
- 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:
301304

302305
<!--pytest-codeblocks:cont-->
@@ -338,6 +341,8 @@ SBUX: 0.0330
338341
ef = EfficientFrontier(mu, S, weight_bounds=(0, 0.1))
339342
```
340343

344+
```result
345+
```
341346
One issue with mean-variance optimization is that it leads to many zero-weights. While these are
342347
"optimal" in-sample, there is a large body of research showing that this characteristic leads
343348
mean-variance portfolios to underperform out-of-sample. To that end, I have introduced an
@@ -463,10 +468,13 @@ Tests are written in pytest (much more intuitive than `unittest` and the variant
463468

464469
PyPortfolioOpt provides a test dataset of daily returns for 20 tickers:
465470

466-
```
471+
```python
467472
['GOOG', 'AAPL', 'FB', 'BABA', 'AMZN', 'GE', 'AMD', 'WMT', 'BAC', 'GM', 'T', 'UAA', 'SHLD', 'XOM', 'RRC', 'BBY', 'MA', 'PFE', 'JPM', 'SBUX']
468473
```
469474

475+
```result
476+
```
477+
470478
These tickers have been informally selected to meet several criteria:
471479

472480
- reasonably liquid

tests/test_discrete_allocation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
from cvxpy.error import SolverError
12
import numpy as np
23
import pandas as pd
34
import pytest
4-
from cvxpy.error import SolverError
55

66
from pypfopt.discrete_allocation import DiscreteAllocation, get_latest_prices
77
from tests.utilities_for_tests import get_data, setup_efficient_frontier

tests/test_readme.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919

2020
def test_readme_runs():
2121
"""Execute README code blocks and compare output to documented results."""
22-
code_blocks = CODE_BLOCK.findall(README.read_text())
23-
result_blocks = RESULT.findall(README.read_text())
22+
readme_text = README.read_text(encoding="utf-8")
23+
code_blocks = CODE_BLOCK.findall(readme_text)
24+
result_blocks = RESULT.findall(readme_text)
25+
26+
# Optional: keep docs and expectations in sync.
27+
assert len(code_blocks) == len(result_blocks), "Mismatch between python and result blocks in README.md"
2428

2529
code = "".join(code_blocks) # merged code
2630
expected = "".join(result_blocks)

0 commit comments

Comments
 (0)