Download tests/test_logic.py from algorembrant/mBA-Terminal: direct link, hf CLI and curl.
- Browser
- Download file 2.28 kB
-
https://huggingface.co/algorembrant/mBA-Terminal/resolve/main/tests/test_logic.py
- Command line
-
hf download hf://algorembrant/mBA-Terminal/tests/test_logic.py
-
curl -L -o test_logic.py https://huggingface.co/algorembrant/mBA-Terminal/resolve/main/tests/test_logic.py
2.28 kB
| import sys | |
| import os | |
| import unittest | |
| import numpy as np | |
| import pandas as pd | |
| # Add src to path | |
| sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | |
| from src.core.market_profile import MarketProfile | |
| class TestMarketProfile(unittest.TestCase): | |
| def setUp(self): | |
| self.mp = MarketProfile(unit_size=1.0) # Simple unit size | |
| def test_gap_fill(self): | |
| prices = np.array([100.0, 105.0]) | |
| timestamps = np.array([0, 100], dtype=np.int64) | |
| filled = self.mp.fill_gaps(prices, timestamps) | |
| # Expected: 100, 101, 102, 103, 104, 105 | |
| expected = np.array([100.0, 101.0, 102.0, 103.0, 104.0, 105.0]) | |
| np.testing.assert_array_equal(filled, expected) | |
| def test_profile_calculation(self): | |
| # Create a skewed profile | |
| # 100: 10 counts | |
| # 101: 20 counts (POC) | |
| # 102: 5 counts | |
| # Construct dataframe | |
| data = { | |
| 'bid': np.concatenate([ | |
| np.full(10, 100.0), | |
| np.full(20, 101.0), | |
| np.full(5, 102.0) | |
| ]), | |
| 'datetime': np.zeros(35, dtype='datetime64[ns]') # Timestamps don't matter much for counts | |
| } | |
| df = pd.DataFrame(data) | |
| # Since gap filling needs consecutive diffs, and here we have flat regions, | |
| # gap filling on [100, 100] produces just [100, 100]. | |
| # But `fill_gaps` logic: diff=0 -> count=0 -> total=0? | |
| # My implementation: counts = abs(diff) ... append 1 for last point. | |
| # If diff=0, count=0. Total = 0 + 1 = 1. | |
| # It handles flat lines correctly (just repeats the point). | |
| self.mp.update(df) | |
| vah, val, poc = self.mp.get_vah_val_poc() | |
| self.assertEqual(poc, 101.0) | |
| # Total vol = 35. 70% = 24.5. | |
| # POC volume = 20. | |
| # Neighbors: 100 (10), 102 (5). | |
| # 100 is larger. So it should expand to 100. | |
| # Current vol = 20 + 10 = 30 > 24.5. Stop. | |
| # So Value Area = [100, 101]. | |
| # VAL = 100, VAH = 101. | |
| self.assertEqual(val, 100.0) | |
| self.assertEqual(vah, 101.0) | |
| if __name__ == '__main__': | |
| unittest.main() | |