File size: 2,239 Bytes
c99df4c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import sys
import os
import pandas as pd
import numpy as np

# Add project root to sys.path
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)...")
    
    # 1. Setup Data
    # Bid moves from 100.00 to 101.00 (Diff 1.0)
    # Ask moves from 100.10 to 101.10 (Diff 1.0)
    # Spread = 0.10
    # Multiplier = 2.0 -> Bin Size = 0.20
    
    # Expected Gaps for Bid: 1.0 / 0.20 = 5 steps.
    # Bid points: 100.0, 100.2, 100.4, 100.6, 100.8, 101.0 -> 6 points.
    
    # Expected Gaps for Ask: 1.0 / 0.20 = 5 steps.
    # Ask points: 100.1, 100.3, 100.5, 100.7, 100.9, 101.1 -> 6 points.
    
    # Total Ticks = 12.
    
    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)
    
    # 2. Initialize Profile
    mp = MarketProfile(multiplier=multiplier)
    
    # 3. Update
    mp.update(df)
    
    # 4. Verify
    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}")
    
    # Check specific prices
    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()