6
6
import pandas as pd
7
7
import unittest
8
8
9
- sys .path .append (os .path .abspath ("../" ))
9
+ BASE_DIR = os .path .dirname (__file__ )
10
+ sys .path .append (os .path .abspath (os .path .join (BASE_DIR , ".." )))
10
11
from smartmoneyconcepts .smc import smc
11
12
12
13
# define and import test data
13
14
test_instrument = "EURUSD"
14
15
instrument_data = f"{ test_instrument } _15M.csv"
15
- df = pd .read_csv (os .path .join ("test_data" , test_instrument , instrument_data ))
16
+ TEST_DATA_DIR = os .path .join (BASE_DIR , "test_data" , test_instrument )
17
+ df = pd .read_csv (os .path .join (TEST_DATA_DIR , instrument_data ))
16
18
df = df .set_index ("Date" )
17
19
df .index = pd .to_datetime (df .index )
18
20
@@ -24,7 +26,7 @@ def test_fvg(self):
24
26
start_time = time .time ()
25
27
fvg_data = smc .fvg (df )
26
28
fvg_result_data = pd .read_csv (
27
- os .path .join ("test_data" , test_instrument , "fvg_result_data.csv" )
29
+ os .path .join (TEST_DATA_DIR , "fvg_result_data.csv" )
28
30
)
29
31
print ("fvg test time: " , time .time () - start_time )
30
32
pd .testing .assert_frame_equal (fvg_data , fvg_result_data , check_dtype = False )
@@ -33,7 +35,7 @@ def test_fvg_consecutive(self):
33
35
start_time = time .time ()
34
36
fvg_data = smc .fvg (df , join_consecutive = True )
35
37
fvg_consecutive_result_data = pd .read_csv (
36
- os .path .join ("test_data" , test_instrument , "fvg_consecutive_result_data.csv" )
38
+ os .path .join (TEST_DATA_DIR , "fvg_consecutive_result_data.csv" )
37
39
)
38
40
print ("fvg consecutive test time: " , time .time () - start_time )
39
41
pd .testing .assert_frame_equal (fvg_data , fvg_consecutive_result_data , check_dtype = False )
@@ -42,9 +44,7 @@ def test_swing_highs_lows(self):
42
44
start_time = time .time ()
43
45
swing_highs_lows_data = smc .swing_highs_lows (df , swing_length = 5 )
44
46
swing_highs_lows_result_data = pd .read_csv (
45
- os .path .join (
46
- "test_data" , test_instrument , "swing_highs_lows_result_data.csv"
47
- )
47
+ os .path .join (TEST_DATA_DIR , "swing_highs_lows_result_data.csv" )
48
48
)
49
49
print ("swing_highs_lows test time: " , time .time () - start_time )
50
50
pd .testing .assert_frame_equal (swing_highs_lows_data , swing_highs_lows_result_data , check_dtype = False )
@@ -54,7 +54,7 @@ def test_bos_choch(self):
54
54
swing_highs_lows_data = smc .swing_highs_lows (df , swing_length = 5 )
55
55
bos_choch_data = smc .bos_choch (df , swing_highs_lows_data )
56
56
bos_choch_result_data = pd .read_csv (
57
- os .path .join ("test_data" , test_instrument , "bos_choch_result_data.csv" )
57
+ os .path .join (TEST_DATA_DIR , "bos_choch_result_data.csv" )
58
58
)
59
59
print ("bos_choch test time: " , time .time () - start_time )
60
60
pd .testing .assert_frame_equal (
@@ -66,17 +66,32 @@ def test_ob(self):
66
66
swing_highs_lows_data = smc .swing_highs_lows (df , swing_length = 5 )
67
67
ob_data = smc .ob (df , swing_highs_lows_data )
68
68
ob_result_data = pd .read_csv (
69
- os .path .join ("test_data" , test_instrument , "ob_result_data.csv" )
69
+ os .path .join (TEST_DATA_DIR , "ob_result_data.csv" )
70
70
)
71
71
print ("ob test time: " , time .time () - start_time )
72
72
pd .testing .assert_frame_equal (ob_data , ob_result_data , check_dtype = False )
73
73
74
+ def test_ob_early_data (self ):
75
+ """Ensure early candles do not cause index errors in OB calculation."""
76
+ short_df = pd .DataFrame (
77
+ {
78
+ "open" : [1.0 , 1.1 , 1.2 ],
79
+ "high" : [1.05 , 1.15 , 1.25 ],
80
+ "low" : [0.95 , 1.05 , 1.15 ],
81
+ "close" : [1.02 , 1.14 , 1.24 ],
82
+ "volume" : [5 , 6 , 7 ],
83
+ }
84
+ )
85
+ swing = smc .swing_highs_lows (short_df , swing_length = 1 )
86
+ ob_df = smc .ob (short_df , swing )
87
+ self .assertEqual (len (ob_df ), len (short_df ))
88
+
74
89
def test_liquidity (self ):
75
90
start_time = time .time ()
76
91
swing_highs_lows_data = smc .swing_highs_lows (df , swing_length = 5 )
77
92
liquidity_data = smc .liquidity (df , swing_highs_lows_data )
78
93
liquidity_result_data = pd .read_csv (
79
- os .path .join ("test_data" , test_instrument , "liquidity_result_data.csv" )
94
+ os .path .join (TEST_DATA_DIR , "liquidity_result_data.csv" )
80
95
)
81
96
print ("liquidity test time: " , time .time () - start_time )
82
97
pd .testing .assert_frame_equal (liquidity_data , liquidity_result_data , check_dtype = False )
@@ -86,9 +101,7 @@ def test_previous_high_low(self):
86
101
start_time = time .time ()
87
102
previous_high_low_data = smc .previous_high_low (df , time_frame = "4h" )
88
103
previous_high_low_result_data = pd .read_csv (
89
- os .path .join (
90
- "test_data" , test_instrument , "previous_high_low_result_data_4h.csv"
91
- )
104
+ os .path .join (TEST_DATA_DIR , "previous_high_low_result_data_4h.csv" )
92
105
)
93
106
print ("previous_high_low test time: " , time .time () - start_time )
94
107
pd .testing .assert_frame_equal (previous_high_low_data , previous_high_low_result_data , check_dtype = False )
@@ -97,9 +110,7 @@ def test_previous_high_low(self):
97
110
start_time = time .time ()
98
111
previous_high_low_data = smc .previous_high_low (df , time_frame = "1D" )
99
112
previous_high_low_result_data = pd .read_csv (
100
- os .path .join (
101
- "test_data" , test_instrument , "previous_high_low_result_data_1D.csv"
102
- )
113
+ os .path .join (TEST_DATA_DIR , "previous_high_low_result_data_1D.csv" )
103
114
)
104
115
print ("previous_high_low test time: " , time .time () - start_time )
105
116
pd .testing .assert_frame_equal (previous_high_low_data , previous_high_low_result_data , check_dtype = False )
@@ -108,9 +119,7 @@ def test_previous_high_low(self):
108
119
start_time = time .time ()
109
120
previous_high_low_data = smc .previous_high_low (df , time_frame = "W" )
110
121
previous_high_low_result_data = pd .read_csv (
111
- os .path .join (
112
- "test_data" , test_instrument , "previous_high_low_result_data_W.csv"
113
- )
122
+ os .path .join (TEST_DATA_DIR , "previous_high_low_result_data_W.csv" )
114
123
)
115
124
print ("previous_high_low test time: " , time .time () - start_time )
116
125
pd .testing .assert_frame_equal (previous_high_low_data , previous_high_low_result_data , check_dtype = False )
@@ -119,7 +128,7 @@ def test_sessions(self):
119
128
start_time = time .time ()
120
129
sessions = smc .sessions (df , session = "London" )
121
130
sessions_result_data = pd .read_csv (
122
- os .path .join ("test_data" , test_instrument , "sessions_result_data.csv" )
131
+ os .path .join (TEST_DATA_DIR , "sessions_result_data.csv" )
123
132
)
124
133
print ("sessions test time: " , time .time () - start_time )
125
134
pd .testing .assert_frame_equal (sessions , sessions_result_data , check_dtype = False )
@@ -129,7 +138,7 @@ def test_retracements(self):
129
138
swing_highs_lows_data = smc .swing_highs_lows (df , swing_length = 5 )
130
139
retracements = smc .retracements (df , swing_highs_lows_data )
131
140
retracements_result_data = pd .read_csv (
132
- os .path .join ("test_data" , test_instrument , "retracements_result_data.csv" )
141
+ os .path .join (TEST_DATA_DIR , "retracements_result_data.csv" )
133
142
)
134
143
print ("retracements test time: " , time .time () - start_time )
135
144
pd .testing .assert_frame_equal (retracements , retracements_result_data , check_dtype = False )
0 commit comments