Skip to content

Commit

Permalink
gh now tests also against old packages (~2021)
Browse files Browse the repository at this point in the history
  • Loading branch information
enzbus committed Sep 2, 2023
1 parent 677b579 commit 8fa6038
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,22 @@ jobs:

# rationale: we test against an environment which had
# current packages as of ~ Q4 2022 for python 3.10
# and ~ Q4 2021 for python 3.9
# and ~ Q4 2021 for python 3.9 (with the exception of pandas,
# for which we use a mid-2022 package).
# we only install the base packages here (pip below figures out the others)

- name: If running on old python install some old dependencies
- name: If running on python 3.9 install some old dependencies
if: ${{ matrix.python-version == '3.9'}}
run: python -m pip install numpy==1.21.5 scipy==1.7.3 cvxpy==1.1.17 pandas==1.5.0 osqp==0.6.2.post0 ecos==2.0.11 scs==2.1.4

- name: If running on python 3.10 install some old dependencies
if: ${{ matrix.python-version == '3.10'}}
run: python -m pip install numpy==1.23.4 scipy==1.9.3 cvxpy==1.2.3 pandas==1.5.0 osqp==0.6.2.post9 ecos==2.0.12 scs==3.2.2

- name: Install package
run: |
pip install .
pip install coverage
python -m pip install .
python -m pip install coverage
- name: Run tests with coverage
run: |
Expand Down
5 changes: 3 additions & 2 deletions cvxportfolio/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,14 @@ def _downsample(self, interval):
# print(new_returns_index)
self.returns = np.exp(np.log(
1+self.returns).resample(interval, closed='left', label='left'
).sum(False, 1))-1
).sum(numeric_only=False, min_count=1))-1
self.returns.index = new_returns_index
if self.volumes is not None:
new_volumes_index = pd.Series(self.volumes.index, self.volumes.index
).resample(interval, closed='left', label='left').first().values
self.volumes = self.volumes.resample(
interval, closed='left', label='left').sum(False, 1)
interval, closed='left', label='left').sum(
numeric_only=False, min_count=1)
self.volumes.index = new_volumes_index
if self.prices is not None:
new_prices_index = pd.Series(self.prices.index, self.prices.index
Expand Down
4 changes: 2 additions & 2 deletions cvxportfolio/tests/test_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def tearDownClass(cls):

def test_market_data__downsample(self):
"Test downsampling of market data."
md = MarketData(['AAPL', 'GOOG'])
md = MarketData(['AAPL', 'GOOG'], base_location=self.datadir)

idx = md.returns.index

Expand Down Expand Up @@ -474,7 +474,7 @@ def test_backtest(self):
print(result)

def test_backtest_concatenation(self):
sim = cvx.MarketSimulator(['AAPL', 'ZM'])
sim = cvx.MarketSimulator(['AAPL', 'ZM'], base_location=self.datadir)
pol = cvx.SinglePeriodOptimization(cvx.ReturnsForecast() -
cvx.ReturnsForecastError() -
.5 * cvx.FullCovariance(),
Expand Down

0 comments on commit 8fa6038

Please sign in to comment.