From e94f0fadaf0549103dfd032b3ddbde0585936fef Mon Sep 17 00:00:00 2001 From: Avraham Sakal Date: Wed, 28 Jun 2023 21:47:09 -0400 Subject: [PATCH] Add sample query to scratch.sql --- scratch.sql | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scratch.sql b/scratch.sql index e7ac885..5444471 100644 --- a/scratch.sql +++ b/scratch.sql @@ -70,3 +70,23 @@ ORDER BY strike, "type" LIMIT 30; + +-- given an underlying, contract type, strike, and front/back expirations: for each quote_date, list prices of calendars: +SELECT + "front_contract"."quote_date", + ("back_contract"."ask" - "front_contract"."bid") AS "price" +FROM + "option_quote" AS "front_contract" +INNER JOIN + "option_quote" AS "back_contract" + ON + "back_contract"."underlying" = "front_contract"."underlying" + AND "back_contract"."type" = "front_contract"."type" + AND "back_contract"."quote_date" = "front_contract"."quote_date" + AND "back_contract"."strike" = "front_contract"."strike" + AND "back_contract"."expiration" = '?' +WHERE + "front_contract"."underlying" = '?' + AND "front_contract"."type" = 'call' + AND "front_contract"."strike" = '?' + AND "front_contract"."expiration" = '?'