Skip to content

Commit 29f634d

Browse files
committed
fix: resolve import issues for GitHub Actions tests
- Convert all relative imports to use dot notation (from .module import) - Add __init__.py to make src a proper Python package - Update GitHub Actions workflow to run tests from src directory - Fix ModuleNotFoundError issues in CI environment - Ensure all modules can be imported correctly
1 parent 1e6c66b commit 29f634d

File tree

11 files changed

+62
-20
lines changed

11 files changed

+62
-20
lines changed

.github/workflows/test.yml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,22 @@ jobs:
3636
3737
- name: Test optimization modules
3838
run: |
39-
python -c "from src.markowitz import markowitz_weights; print('✅ Markowitz module import successful!')"
40-
python -c "from src.risk_parity import risk_parity_weights; print('✅ Risk parity module import successful!')"
41-
python -c "from src.monte_carlo import monte_carlo_simulation; print('✅ Monte Carlo module import successful!')"
42-
python -c "from src.black_litterman import black_litterman_weights; print('✅ Black-Litterman module import successful!')"
43-
python -c "from src.ml_predictor import ml_predictor; print('✅ ML predictor module import successful!')"
44-
python -c "from src.hybrid_model import hybrid_weights; print('✅ Hybrid model module import successful!')"
45-
python -c "from src.custom_metrics_opt import custom_metrics_weights; print('✅ Custom metrics module import successful!')"
46-
python -c "from src.walkforward_backtest import walkforward_backtest; print('✅ Walkforward backtest module import successful!')"
39+
cd src
40+
python -c "from markowitz import markowitz_weights; print('✅ Markowitz module import successful!')"
41+
python -c "from risk_parity import risk_parity_weights; print('✅ Risk parity module import successful!')"
42+
python -c "from monte_carlo import monte_carlo_simulation; print('✅ Monte Carlo module import successful!')"
43+
python -c "from black_litterman import black_litterman_weights; print('✅ Black-Litterman module import successful!')"
44+
python -c "from ml_predictor import ml_predictor; print('✅ ML predictor module import successful!')"
45+
python -c "from hybrid_model import hybrid_weights; print('✅ Hybrid model module import successful!')"
46+
python -c "from custom_metrics_opt import custom_metrics_weights; print('✅ Custom metrics module import successful!')"
47+
python -c "from walkforward_backtest import walkforward_backtest; print('✅ Walkforward backtest module import successful!')"
4748
4849
- name: Test basic functionality
4950
run: |
51+
cd src
5052
python -c "
5153
import numpy as np
52-
from src.risk_parity import risk_parity_weights
54+
from risk_parity import risk_parity_weights
5355
5456
# Test basic functionality
5557
cov_matrix = np.array([[0.01, 0.005], [0.005, 0.01]])

