diff --git a/src/lib/components/BorrowedShare.svelte b/src/lib/components/BorrowedShare.svelte index 0c99f89e..84242f3c 100644 --- a/src/lib/components/BorrowedShare.svelte +++ b/src/lib/components/BorrowedShare.svelte @@ -2,7 +2,7 @@ import { borrowedShareComponent, displayCompanyName, stockTicker, assetType, etfTicker, screenWidth, userRegion, getCache, setCache} from '$lib/store'; import InfoModal from '$lib/components/InfoModal.svelte'; import { Chart } from 'svelte-echarts' - import { abbreviateNumber, formatString } from "$lib/utils"; + import { abbreviateNumber, formatDateRange } from "$lib/utils"; import Lazy from 'svelte-lazy'; export let data; @@ -30,20 +30,6 @@ let monthlyAvailableShares; let totalAvailableShares; - function formatDateRange(lastDateStr) { - // Convert lastDateStr to Date object - const lastDate = new Date(lastDateStr); - - // Set the first date to the beginning of the month of lastDate - const firstDate = new Date(lastDate.getFullYear(), lastDate.getMonth(), 1); - - // Format first and last dates - const firstDateFormatted = firstDate.toLocaleString('en-US', { month: 'short', day: 'numeric', year: 'numeric', day: '2-digit' }); - const lastDateFormatted = lastDate.toLocaleString('en-US', { month: 'short', day: 'numeric', year: 'numeric', day: '2-digit' }); - - // Construct and return the formatted date range string - return `${firstDateFormatted} - ${lastDateFormatted}`; -} function findLowestAndHighestFee(data, lastDateStr) { // Convert lastDateStr to Date object diff --git a/src/lib/components/DarkPool.svelte b/src/lib/components/DarkPool.svelte index 5534831c..257f3e15 100644 --- a/src/lib/components/DarkPool.svelte +++ b/src/lib/components/DarkPool.svelte @@ -2,7 +2,7 @@ import { darkPoolComponent, displayCompanyName, stockTicker, assetType, etfTicker, screenWidth, userRegion, getCache, setCache} from '$lib/store'; import InfoModal from '$lib/components/InfoModal.svelte'; import { Chart } from 'svelte-echarts' - import { abbreviateNumber } from "$lib/utils"; + import { abbreviateNumber, formatDateRange } from "$lib/utils"; import Lazy from 'svelte-lazy'; export let data; @@ -21,7 +21,6 @@ } }); - const monthNames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; let rawData = []; let optionsData; @@ -46,23 +45,6 @@ function normalizer(value) { } } -function formatDateRange(lastDateStr) { - // Convert lastDateStr to Date object - const lastDate = new Date(lastDateStr); - - // Set the first date to the beginning of the month of lastDate - const firstDate = new Date(lastDate.getFullYear(), lastDate.getMonth(), 1); - - // Format first and last dates - const firstDateFormatted = firstDate.toLocaleString('en-US', { month: 'short', day: 'numeric', year: 'numeric', day: '2-digit' }); - const lastDateFormatted = lastDate.toLocaleString('en-US', { month: 'short', day: 'numeric', year: 'numeric', day: '2-digit' }); - - - - // Construct and return the formatted date range string - return `${firstDateFormatted} - ${lastDateFormatted}`; -} - function findMonthlyValue(data, lastDateStr) { // Convert lastDateStr to Date object diff --git a/src/lib/components/FailToDeliver.svelte b/src/lib/components/FailToDeliver.svelte index b2dc25a7..abffb4bb 100644 --- a/src/lib/components/FailToDeliver.svelte +++ b/src/lib/components/FailToDeliver.svelte @@ -2,7 +2,7 @@ import { failToDeliverComponent, displayCompanyName, stockTicker, assetType, etfTicker, screenWidth, userRegion, getCache, setCache} from '$lib/store'; import InfoModal from '$lib/components/InfoModal.svelte'; import { Chart } from 'svelte-echarts' - import { abbreviateNumber, formatString } from "$lib/utils"; + import { abbreviateNumber, formatDateRange } from "$lib/utils"; import Lazy from 'svelte-lazy'; export let data; @@ -29,20 +29,7 @@ let highestPrice; let totalFailToDeliver; - function formatDateRange(lastDateStr) { - // Convert lastDateStr to Date object - const lastDate = new Date(lastDateStr); - - // Set the first date to the beginning of the month of lastDate - const firstDate = new Date(lastDate.getFullYear(), lastDate.getMonth(), 1); - - // Format first and last dates - const firstDateFormatted = firstDate.toLocaleString('en-US', { month: 'short', day: 'numeric', year: 'numeric', day: '2-digit' }); - const lastDateFormatted = lastDate.toLocaleString('en-US', { month: 'short', day: 'numeric', year: 'numeric', day: '2-digit' }); - - // Construct and return the formatted date range string - return `${firstDateFormatted} - ${lastDateFormatted}`; -} + function findLowestAndHighestPrice(data, lastDateStr) { // Convert lastDateStr to Date object diff --git a/src/lib/components/ImpliedVolatility.svelte b/src/lib/components/ImpliedVolatility.svelte index f27389bf..588f43dd 100644 --- a/src/lib/components/ImpliedVolatility.svelte +++ b/src/lib/components/ImpliedVolatility.svelte @@ -2,7 +2,7 @@ import { impliedVolatilityComponent, displayCompanyName, stockTicker, assetType, etfTicker, screenWidth, userRegion, getCache, setCache} from '$lib/store'; import InfoModal from '$lib/components/InfoModal.svelte'; import { Chart } from 'svelte-echarts' - import { abbreviateNumber, formatString } from "$lib/utils"; + import { formatDateRange } from "$lib/utils"; import Lazy from 'svelte-lazy'; export let data; @@ -33,20 +33,6 @@ let totalAvailableShares; - function formatDateRange(lastDateStr) { - // Convert lastDateStr to Date object - const lastDate = new Date(lastDateStr); - - // Set the first date to the beginning of the month of lastDate - const firstDate = new Date(lastDate.getFullYear(), lastDate.getMonth(), 1); - - // Format first and last dates - const firstDateFormatted = firstDate.toLocaleString('en-US', { month: 'short', day: 'numeric', year: 'numeric', day: '2-digit' }); - const lastDateFormatted = lastDate.toLocaleString('en-US', { month: 'short', day: 'numeric', year: 'numeric', day: '2-digit' }); - - // Construct and return the formatted date range string - return `${firstDateFormatted} - ${lastDateFormatted}`; -} function findLowestAndhighestIV(data, lastDateStr) { // Convert lastDateStr to Date object diff --git a/src/lib/components/MarketMaker.svelte b/src/lib/components/MarketMaker.svelte index 811b16db..819fa665 100644 --- a/src/lib/components/MarketMaker.svelte +++ b/src/lib/components/MarketMaker.svelte @@ -2,7 +2,7 @@ import { marketMakerComponent, displayCompanyName, stockTicker, assetType, etfTicker, screenWidth, userRegion, getCache, setCache} from '$lib/store'; import InfoModal from '$lib/components/InfoModal.svelte'; import { Chart } from 'svelte-echarts' - import { abbreviateNumber, formatString } from "$lib/utils"; + import { abbreviateNumber, formatString, formatDateRange } from "$lib/utils"; import Lazy from 'svelte-lazy'; export let data; @@ -32,20 +32,6 @@ let avgNotionalSum; let showFullStats = false; -function formatDateRange(lastDateStr) { - // Convert lastDateStr to Date object - const lastDate = new Date(lastDateStr); - - // Get today's date for the first date (assuming today is the last date in your original logic) - const firstDate = new Date(lastDate.getTime() - 7 * 24 * 60 * 60 * 1000); - - // Format first and last dates - const firstDateFormatted = firstDate.toLocaleString('en-US', { month: 'short', day: 'numeric', year: 'numeric', day: '2-digit' }); - const lastDateFormatted = lastDate.toLocaleString('en-US', { month: 'short', day: 'numeric', year: 'numeric', day: '2-digit' }); - - // Construct and return the formatted date range string - return `${firstDateFormatted} - ${lastDateFormatted}`; -} function normalizer(value) { if (Math?.abs(value) >= 1e18) { diff --git a/src/lib/components/RetailVolume.svelte b/src/lib/components/RetailVolume.svelte index 613dddb9..ffa6e6ad 100644 --- a/src/lib/components/RetailVolume.svelte +++ b/src/lib/components/RetailVolume.svelte @@ -3,7 +3,7 @@ import { retailVolumeComponent,displayCompanyName, stockTicker, assetType, etfTicker, screenWidth, userRegion, getCache, setCache} from '$lib/store'; import InfoModal from '$lib/components/InfoModal.svelte'; import { Chart } from 'svelte-echarts' - import { abbreviateNumber } from "$lib/utils"; + import { abbreviateNumber, formatDateRange } from "$lib/utils"; import Lazy from 'svelte-lazy'; export let data; @@ -29,6 +29,37 @@ let optionsData; let avgVolume; let avgSentiment; + let monthlyVolume; + let lowestSentiment; + let highestSentiment; + + + function findMonthlyValue(data, lastDateStr) { + // Convert lastDateStr to Date object + const lastDate = new Date(lastDateStr); + // Set the first date to the beginning of the month of lastDate + const firstDate = new Date(lastDate.getFullYear(), lastDate.getMonth(), 1); + // Filter data to include only prices within the specified month period + const filteredData = data?.filter(item => { + const currentDate = new Date(item?.date); + return currentDate >= firstDate && currentDate <= lastDate; + }); + + + // Extract prices from filtered data + monthlyVolume = filteredData?.reduce((accumulator, currentItem) => { + return accumulator + currentItem?.traded; + }, 0); + + monthlyVolume = monthlyVolume > 100e3 ? abbreviateNumber(monthlyVolume,true) : '< $100K' + + // Extract prices from filtered data + let sentiment = filteredData?.map(item => parseFloat(item?.sentiment)); + // Find the lowest and highest prices + lowestSentiment = Math.min(...sentiment)?.toFixed(0); + highestSentiment = Math.max(...sentiment)?.toFixed(0); +} + function normalizer(value) { if (Math?.abs(value) >= 1e18) { @@ -58,6 +89,9 @@ function getPlotOptions() { }); + findMonthlyValue(historyData, rawData?.lastDate) + + // Compute the average of item?.traded const totalTraded = tradingList?.reduce((acc, traded) => acc + traded, 0); avgVolume = totalTraded / tradingList?.length; @@ -285,23 +319,23 @@ $: { Date