Spaces:
Configuration error
Configuration error
Niranjan-Murugarasu024
feat: TradeSense AI Chairman Edition production release ready for Hugging Face Spaces
0125724 Download backend/tests/quant/test_conditional_replication.py from BlueMen/tradesenseAi: direct link, hf CLI and curl.
- Browser
- Download file 2.27 kB
-
https://huggingface.co/spaces/BlueMen/tradesenseAi/resolve/main/backend/tests/quant/test_conditional_replication.py
- Command line
-
hf download hf://spaces/BlueMen/tradesenseAi/backend/tests/quant/test_conditional_replication.py
-
curl -L -o test_conditional_replication.py https://huggingface.co/spaces/BlueMen/tradesenseAi/resolve/main/backend/tests/quant/test_conditional_replication.py
2.27 kB
| """ | |
| TradeSense AI — Conditional Replication Unit Tests | |
| Validates: | |
| - Untouched 20-asset Tech/Consumer cohort definition | |
| - Cohort evaluation pipeline execution | |
| """ | |
| from datetime import date, timedelta | |
| import numpy as np | |
| import pandas as pd | |
| import pytest | |
| from quant.research.conditional_replication_engine import ( | |
| ConditionalReplicationEngine, | |
| CohortReplicationReport, | |
| UNTOUCHED_TECH_CONSUMER_20, | |
| ) | |
| def generate_synthetic_universe(tickers: list, n_rows: int = 250) -> dict: | |
| np.random.seed(42) | |
| start_date = date(2020, 1, 1) | |
| dates = [start_date + timedelta(days=i) for i in range(n_rows)] | |
| universe = {} | |
| for idx, tk in enumerate(tickers): | |
| drift = 0.0004 + (idx * 0.0001) | |
| vol = 0.012 + (idx * 0.002) | |
| rets = np.random.normal(drift, vol, n_rows) | |
| close = 100.0 * np.cumprod(1.0 + rets) | |
| high = close * 1.01 | |
| low = close * 0.99 | |
| open_p = (high + low) / 2.0 | |
| vol_shares = np.random.randint(1000000, 5000000, n_rows) | |
| universe[tk] = pd.DataFrame({ | |
| "session": dates, | |
| "Open": open_p, | |
| "High": high, | |
| "Low": low, | |
| "Close": close, | |
| "Volume": vol_shares, | |
| }) | |
| return universe | |
| class TestConditionalReplication: | |
| def test_cohort_definition_structure(self): | |
| tks = ConditionalReplicationEngine.get_cohort_tickers() | |
| sec_map = ConditionalReplicationEngine.get_cohort_sector_map() | |
| assert len(tks) == 20 | |
| assert len(sec_map) == 20 | |
| assert "QCOM" in tks | |
| assert "BKNG" in tks | |
| def test_evaluate_untouched_cohort_execution(self): | |
| tks = ["QCOM", "TXN", "AVGO", "BKNG", "ABNB", "ORLY", "SPY"] | |
| universe = generate_synthetic_universe(tks, n_rows=300) | |
| rep: CohortReplicationReport = ConditionalReplicationEngine.evaluate_untouched_cohort( | |
| cohort_dfs={tk: universe[tk] for tk in tks if tk != "SPY"}, | |
| spy_df=universe["SPY"], | |
| horizon_sessions=5, | |
| ) | |
| assert rep.n_cohort_assets == 6 | |
| assert rep.orthogonalization_audit.n_sessions > 0 | |
| assert rep.purged_walk_forward.total_folds > 0 | |
| assert isinstance(rep.is_graduation_to_robust_conditional_alpha_approved, bool) | |