Skip to content

Commit a3d3249

Browse files
committed
#145 Add tests for VolatilityWeight with positive and edge cases
Introduce new test cases to verify the correctness of `VolatilityWeight` for both valid and invalid inputs. This enhances test coverage to ensure proper handling of edge cases and improves robustness against unexpected inputs.
1 parent ffe3cfd commit a3d3249

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

tests/test_TradeRoutines.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ def test_VolatilityNegative(self):
13341334
assert result == 0.0 or np.isnan(result), f"Expected 0.0 or NaN for input: {testCase}"
13351335

13361336
except Exception:
1337-
pass # Also acceptable
1337+
pass # Also acceptable.
13381338

13391339
def test_ZScoreCheckType(self):
13401340
result = TradeRoutines.ZScore(logTargetRatio=0.05, meanReturn=0.01, volatility=0.02, horizon=10)
@@ -1368,7 +1368,7 @@ def test_ZScoreNegative(self):
13681368
assert np.isfinite(result), f"Unexpected result: {result}"
13691369

13701370
except Exception:
1371-
pass # Acceptable fallback on bad input
1371+
pass # Acceptable fallback on bad input.
13721372

13731373
def test_BayesianAggregationCheckType(self):
13741374
result = TradeRoutines.BayesianAggregation(0.6, 0.7)
@@ -1403,4 +1403,41 @@ def test_BayesianAggregationNegative(self):
14031403
assert 0.0 <= result <= 1.0, f"Result out of bounds: {result}"
14041404

14051405
except Exception:
1406-
pass # Acceptable on bad input
1406+
pass # Acceptable on bad input.
1407+
1408+
def test_VolatilityWeightCheckType(self):
1409+
result = TradeRoutines.VolatilityWeight(0.01, 0.02)
1410+
1411+
assert isinstance(result, float), "VolatilityWeight must return a float!"
1412+
1413+
def test_VolatilityWeightPositive(self):
1414+
testCases = [
1415+
(0.01, 0.01, 0.5),
1416+
(0.02, 0.01, 0.3333333333),
1417+
(0.01, 0.02, 0.6666666667),
1418+
(0.0, 0.01, 1.0),
1419+
(0.01, 0.0, 0.0),
1420+
]
1421+
1422+
for sigmaLow, sigmaHigh, expected in testCases:
1423+
result = TradeRoutines.VolatilityWeight(sigmaLow, sigmaHigh)
1424+
1425+
assert abs(result - expected) < 1e-10, f"Incorrect result for {sigmaLow}, {sigmaHigh}: {result}, expected: {expected}"
1426+
1427+
def test_VolatilityWeightNegative(self):
1428+
testCases = [
1429+
(-0.01, 0.02), # Negative sigmaLow.
1430+
(0.02, -0.01), # Negative sigmaHigh.
1431+
(0.0, 0.0), # Both zero.
1432+
(None, 0.01), # None input.
1433+
("bad", 0.01), # Non-numeric input.
1434+
]
1435+
1436+
for sigmaLow, sigmaHigh in testCases:
1437+
try:
1438+
result = TradeRoutines.VolatilityWeight(sigmaLow, sigmaHigh)
1439+
1440+
assert 0.0 <= result <= 1.0 or np.isnan(result), f"Unexpected result: {result}"
1441+
1442+
except Exception:
1443+
pass # Acceptable if function raises.

0 commit comments

Comments
 (0)