@@ -81,7 +81,7 @@ def fake_loader(_ib, symbol, duration="2 Y", bar_size="1 day"):
8181 if symbol == "SOXL" :
8282 return [100.0 + idx for idx in range (170 )]
8383 if symbol == "SOXX" :
84- return [200.0 + idx for idx in range (20 )]
84+ return [200.0 + idx for idx in range (170 )]
8585 raise AssertionError (symbol )
8686
8787 indicators = build_semiconductor_rotation_indicators (
@@ -91,20 +91,29 @@ def fake_loader(_ib, symbol, duration="2 Y", bar_size="1 day"):
9191 )
9292
9393 self .assertEqual (observed [0 ], ("SOXL" , "220 D" , "1 day" ))
94- self .assertEqual (observed [1 ], ("SOXX" , "20 D" , "1 day" ))
94+ self .assertEqual (observed [1 ], ("SOXX" , "220 D" , "1 day" ))
9595 self .assertEqual (indicators ["soxl" ]["price" ], 269.0 )
9696 self .assertAlmostEqual (
9797 indicators ["soxl" ]["ma_trend" ],
9898 sum (100.0 + idx for idx in range (20 , 170 )) / 150 ,
9999 )
100- self .assertEqual (indicators ["soxx" ]["price" ], 219.0 )
100+ self .assertEqual (indicators ["soxx" ]["price" ], 369.0 )
101+ self .assertAlmostEqual (
102+ indicators ["soxx" ]["ma_trend" ],
103+ sum (200.0 + idx for idx in range (20 , 170 )) / 150 ,
104+ )
105+ self .assertAlmostEqual (
106+ indicators ["soxx" ]["ma20" ],
107+ sum (200.0 + idx for idx in range (150 , 170 )) / 20 ,
108+ )
109+ self .assertGreater (indicators ["soxx" ]["ma20_slope" ], 0.0 )
101110
102111 def test_build_semiconductor_rotation_inputs_wraps_derived_indicators (self ) -> None :
103112 def fake_loader (_ib , symbol , duration = "2 Y" , bar_size = "1 day" ):
104113 if symbol == "SOXL" :
105114 return [100.0 ] * 170
106115 if symbol == "SOXX" :
107- return [200.0 ] * 20
116+ return [200.0 ] * 170
108117 raise AssertionError (symbol )
109118
110119 payload = build_semiconductor_rotation_inputs (
@@ -116,6 +125,7 @@ def fake_loader(_ib, symbol, duration="2 Y", bar_size="1 day"):
116125 self .assertEqual (set (payload ), {"derived_indicators" })
117126 self .assertEqual (payload ["derived_indicators" ]["soxl" ]["price" ], 100.0 )
118127 self .assertEqual (payload ["derived_indicators" ]["soxx" ]["price" ], 200.0 )
128+ self .assertEqual (payload ["derived_indicators" ]["soxx" ]["ma20" ], 200.0 )
119129
120130 def test_build_semiconductor_rotation_indicators_requires_sufficient_history (self ) -> None :
121131 def fake_loader (_ib , symbol , duration = "2 Y" , bar_size = "1 day" ):
0 commit comments