From 853c82de1255210503d483a95cfcccccd6c8dfd6 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Tue, 14 Jan 2025 23:52:58 +0100 Subject: [PATCH] add new page called volatility --- src/lib/components/Options/Volatility.svelte | 610 ++++++++++++++++++ .../stocks/[tickerID]/options/+layout.svelte | 12 + .../options/volatility/+layout.svelte | 15 + .../options/volatility/+page.server.ts | 31 + .../options/volatility/+page.svelte | 70 ++ 5 files changed, 738 insertions(+) create mode 100644 src/lib/components/Options/Volatility.svelte create mode 100644 src/routes/stocks/[tickerID]/options/volatility/+layout.svelte create mode 100644 src/routes/stocks/[tickerID]/options/volatility/+page.server.ts create mode 100644 src/routes/stocks/[tickerID]/options/volatility/+page.svelte diff --git a/src/lib/components/Options/Volatility.svelte b/src/lib/components/Options/Volatility.svelte new file mode 100644 index 00000000..57095c69 --- /dev/null +++ b/src/lib/components/Options/Volatility.svelte @@ -0,0 +1,610 @@ + + +
+

+ Volatility Exposure +

+ +
+
+
+
Date
+
+ af +
+
+
+ +
+
+
+ Avg. Implied Volatility +
+
+ {avgIV?.toFixed(2)} +
+
+
+
+
+
+ Avg. Realized Volatility +
+
+ {avgRV?.toFixed(2)} +
+
+
+
+
+
IV / RV
+
+ a +
+
+
+
+ +
+ {#if options !== null} +
+
+ {#each ["3M", "6M", "1Y"] as item} + + {/each} +
+ + +
+ {:else} +
+
+ +
+
+ {/if} +
+
+ + + + + + {#each data?.user?.tier === "Pro" ? displayList : displayList?.slice(0, 3) as item, index} + + + + + + + + + + + + + + + + + {/each} + +
+ {formatDate(item?.date)} + + {#if item?.changesPercentage >= 0} + +{item?.changesPercentage >= 1000 + ? abbreviateNumberWithColor(item?.changesPercentage) + : item?.changesPercentage?.toFixed(2)}% + {:else if item?.changesPercentage < 0} + {item?.changesPercentage <= -1000 + ? abbreviateNumberWithColor(item?.changesPercentage) + : item?.changesPercentage?.toFixed(2)}% + + {:else} + n/a + {/if} + + {item?.putCallRatio} + + {@html abbreviateNumberWithColor( + item?.total_open_interest, + false, + true, + )} + + {#if item?.changesPercentageOI >= 0 && item?.changesPercentageOI !== null} + +{item?.changesPercentageOI >= 1000 + ? abbreviateNumberWithColor(item?.changesPercentageOI) + : item?.changesPercentageOI?.toFixed(2)}% + {:else if item?.changesPercentageOI < 0 && item?.changesPercentageOI !== null} + {item?.changesPercentageOI <= -1000 + ? abbreviateNumberWithColor(item?.changesPercentageOI) + : item?.changesPercentageOI?.toFixed(2)}% + + {:else} + n/a + {/if} + + {item?.implied_volatility} + + {item?.realized_volatility ?? "n/a"} + + {item?.volatilitySpread ?? "n/a"} +
+
+ + +
+ + diff --git a/src/routes/stocks/[tickerID]/options/+layout.svelte b/src/routes/stocks/[tickerID]/options/+layout.svelte index b6dbeb35..15dacd7f 100644 --- a/src/routes/stocks/[tickerID]/options/+layout.svelte +++ b/src/routes/stocks/[tickerID]/options/+layout.svelte @@ -11,6 +11,7 @@ const subSectionMap = { overview: "/options", "hottest-contracts": "/options/hottest-contracts", + volatility: "/options/volatility", gex: "/options/gex", dex: "/options/dex", oi: "/options/oi", @@ -31,6 +32,7 @@ const sectionMap = { overview: "overview", "hottest-contracts": "hottest-contracts", + volatility: "volatility", gex: "gex", dex: "dex", oi: "oi", @@ -79,6 +81,16 @@ > Hottest Contracts + changeSubSection("volatility")} + class="p-2 px-5 cursor-pointer {displaySubSection === + 'volatility' + ? 'text-white bg-primary sm:hover:bg-opacity-[0.95]' + : 'text-gray-400 sm:hover:text-white sm:hover:bg-primary sm:hover:bg-opacity-[0.95]'}" + > + Volatility + changeSubSection("oi")} diff --git a/src/routes/stocks/[tickerID]/options/volatility/+layout.svelte b/src/routes/stocks/[tickerID]/options/volatility/+layout.svelte new file mode 100644 index 00000000..22ee866b --- /dev/null +++ b/src/routes/stocks/[tickerID]/options/volatility/+layout.svelte @@ -0,0 +1,15 @@ +
+
+
+
+
+
+ +
+
+
+
+
+
diff --git a/src/routes/stocks/[tickerID]/options/volatility/+page.server.ts b/src/routes/stocks/[tickerID]/options/volatility/+page.server.ts new file mode 100644 index 00000000..2deabb8c --- /dev/null +++ b/src/routes/stocks/[tickerID]/options/volatility/+page.server.ts @@ -0,0 +1,31 @@ + + +export const load = async ({ locals, params }) => { + const { apiKey, apiURL, user } = locals; + + const getData = async () => { + const postData = { + ticker: params.tickerID, + }; + + const response = await fetch(apiURL + "/implied-volatility", { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-KEY": apiKey, + }, + body: JSON.stringify(postData), + }); + const output = await response.json(); + return output; + }; + + + + // Make sure to return a promise + return { + getData: await getData(), + }; +}; + + diff --git a/src/routes/stocks/[tickerID]/options/volatility/+page.svelte b/src/routes/stocks/[tickerID]/options/volatility/+page.svelte new file mode 100644 index 00000000..df37d445 --- /dev/null +++ b/src/routes/stocks/[tickerID]/options/volatility/+page.svelte @@ -0,0 +1,70 @@ + + + + + + + {$numberOfUnreadNotification > 0 ? `(${$numberOfUnreadNotification})` : ""} + {$displayCompanyName} ({$stockTicker}) Volatility · Stocknear + + + + + + + + + + + + + + + + +
+
+
+ {#if data?.getData?.length > 0} + + {:else} +
+
+ +
+
+ {/if} +
+
+