From 64fb6cfaf3412515f02ee4740301c9355f46ac7a Mon Sep 17 00:00:00 2001 From: Brian Sakal Date: Mon, 1 May 2023 00:08:35 -0400 Subject: [PATCH] begin "scratch.sql" --- scratch.sql | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 scratch.sql diff --git a/scratch.sql b/scratch.sql new file mode 100644 index 0000000..e7ac885 --- /dev/null +++ b/scratch.sql @@ -0,0 +1,72 @@ +-- list around-the-money calls: +SELECT + s.symbol, + s.close, + o.strike, + o.delta, + o.bid, + o.ask +FROM + stock_quote AS s +INNER JOIN + option_quote AS o + ON o.underlying = s.symbol +WHERE + abs(o.strike-s.close)/s.close < 0.07 + AND + o.type = 'call' +LIMIT 30; + +-- historical payoff of at-the-money calendars: +SELECT + s.quote_date, + s.symbol, + s.close, + front_month.strike AS strike, + front_month.type AS "type", + front_month.expiration AS front_month_exp, + back_month.expiration AS back_month_exp, + (back_month.ask-front_month.bid) AS cost, + (back_month_at_exp.bid-cost) AS payout +FROM + stock_quote AS s +INNER JOIN + option_quote AS front_month + ON + front_month.underlying = s.symbol + AND + front_month.quote_date = s.quote_date + AND + front_month.expiration > s.quote_date +INNER JOIN + option_quote AS back_month + ON + back_month.underlying = s.symbol + AND + back_month.quote_date = front_month.quote_date + AND + back_month.strike = front_month.strike + AND + back_month.type = front_month.type + AND + back_month.expiration > front_month.expiration +INNER JOIN + option_quote AS back_month_at_exp + ON + back_month_at_exp.underlying = s.symbol + AND + back_month_at_exp.strike = back_month.strike + AND + back_month_at_exp.type = back_month.type + AND + back_month_at_exp.expiration = back_month.expiration + AND + back_month_at_exp.quote_date = front_month.expiration +WHERE + s.symbol = 'MSFT' +ORDER BY + s.quote_date, + s.symbol, + strike, + "type" +LIMIT 30;