| | import sys
|
| | import os
|
| | import unittest
|
| | import numpy as np
|
| | import pandas as pd
|
| |
|
| |
|
| | 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)
|
| |
|
| | 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 = 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):
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | 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]')
|
| | }
|
| | df = pd.DataFrame(data)
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | self.mp.update(df)
|
| |
|
| | vah, val, poc = self.mp.get_vah_val_poc()
|
| |
|
| | self.assertEqual(poc, 101.0)
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | self.assertEqual(val, 100.0)
|
| | self.assertEqual(vah, 101.0)
|
| |
|
| | if __name__ == '__main__':
|
| | unittest.main()
|
| |
|