begin "scratch.sql"

master
Brian Sakal 2 years ago
parent d519084df9
commit 64fb6cfaf3

@ -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;
Loading…
Cancel
Save