diff --git a/src/lib/components/ImpliedVolatility.svelte b/src/lib/components/ImpliedVolatility.svelte index 4fc70cf6..ac8e799f 100644 --- a/src/lib/components/ImpliedVolatility.svelte +++ b/src/lib/components/ImpliedVolatility.svelte @@ -5,23 +5,19 @@ import { formatDateRange } from "$lib/utils"; import Lazy from 'svelte-lazy'; - export let data; let isLoaded = false; - + let displayIV = 'iv60'; + let rawData = []; let optionsData; - let avgFee; let lowestIV; let highestIV; let lowestRV; let highestRV; let ivRank; - - let totalAvailableShares; - function findLowestAndhighestIV(data, lastDateStr) { // Convert lastDateStr to Date object const lastDate = new Date(lastDateStr); @@ -49,27 +45,16 @@ function findLowestAndhighestIV(data, lastDateStr) { } - function normalizer(value) { - if (Math?.abs(value) >= 1e18) { - return { unit: 'Q', denominator: 1e18 }; - } else if (Math?.abs(value) >= 1e12) { - return { unit: 'T', denominator: 1e12 }; - } else if (Math?.abs(value) >= 1e9) { - return { unit: 'B', denominator: 1e9 }; - } else if (Math?.abs(value) >= 1e6) { - return { unit: 'M', denominator: 1e6 }; - } else if (Math?.abs(value) >= 1e5) { - return { unit: 'K', denominator: 1e5 }; - } else { - return { unit: '', denominator: 1 }; - } - } - +function changeStatement(event) +{ + displayIV = event.target.value; + optionsData = getPlotOptions() +} function getPlotOptions() { let dates = []; let priceList = []; - let iv60List = []; + let ivList = []; let realizedVolatility = []; // Iterate over the data and extract required information @@ -77,7 +62,7 @@ function findLowestAndhighestIV(data, lastDateStr) { dates?.push(item?.date); priceList?.push(item?.stockpx); - iv60List?.push(item?.iv60) + ivList?.push(item[displayIV]) realizedVolatility?.push(item['60dorhv']) }); @@ -86,16 +71,10 @@ function findLowestAndhighestIV(data, lastDateStr) { findLowestAndhighestIV(rawData, rawData?.slice(-1)?.at(0)?.date) // Calculate IV Rank - const lowestIV = Math.min(...iv60List); // Find the lowest IV in the past - const highestIV = Math.max(...iv60List); // Find the highest IV in the past - ivRank = ((iv60List?.slice(-1) - lowestIV) / (highestIV - lowestIV) * 100).toFixed(2); // Compute IV Rank + const lowestIV = Math.min(...ivList); // Find the lowest IV in the past + const highestIV = Math.max(...ivList); // Find the highest IV in the past + ivRank = ((ivList?.slice(-1) - lowestIV) / (highestIV - lowestIV) * 100).toFixed(2); // Compute IV Rank - // Compute the average of item?.traded - const totalNumber = iv60List?.reduce((acc, item) => acc + item, 0); - avgFee = (totalNumber / iv60List?.length)?.toFixed(1); - totalAvailableShares = priceList?.reduce((accumulator, sum) => { - return accumulator + sum; - }, 0); const option = { @@ -104,7 +83,7 @@ function findLowestAndhighestIV(data, lastDateStr) { trigger: 'axis', hideDelay: 100, // Set the delay in milliseconds }, - animation: $screenWidth < 640 ? false: true, + animation: false, grid: { left: '0%', right: '0%', @@ -166,7 +145,7 @@ function findLowestAndhighestIV(data, lastDateStr) { }, { name: 'IV', - data: iv60List, + data: ivList, type: 'line', areaStyle: {opacity: 0.3}, stack: 'ImpliedVolatility', @@ -231,6 +210,7 @@ function findLowestAndhighestIV(data, lastDateStr) { $: { if($assetType === 'stock' ? $stockTicker : $etfTicker && typeof window !== 'undefined') { isLoaded=false; + displayIV = 'iv60'; const ticker = $assetType === 'stock' ? $stockTicker : $etfTicker const asyncFunctions = [ getImpliedVolatility(ticker) @@ -273,12 +253,27 @@ function findLowestAndhighestIV(data, lastDateStr) { {#if rawData?.length !== 0} -
+
Based on the past 12 months of historical data, {$displayCompanyName} has an IV Rank of {ivRank}%, with the current implied volatility standing at {rawData?.slice(-1)?.at(0)?.iv60}%.
+ + + +
diff --git a/src/lib/components/shadcn/Table/table.svelte b/src/lib/components/shadcn/Table/table.svelte index 92b02485..05f345b1 100644 --- a/src/lib/components/shadcn/Table/table.svelte +++ b/src/lib/components/shadcn/Table/table.svelte @@ -1,6 +1,6 @@ + + +
+ +
+
\ No newline at end of file diff --git a/src/lib/components/shadcn/select/select-item.svelte b/src/lib/components/shadcn/select/select-item.svelte new file mode 100644 index 00000000..698ca343 --- /dev/null +++ b/src/lib/components/shadcn/select/select-item.svelte @@ -0,0 +1,40 @@ + + + + + + + + + + {label || value} + + \ No newline at end of file diff --git a/src/lib/components/shadcn/select/select-label.svelte b/src/lib/components/shadcn/select/select-label.svelte new file mode 100644 index 00000000..35d8b2e5 --- /dev/null +++ b/src/lib/components/shadcn/select/select-label.svelte @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file diff --git a/src/lib/components/shadcn/select/select-separator.svelte b/src/lib/components/shadcn/select/select-separator.svelte new file mode 100644 index 00000000..69761482 --- /dev/null +++ b/src/lib/components/shadcn/select/select-separator.svelte @@ -0,0 +1,11 @@ + + + \ No newline at end of file diff --git a/src/lib/components/shadcn/select/select-trigger.svelte b/src/lib/components/shadcn/select/select-trigger.svelte new file mode 100644 index 00000000..e3c5ad64 --- /dev/null +++ b/src/lib/components/shadcn/select/select-trigger.svelte @@ -0,0 +1,27 @@ + + +span]:text-white flex h-10 w-full items-center justify-between rounded-md border border-gray-800 px-3 py-2 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1", + className + )} + {...$$restProps} + let:builder + on:click + on:keydown +> + +
+ +
+
\ No newline at end of file diff --git a/src/lib/components/shadcn/table/table-body.svelte b/src/lib/components/shadcn/table/table-body.svelte index 10ba9da5..e17a78f6 100644 --- a/src/lib/components/shadcn/table/table-body.svelte +++ b/src/lib/components/shadcn/table/table-body.svelte @@ -1,6 +1,6 @@