arbintel / tests /test_bayesian.py
AJAY KASU
Add tests, alerts, and blockchain tracker
81146df
import pytest
from src.models.bayesian import BayesianFairValue
def test_bayesian_fair_value_initialization():
model = BayesianFairValue(prior_prob=0.5, prior_confidence=10.0)
assert model.get_fair_value() == 0.5
assert model.alpha == 5.0
assert model.beta == 5.0
def test_bayesian_update():
model = BayesianFairValue(prior_prob=0.5, prior_confidence=10.0)
# We observe a lot of volume trading at 0.70 implied probability
model.update(market_implied_prob=0.70, trade_volume=100.0, noise_factor=0.1)
# FV should shift towards 0.70
fv = model.get_fair_value()
assert fv > 0.5
assert fv < 0.70
def test_evaluate_opportunity():
model = BayesianFairValue(prior_prob=0.6, prior_confidence=100.0) # Highly confident at 0.6
# Market asks are way below FV (Underpriced)
opp_buy = model.evaluate_opportunity(current_ask=0.40, current_bid=0.38)
assert opp_buy is not None
assert opp_buy["action"] == "BUY_YES"
assert opp_buy["edge"] > 0.15 # 0.60 - 0.40 = 0.20ish edge
# Market bids are way above FV (Overpriced)
opp_sell = model.evaluate_opportunity(current_ask=0.82, current_bid=0.80)
assert opp_sell is not None
assert opp_sell["action"] == "SELL_YES"
assert opp_sell["edge"] > 0.15 # 0.80 - 0.60 = 0.20ish edge