razvan commited on
Commit
fdd86fe
·
verified ·
1 Parent(s): 083ef84

Upload tests/test_quant_engine.py

Browse files
Files changed (1) hide show
  1. tests/test_quant_engine.py +54 -0
tests/test_quant_engine.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Unit tests for the Kelly quant engine.
3
+ """
4
+ import numpy as np
5
+ from builderbrain.quant_engine import KellyEngine, CorrelationMatrix, MarketEdge
6
+
7
+
8
+ def test_correlation_matrix_build():
9
+ markets = [
10
+ MarketEdge("trump_2024", "Will Trump win?", "politics", "YES", 0.08, 0.55, 0.63, 50000, "2024-11-05"),
11
+ MarketEdge("musk_doge", "Will Musk lead DOGE?", "politics", "YES", 0.05, 0.60, 0.65, 30000, "2024-12-01"),
12
+ MarketEdge("btc_100k", "BTC > $100k?", "crypto", "YES", 0.10, 0.40, 0.50, 100000, "2024-12-31"),
13
+ ]
14
+ corr = CorrelationMatrix()
15
+ matrix = corr.build(markets)
16
+ assert matrix.shape == (3, 3)
17
+ assert np.allclose(np.diag(matrix), 1.0)
18
+ # Politics-politics should be high
19
+ assert matrix[0, 1] > 0.5
20
+ # Politics-crypto should be low
21
+ assert matrix[0, 2] < 0.2
22
+ print("✅ test_correlation_matrix_build passed")
23
+
24
+
25
+ def test_kelly_engine_basic():
26
+ engine = KellyEngine(bankroll_usd=10000)
27
+ markets = [
28
+ MarketEdge("m1", "Test 1", "sports", "YES", 0.10, 0.40, 0.50, 10000, "2024-12-01"),
29
+ MarketEdge("m2", "Test 2", "sports", "NO", 0.05, 0.55, 0.50, 10000, "2024-12-01"),
30
+ ]
31
+ positions = engine.size_positions(markets)
32
+ assert len(positions) > 0
33
+ total = sum(p.fraction_of_bankroll for p in positions)
34
+ assert total <= engine.max_leverage + 1e-6
35
+ for p in positions:
36
+ assert p.fraction_of_bankroll <= 0.25 + 1e-6
37
+ print("✅ test_kelly_engine_basic passed")
38
+
39
+
40
+ def test_kelly_no_viable_edges():
41
+ engine = KellyEngine(bankroll_usd=10000, min_edge=0.50)
42
+ markets = [
43
+ MarketEdge("m1", "Test", "sports", "YES", 0.01, 0.49, 0.50, 10000, "2024-12-01"),
44
+ ]
45
+ positions = engine.size_positions(markets)
46
+ assert len(positions) == 0
47
+ print("✅ test_kelly_no_viable_edges passed")
48
+
49
+
50
+ if __name__ == "__main__":
51
+ test_correlation_matrix_build()
52
+ test_kelly_engine_basic()
53
+ test_kelly_no_viable_edges()
54
+ print("\n🎉 All quant engine tests passed")