Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CmampTask4662: PR #5664
Browse files Browse the repository at this point in the history
vlady committed Nov 14, 2023
1 parent 39dcb0d commit df07377
Showing 17 changed files with 1,478 additions and 1,227 deletions.
6 changes: 6 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# cmamp-1.10.0
- 2023-11-13
- Promote Pandas to 2.1.1
- Promote Numpy to 1.26.0
- Changes from #4662 - Promote pandas version

# cmamp-1.9.0
- 2023-09-29
- Promote Python to 3.9
4 changes: 3 additions & 1 deletion core/finance/market_impact.py
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
import core.finance.market_impact as cfimaimp
"""

import numpy as np
import pandas as pd

import helpers.hdbg as hdbg
@@ -30,7 +31,8 @@ def estimate_market_order_price(
hdbg.dassert_isinstance(df, pd.DataFrame)
hdbg.dassert_in(price_col, df.columns)
hdbg.dassert_in(size_col, df.columns)
hdbg.dassert_isinstance(df.index, (pd.RangeIndex, pd.Int64Index))
# Check that it is an integer index.
hdbg.dassert_eq(df.index.dtype.type, np.int64)
# Compute market impact-related quantities.
cumulative_size = df[size_col].cumsum()
notional = df[price_col] * df[size_col]
14 changes: 7 additions & 7 deletions core/finance/test/test_prediction_processing.py
Original file line number Diff line number Diff line change
@@ -24,13 +24,13 @@ def test1(self) -> None:
ath_end=datetime.time(16, 0),
)
expected_txt = """
,amid,alpha,eob_close,eob_ret,eob_vwap,eopb_close,minute_index,start_bar_et_ts
0,MN0,,100.0,,100.0,,24198330,2016-01-04T09:30:00
1,MN1,,73.25,,73.25,,24198330,2016-01-04T09:30:00
2,MN0,,100.05,0.0005,100.04,100.0,24198331,2016-01-04T09:31:00
3,MN1,,73.22,-0.00041,73.24,73.25,24198331,2016-01-04T09:31:00
4,MN0,1e-05,100.07,0.0002,100.05,100.05,24198332,2016-01-04T09:32:00
5,MN1,-3e-05,73.22,0.0,73.23,73.22,24198332,2016-01-04T09:32:00
,amid,eob_close,eob_vwap,eob_ret,eopb_close,alpha,minute_index,start_bar_et_ts
0,MN0,100.0,100.0,,,,24198330,2016-01-04T09:30:00
1,MN1,73.25,73.25,,,,24198330,2016-01-04T09:30:00
2,MN0,100.05,100.04,0.0005,100.0,,24198331,2016-01-04T09:31:00
3,MN1,73.22,73.24,-0.00041,73.25,,24198331,2016-01-04T09:31:00
4,MN0,100.07,100.05,0.0002,100.05,1e-05,24198332,2016-01-04T09:32:00
5,MN1,73.22,73.23,0.0,73.22,-3e-05,24198332,2016-01-04T09:32:00
"""
expected = pd.read_csv(
io.StringIO(expected_txt),
50 changes: 50 additions & 0 deletions core/statistics/test/test_empirical_distribution_function.py
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ def test_gaussian(self) -> None:
actual = get_df_as_str(empirical_cdf)
expected = r"""
n_samples=10_seed=0.ecdf
n_samples=10_seed=0
-1.26542 0.1
-0.70374 0.2
-0.53567 0.3
@@ -44,6 +45,7 @@ def test_with_duplicates(self) -> None:
actual = get_df_as_str(empirical_cdf)
expected = r"""
n_samples=10_seed=0.ecdf
n_samples=10_seed=0
-1.26542 0.1
-0.70374 0.2
-0.53567 0.3
@@ -67,6 +69,7 @@ def test_gaussian1(self) -> None:
actual = get_df_as_str(empirical_cdf_with_bounds)
expected = r"""
n_samples=10_seed=0.ecdf lower_CI upper_CI
n_samples=10_seed=0
-1.26542 0.1 0.00000 0.43931
-0.70374 0.2 0.00000 0.53931
-0.53567 0.3 0.00000 0.63931
@@ -89,6 +92,7 @@ def test_gaussian2(self) -> None:
actual = get_df_as_str(empirical_cdf_with_bounds)
expected = r"""
n_samples=20_seed=1.ecdf lower_CI upper_CI
n_samples=20_seed=1
-1.30316 0.05 0.00000 0.32367
-0.78191 0.10 0.00000 0.37367
-0.73645 0.15 0.00000 0.42367
@@ -122,6 +126,52 @@ def get_gaussian_empirical_cdf_with_bounds(
empirical_cdf = csemdifu.compute_empirical_cdf_with_bounds(data, alpha)
return empirical_cdf

def test_combine_empirical_cdfs(self) -> None:
input_data = [
{"n_samples": 10, "seed": 0},
{"n_samples": 15, "seed": 0},
{"n_samples": 10, "seed": 1},
]
ecdfs = []
for sample_data in input_data:
data = cstrasam.get_iid_standard_gaussian_samples(
sample_data["n_samples"],
sample_data["seed"],
)
empirical_cdf = csemdifu.compute_empirical_cdf(data)
ecdfs.append(empirical_cdf)
actual_df = csemdifu.combine_empirical_cdfs(ecdfs)
actual = get_df_as_str(actual_df)
expected = r"""
n_samples=10_seed=0.ecdf n_samples=15_seed=0.ecdf n_samples=10_seed=1.ecdf
-2.32503 0.0 0.06667 0.0
-1.30316 0.0 0.06667 0.1
-1.26542 0.1 0.13333 0.1
-1.24591 0.1 0.20000 0.1
-0.70374 0.2 0.26667 0.1
-0.62327 0.2 0.33333 0.1
-0.53695 0.2 0.33333 0.2
-0.53567 0.3 0.40000 0.2
-0.21879 0.3 0.46667 0.2
-0.13210 0.4 0.53333 0.2
0.04133 0.4 0.60000 0.2
0.10490 0.5 0.66667 0.2
0.12573 0.6 0.73333 0.2
0.29413 0.6 0.73333 0.3
0.33044 0.6 0.73333 0.4
0.34558 0.6 0.73333 0.5
0.36160 0.7 0.80000 0.5
0.36457 0.7 0.80000 0.6
0.44637 0.7 0.80000 0.7
0.58112 0.7 0.80000 0.8
0.64042 0.8 0.86667 0.8
0.82162 0.8 0.86667 0.9
0.90536 0.8 0.86667 1.0
0.94708 0.9 0.93333 1.0
1.30400 1.0 1.00000 1.0
"""
self.assert_equal(actual, expected, fuzzy_match=True)


def get_df_as_str(df: pd.DataFrame) -> pd.DataFrame:
precision = 5
5 changes: 3 additions & 2 deletions dataflow_amp/pipelines/mock1/mock1_pipeline.py
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@
import core.signal_processing as csigproc
import dataflow.core as dtfcore
import helpers.hdbg as hdbg
import helpers.hpandas as hpandas

_LOG = logging.getLogger(__name__)

@@ -71,9 +72,9 @@ def set_weights(
"""
hdbg.dassert_isinstance(config, cconfig.Config)
hdbg.dassert_isinstance(weights, pd.Series)
# Index must be an Int64Index of consecutive integers starting at 1.
# Index must be an pd.Index of consecutive integers starting at 1.
idx = weights.index
hdbg.dassert_isinstance(idx, pd.Int64Index)
hdbg.dassert_eq(idx.dtype.type, np.int64)
# idx_size = idx.size
# hdbg.dassert_set_eq(weights.index.to_list(), list(range(1, idx_size + 1)))
# Generate the number of features corresponding to the weights.
21 changes: 11 additions & 10 deletions dev_scripts/test/outcomes/TestRunNotebook3.test3/output/test.txt
Original file line number Diff line number Diff line change
@@ -2,17 +2,17 @@
Traceback (most recent call last):
File "/venv/bin/jupyter-nbconvert", line 8, in <module>
sys.exit(main())
File "/venv/lib/python3.9/site-packages/jupyter_core/application.py", line 285, in launch_instance
return super().launch_instance(argv=argv, **kwargs)
File "/venv/lib/python3.9/site-packages/traitlets/config/application.py", line 1043, in launch_instance
File "/venv/lib/python3.9/site-packages/jupyter_core/application.py", line 282, in launch_instance
super().launch_instance(argv=argv, **kwargs)
File "/venv/lib/python3.9/site-packages/traitlets/config/application.py", line 1053, in launch_instance
app.start()
File "/venv/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 414, in start
File "/venv/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 412, in start
self.convert_notebooks()
File "/venv/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 589, in convert_notebooks
File "/venv/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 590, in convert_notebooks
self.convert_single_notebook(notebook_filename)
File "/venv/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 555, in convert_single_notebook
File "/venv/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 556, in convert_single_notebook
output, resources = self.export_single_notebook(
File "/venv/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 481, in export_single_notebook
File "/venv/lib/python3.9/site-packages/nbconvert/nbconvertapp.py", line 479, in export_single_notebook
output, resources = self.exporter.from_filename(
File "/venv/lib/python3.9/site-packages/nbconvert/exporters/exporter.py", line 201, in from_filename
return self.from_file(f, resources=resources, **kw)
@@ -26,11 +26,11 @@ Traceback (most recent call last):
nbc, resc = preprocessor(nbc, resc)
File "/venv/lib/python3.9/site-packages/nbconvert/preprocessors/base.py", line 48, in __call__
return self.preprocess(nb, resources)
File "/venv/lib/python3.9/site-packages/nbconvert/preprocessors/execute.py", line 100, in preprocess
File "/venv/lib/python3.9/site-packages/nbconvert/preprocessors/execute.py", line 102, in preprocess
self.preprocess_cell(cell, resources, index)
File "/venv/lib/python3.9/site-packages/nbconvert/preprocessors/execute.py", line 121, in preprocess_cell
File "/venv/lib/python3.9/site-packages/nbconvert/preprocessors/execute.py", line 123, in preprocess_cell
cell = self.execute_cell(cell, index, store_history=True)
File "/venv/lib/python3.9/site-packages/jupyter_core/utils/__init__.py", line 166, in wrapped
File "/venv/lib/python3.9/site-packages/jupyter_core/utils/__init__.py", line 168, in wrapped
return loop.run_until_complete(inner)
File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
return future.result()
@@ -54,3 +54,4 @@ Cell In[4], line 2
 3 print("Success")

ValueError: Failure

Loading

0 comments on commit df07377

Please sign in to comment.