-
Notifications
You must be signed in to change notification settings - Fork 13
Custom Functions
Pedro Holanda edited this page Jun 22, 2024
·
1 revision
Scrooge supports various custom functions, focusing on performing financial analysis.
FIRST_S(A::{NUMERIC_VALUE}, B::{TIMESTAMPTZ})
It returns the value of column A based on the earliest timestamp in column B.
SELECT FIRST_S(price, time) AS "open" FROM finance;
LAST_S(A::{NUMERIC_VALUE}, B::{TIMESTAMPTZ})
It returns the value of column A based on the latest timestamp value of column B.
SELECT LAST_S(price, time) AS "close" FROM finance;
TIMEBUCKET(A::{TIMESTAMPTZ}, B::{INTERVAL})
Creates timestamp buckets on column A, with ranges on the interval of value B.
SELECT TIMEBUCKET(time,'1M'::INTERVAL) AS bucket FROM finance;
VOLATILITY(A::{NUMERIC})
Returns the volatility of that financial instrument during the given period of time.
SELECT VOLATILITY(value) AS bucket FROM finance;
SMA(A::{NUMERIC})
Returns a financial instrument's average price during a period of time.
SELECT SMA(value) AS bucket FROM finance;