src/__init__.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
SiraEdge Portfolio Optimization Module
3+
4+
This package contains implementations of various portfolio optimization models:
5+
- Markowitz (Mean-Variance) optimization
6+
- Risk Parity optimization
7+
- Monte Carlo simulation
8+
- Black-Litterman model
9+
- Machine Learning predictor
10+
- Hybrid model
11+
- Custom metrics optimization
12+
- Walk-forward backtesting
13+
14+
All modules are designed to work together for comprehensive portfolio analysis.
15+
"""
16+
17+
__version__ = "1.0.0"
18+
__author__ = "Ismail Moudden"
19+
__email__ = "[email protected]"
20+
21+
# Import main functions for easy access
22+
from .markowitz import markowitz_weights
23+
from .risk_parity import risk_parity_weights
24+
from .monte_carlo import monte_carlo_simulation
25+
from .black_litterman import black_litterman_weights
26+
from .ml_predictor import ml_predictor
27+
from .hybrid_model import hybrid_weights
28+
from .custom_metrics_opt import custom_metrics_weights
29+
from .walkforward_backtest import walkforward_backtest
30+
31+
__all__ = [
32+
"markowitz_weights",
33+
"risk_parity_weights",
34+
"monte_carlo_simulation",
35+
"black_litterman_weights",
36+
"ml_predictor",
37+
"hybrid_weights",
38+
"custom_metrics_weights",
39+
"walkforward_backtest"
40+
]

src/black_litterman.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import numpy as np
33
import pandas as pd
44
import matplotlib.pyplot as plt
5-
from data_utils import download_prices, ensure_figures_dir, DEFAULT_TICKERS
5+
from .data_utils import download_prices, ensure_figures_dir, DEFAULT_TICKERS
66

77

88
def run_black_litterman(tickers=None, start="2020-01-01", end="2023-12-31") -> pd.Series:

src/custom_metrics_opt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pandas as pd
44
import matplotlib.pyplot as plt
55
from scipy.optimize import minimize
6-
from data_utils import download_prices, ensure_figures_dir, DEFAULT_TICKERS
6+
from .data_utils import download_prices, ensure_figures_dir, DEFAULT_TICKERS
77

88

99
def sharpe_ratio(returns: pd.Series, rf: float = 0.0) -> float:

src/hybrid_model.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import numpy as np
33
import pandas as pd
44
import matplotlib.pyplot as plt
5-
from data_utils import download_prices, compute_indicators, ensure_figures_dir, DEFAULT_TICKERS
6-
from risk_parity import risk_parity_weights
5+
from .data_utils import download_prices, compute_indicators, ensure_figures_dir, DEFAULT_TICKERS
6+
from .risk_parity import risk_parity_weights
77
from sklearn.linear_model import Ridge
88
from sklearn.preprocessing import StandardScaler
99
from sklearn.pipeline import Pipeline

src/markowitz.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import numpy as np
33
import pandas as pd
44
import matplotlib.pyplot as plt
5-
from data_utils import download_prices, ensure_figures_dir, DEFAULT_TICKERS
5+
from .data_utils import download_prices, ensure_figures_dir, DEFAULT_TICKERS
66

77

88
def random_portfolios(mu: np.ndarray, cov: np.ndarray, n: int = 20000, seed: int = 42):

src/ml_predictor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from sklearn.preprocessing import StandardScaler
88
from sklearn.pipeline import Pipeline
99
from sklearn.model_selection import TimeSeriesSplit
10-
from data_utils import download_prices, compute_indicators, ensure_figures_dir, DEFAULT_TICKERS
10+
from .data_utils import download_prices, compute_indicators, ensure_figures_dir, DEFAULT_TICKERS
1111

1212

1313
def prepare_ml_dataset(start="2020-01-01", end="2023-12-31", tickers=None) -> Tuple[pd.DataFrame, pd.Series, pd.Series]:

src/ml_training_report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from sklearn.pipeline import Pipeline
1111
from sklearn.metrics import r2_score, mean_absolute_error
1212

13-
from data_utils import (
13+
from .data_utils import (
1414
download_prices,
1515
compute_indicators,
1616
align_features_and_targets,

src/monte_carlo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import numpy as np
33
import pandas as pd
44
import matplotlib.pyplot as plt
5-
from data_utils import download_prices, ensure_figures_dir, DEFAULT_TICKERS
5+
from .data_utils import download_prices, ensure_figures_dir, DEFAULT_TICKERS
66

77

88
def simulate_portfolios(returns: pd.DataFrame, n_portfolios: int = 10000, seed: int = 42):

src/risk_parity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pandas as pd
44
import matplotlib.pyplot as plt
55
from scipy.optimize import minimize
6-
from data_utils import download_prices, ensure_figures_dir, DEFAULT_TICKERS
6+
from .data_utils import download_prices, ensure_figures_dir, DEFAULT_TICKERS
77

88

99
def risk_contribution(weights: np.ndarray, cov: np.ndarray) -> np.ndarray:

0 commit comments

Comments
 (0)