Trading

Build trading strategies using probabilistic forecasts.

Directional Trading

directional_trading.py
def get_signal(asset, threshold=0.60):
    predictions = get_predictions(asset)
    all_paths = aggregate_paths(predictions)
    
    current = all_paths[0][0]
    final_prices = [path[-1] for path in all_paths]
    prob_up = sum(1 for p in final_prices if p > current) / len(final_prices)
    
    if prob_up > threshold:
        return "LONG"
    elif prob_up < (1 - threshold):
        return "SHORT"
    else:
        return "NEUTRAL"

Position Sizing

position_sizing.py
def kelly_size(prob_win, avg_win, avg_loss, max_kelly=0.25):
    win_loss_ratio = avg_win / avg_loss
    kelly = (prob_win * win_loss_ratio - (1 - prob_win)) / win_loss_ratio
    return max(0, min(kelly, max_kelly))

Risk Management