From 4859b0ff5083d301d851cd9ec15be9bcb0d4ec7d Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Sun, 6 Apr 2025 14:39:22 +0200 Subject: [PATCH] update tooltip --- src/routes/analysts/analyst-flow/+page.svelte | 2 +- src/routes/options-calculator/+page.svelte | 81 +++++++++---------- 2 files changed, 39 insertions(+), 44 deletions(-) diff --git a/src/routes/analysts/analyst-flow/+page.svelte b/src/routes/analysts/analyst-flow/+page.svelte index 9169a4c1..53ca082c 100644 --- a/src/routes/analysts/analyst-flow/+page.svelte +++ b/src/routes/analysts/analyst-flow/+page.svelte @@ -190,7 +190,7 @@ > {item?.analystName} diff --git a/src/routes/options-calculator/+page.svelte b/src/routes/options-calculator/+page.svelte index 61a47cde..64d66273 100644 --- a/src/routes/options-calculator/+page.svelte +++ b/src/routes/options-calculator/+page.svelte @@ -3,7 +3,7 @@ import { Button } from "$lib/components/shadcn/button/index.js"; import SEO from "$lib/components/SEO.svelte"; import { onMount } from "svelte"; - import { buildOptionSymbol } from "$lib/utils"; + import { abbreviateNumber, buildOptionSymbol } from "$lib/utils"; import { setCache, getCache } from "$lib/store"; import { mode } from "mode-watcher"; @@ -23,6 +23,7 @@ let dateList = Object?.keys(optionData); let selectedDate = Object?.keys(optionData)[0]; let strikeList = optionData[selectedDate] || []; + let deltaList = optionData[selectedDate] || []; let selectedStrike = strikeList?.at(0) || []; let optionSymbol; @@ -92,7 +93,6 @@ // Else payoff = (underlying - strike)*100 - premium const payoff = s < strikePrice ? -premium : (s - strikePrice) * 100 - premium; - dataPoints.push([s, payoff]); } @@ -108,7 +108,8 @@ animation: false, }, title: { - text: null, + text: `

`, + useHTML: true, }, xAxis: { // numeric axis from 0 to 600 @@ -123,7 +124,7 @@ style: { color: $mode === "light" ? "#545454" : "white" }, }, plotLines: [ - // Strike Price + // Underlying Price line { value: currentStockPrice, color: "black", @@ -134,14 +135,14 @@ }, zIndex: 5, }, - // Break-Even + // Break-Even line { value: breakEven, color: "#10B981", dashStyle: "Dash", width: 1.2, label: { - text: `Breakeven $${breakEven?.toFixed(2)}`, + text: `Breakeven $${breakEven.toFixed(2)}`, }, zIndex: 5, }, @@ -157,12 +158,9 @@ labels: { style: { color: $mode === "light" ? "#545454" : "white" }, formatter: function () { - return "$" + this.value.toFixed(0); + return abbreviateNumber(this.value.toFixed(2)); }, }, - // If you want symmetrical around zero, set min/max or startOnTick/endOnTick - // startOnTick: false, - // endOnTick: false, }, tooltip: { shared: true, @@ -172,15 +170,32 @@ color: $mode === "light" ? "black" : "white", }, formatter: function () { + const underlyingPrice = this.x; + const profitLoss = this.y; + // Calculate percentage change for underlying price relative to currentStockPrice + const underlyingPctChange = + ((underlyingPrice - currentStockPrice) / currentStockPrice) * 100; + // Calculate profit/loss percentage relative to the total premium paid + const profitLossPctChange = (profitLoss / premium) * 100; + return ` - TSLA Price: $${this.x}
- P/L: $${this.y?.toLocaleString("en-US")} - `; +
+
+ Underlying Price: + $${underlyingPrice} + (${underlyingPctChange.toFixed(2)}%) +
+
+ Profit or Loss: + $${profitLoss.toLocaleString("en-US")} + (${profitLossPctChange.toFixed(2)}%) +
+
+ `; }, }, plotOptions: { area: { - // Fill the area below the line fillOpacity: 0.2, marker: { enabled: false, @@ -188,7 +203,6 @@ animation: false, }, series: { - // Zone coloring based on profit/loss zoneAxis: "y", zones: [ { @@ -334,8 +348,10 @@ {strategy.name} {#if strategy?.sentiment} {strategy.sentiment}{strategy.sentiment} {/if} @@ -402,22 +418,6 @@ > Price - - Delta - - - Adjustment - - @@ -554,16 +554,9 @@ class="border border-gray-300 rounded px-2 py-1 w-24 focus:outline-none focus:ring-1 focus:ring-blue-500" /> + + + --> + + -->