| | import sys
|
| | import os
|
| | import pandas as pd
|
| | import numpy as np
|
| |
|
| |
|
| | current_dir = os.path.dirname(os.path.abspath(__file__))
|
| | project_root = os.path.dirname(current_dir)
|
| | sys.path.append(project_root)
|
| |
|
| | from src.core.market_profile import MarketProfile
|
| |
|
| | def test_market_profile_logic():
|
| | print("Testing Market Profile Logic (Bid + Ask + Timestamp Interpolation)...")
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| |
|
| | multiplier = 2.0
|
| |
|
| | data = {
|
| | 'datetime': [pd.Timestamp('2023-01-01 10:00:00'), pd.Timestamp('2023-01-01 10:00:01')],
|
| | 'bid': [100.00, 101.00],
|
| | 'ask': [100.10, 101.10]
|
| | }
|
| | df = pd.DataFrame(data)
|
| |
|
| |
|
| | mp = MarketProfile(multiplier=multiplier)
|
| |
|
| |
|
| | mp.update(df)
|
| |
|
| |
|
| | print(f"Total Ticks (Count sum): {mp.total_ticks}")
|
| | expected_ticks = 12
|
| |
|
| | if mp.total_ticks == expected_ticks:
|
| | print("SUCCESS: Total Ticks match expected (Bid + Ask filled).")
|
| | else:
|
| | print(f"FAILURE: Expected {expected_ticks}, got {mp.total_ticks}")
|
| |
|
| | print(f"Counts: {mp.counts}")
|
| |
|
| |
|
| | expected_bids = [100.00, 100.20, 100.40, 100.60, 100.80, 101.00]
|
| | expected_asks = [100.10, 100.30, 100.50, 100.70, 100.90, 101.10]
|
| | all_expected = expected_bids + expected_asks
|
| |
|
| | missing = []
|
| | for p in all_expected:
|
| | p_rounded = round(p, 2)
|
| | if p_rounded not in mp.counts:
|
| | missing.append(p_rounded)
|
| |
|
| | if not missing:
|
| | print("SUCCESS: All expected Bid and Ask gap prices found.")
|
| | else:
|
| | print(f"FAILURE: Missing prices: {missing}")
|
| |
|
| | if __name__ == "__main__":
|
| | test_market_profile_logic()
|
| |
|