From 2471ce872a1300d80c212c3442a100c2da8247db Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Fri, 13 Dec 2024 20:29:09 +0100 Subject: [PATCH] add new filter for options flow page moneyness --- src/routes/options-flow/+page.svelte | 13 ++++++--- .../options-flow/workers/filterWorker.ts | 27 ++++++++++++++++++- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/routes/options-flow/+page.svelte b/src/routes/options-flow/+page.svelte index 3f2a4a21..b6a2ca35 100644 --- a/src/routes/options-flow/+page.svelte +++ b/src/routes/options-flow/+page.svelte @@ -90,6 +90,11 @@ defaultCondition: "over", defaultValue: "any", }, + moneyness: { + label: "Moneyness", + step: ["ITM", "OTM"], + defaultValue: "any", + }, put_call: { label: "Contract Type", step: ["Calls", "Puts"], @@ -212,6 +217,7 @@ let newRule; switch (ruleName) { + case "moneyness": case "put_call": case "sentiment": case "execution_estimate": @@ -343,6 +349,7 @@ // Specific rule handling for options-related rules if ( [ + "moneyness", "put_call", "sentiment", "execution_estimate", @@ -1123,7 +1130,7 @@ - {#if !["put_call", "sentiment", "execution_estimate", "option_activity_type", "underlying_type"]?.includes(row?.rule)} + {#if !["moneyness", "put_call", "sentiment", "execution_estimate", "option_activity_type", "underlying_type"]?.includes(row?.rule)} @@ -1283,7 +1290,7 @@ > {/if} - {#if !["put_call", "sentiment", "execution_estimate", "option_activity_type", "underlying_type"]?.includes(row?.rule)} + {#if !["moneyness", "put_call", "sentiment", "execution_estimate", "option_activity_type", "underlying_type"]?.includes(row?.rule)} {#each row?.step as newValue, index} {#if ruleCondition[row?.rule] === "between"} {#if newValue && row?.step[index + 1]} @@ -1327,7 +1334,7 @@ {/if} {/each} - {:else if ["put_call", "sentiment", "execution_estimate", "option_activity_type", "underlying_type"]?.includes(row?.rule)} + {:else if ["moneyness", "put_call", "sentiment", "execution_estimate", "option_activity_type", "underlying_type"]?.includes(row?.rule)} {#each row?.step as item} { + + if (ruleValue === 'any') return true; + + const currentPrice = parseFloat(item?.underlying_price); + const strikePrice = parseFloat(item?.strike_price); + const optionType = item?.put_call; + if (isNaN(currentPrice) || isNaN(strikePrice)) return false; + + // Determine moneyness + let moneyness = ''; + if (optionType === 'Calls') { + moneyness = currentPrice > strikePrice ? 'ITM' : 'OTM'; + } else if (optionType === 'Puts') { + moneyness = currentPrice < strikePrice ? 'ITM' : 'OTM'; + } + // Check if the item matches the ruleValue ('itm' or 'otm') + if (!ruleValue?.includes(moneyness)) return false; + return true; + }; + } + if (ruleName === 'volumeoiratio') { return (item) => { const volume = parseFloat(item.volume);