Skip to content

Commit 8c3c1bd

Browse files
author
88d52bdba0366127fffca9dfa93895
committed
fix pytest badge using branch; slightly enhance code
1 parent c687392 commit 8c3c1bd

File tree

5 files changed

+14
-15
lines changed

5 files changed

+14
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<img src="https://img.shields.io/badge/license-MIT-brightgreen.svg"
1818
alt="MIT license"></a> &nbsp;
1919
<a href="https://github.com/robertmartin8/PyPortfolioOpt/actions">
20-
<img src="https://github.com/robertmartin8/PyPortfolioOpt/workflows/pytest/badge.svg?event=push"
20+
<img src="https://github.com/robertmartin8/PyPortfolioOpt/workflows/pytest/badge.svg?branch=master"
2121
alt="build"></a> &nbsp;
2222
<a href="https://app.codecov.io/gh/robertmartin8/PyPortfolioOpt">
2323
<img src="https://codecov.io/github/robertmartin8/PyPortfolioOpt/coverage.svg?branch=main"

pypfopt/efficient_frontier/efficient_frontier.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,8 @@ def __init__(
8383
:raises TypeError: if ``cov_matrix`` is not a dataframe or array
8484
"""
8585
# Inputs
86-
self.cov_matrix = EfficientFrontier._validate_cov_matrix(cov_matrix)
87-
self.expected_returns = EfficientFrontier._validate_expected_returns(
88-
expected_returns
89-
)
86+
self.cov_matrix = self._validate_cov_matrix(cov_matrix)
87+
self.expected_returns = self._validate_expected_returns(expected_returns)
9088
self._max_return_value = None
9189
self._market_neutral = None
9290

pypfopt/expected_returns.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
"""
2222

2323
import warnings
24-
import pandas as pd
24+
2525
import numpy as np
26+
import pandas as pd
2627

2728

2829
def _check_returns(returns):
@@ -247,12 +248,12 @@ def capm_return(
247248
market_returns = market_prices
248249
else:
249250
returns = returns_from_prices(prices, log_returns)
250-
251+
251252
if market_prices is not None:
252253
if not isinstance(market_prices, pd.DataFrame):
253254
warnings.warn("market prices are not in a dataframe", RuntimeWarning)
254255
market_prices = pd.DataFrame(market_prices)
255-
256+
256257
market_returns = returns_from_prices(market_prices, log_returns)
257258
# Use the equally-weighted dataset as a proxy for the market
258259
if market_returns is None:

tests/test_efficient_semivariance.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
from cvxpy.error import SolverError
44

55
from pypfopt import (
6-
risk_models,
7-
expected_returns,
86
EfficientFrontier,
97
EfficientSemivariance,
8+
expected_returns,
109
objective_functions,
10+
risk_models,
1111
)
12-
from tests.utilities_for_tests import setup_efficient_semivariance, get_data
12+
from tests.utilities_for_tests import get_data, setup_efficient_semivariance
1313

1414

1515
def test_es_example():

tests/utilities_for_tests.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import numpy as np
44
import pandas as pd
5+
56
from pypfopt import expected_returns
67
from pypfopt import risk_models
78
from pypfopt.efficient_frontier import (
@@ -11,7 +12,6 @@
1112
EfficientCDaR,
1213
)
1314
from pypfopt.cla import CLA
14-
from pypfopt.expected_returns import returns_from_prices
1515

1616

1717
def resource(name):
@@ -72,7 +72,7 @@ def setup_efficient_frontier(
7272
def setup_efficient_semivariance(data_only=False, solver=None, verbose=False):
7373
df = get_data().dropna(axis=0, how="any")
7474
mean_return = expected_returns.mean_historical_return(df, compounding=False)
75-
historic_returns = returns_from_prices(df)
75+
historic_returns = expected_returns.returns_from_prices(df)
7676
if data_only:
7777
return mean_return, historic_returns
7878
return EfficientSemivariance(
@@ -85,7 +85,7 @@ def setup_efficient_cvar(
8585
):
8686
df = get_data().dropna(axis=0, how="any")
8787
mean_return = expected_returns.mean_historical_return(df)
88-
historic_returns = returns_from_prices(df)
88+
historic_returns = expected_returns.returns_from_prices(df)
8989
if data_only:
9090
return mean_return, historic_returns
9191
return EfficientCVaR(
@@ -102,7 +102,7 @@ def setup_efficient_cdar(
102102
):
103103
df = get_data().dropna(axis=0, how="any")
104104
mean_return = expected_returns.mean_historical_return(df)
105-
historic_returns = returns_from_prices(df)
105+
historic_returns = expected_returns.returns_from_prices(df)
106106
if data_only:
107107
return mean_return, historic_returns
108108
return EfficientCDaR(

0 commit comments

Comments
 (0)