Add postgres functions for LMSR

This commit is contained in:
ekzyis 2024-08-26 16:16:19 -05:00
parent 74aa41d5f4
commit ce0084fc20
1 changed files with 14 additions and 0 deletions

View File

@ -64,3 +64,17 @@ CREATE TABLE withdrawals(
bolt11 TEXT NOT NULL UNIQUE,
paid_at TIMESTAMP WITH TIME ZONE
);
CREATE FUNCTION lmsr(b FLOAT, q1 FLOAT, q2 FLOAT)
RETURNS FLOAT AS $$
BEGIN
RETURN b * LN(EXP(q1 / b) + EXP(q2 / b));
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION quote(b FLOAT, q1 FLOAT, q2 FLOAT, dq1 FLOAT)
RETURNS FLOAT AS $$
BEGIN
RETURN lmsr(b, q1+dq1, q2) - lmsr(b, q1, q2);
END;
$$ LANGUAGE plpgsql;