bugfixing
This commit is contained in:
parent
0c5b6b0af5
commit
7a8ca4aa10
@ -719,7 +719,6 @@
|
|||||||
|
|
||||||
function calculateMetrics() {
|
function calculateMetrics() {
|
||||||
const multiplier = 100;
|
const multiplier = 100;
|
||||||
let metrics = {};
|
|
||||||
|
|
||||||
// Get all legs in the strategy
|
// Get all legs in the strategy
|
||||||
const allLegs = [...userStrategy];
|
const allLegs = [...userStrategy];
|
||||||
@ -788,9 +787,8 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Calculate net premium for the entire strategy.
|
// Calculate net premium for the entire strategy.
|
||||||
// For each leg, buying incurs a debit and selling generates a credit.
|
|
||||||
let netPremium = 0;
|
let netPremium = 0;
|
||||||
allLegs?.forEach((leg) => {
|
allLegs.forEach((leg) => {
|
||||||
const quantity = leg.quantity || 1;
|
const quantity = leg.quantity || 1;
|
||||||
const premium = leg.optionPrice * multiplier * quantity;
|
const premium = leg.optionPrice * multiplier * quantity;
|
||||||
if (leg.action === "Buy") {
|
if (leg.action === "Buy") {
|
||||||
@ -800,21 +798,30 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (
|
// --- VERTICAL SPREAD HANDLING (UPDATED) ---
|
||||||
buyCalls.length === 1 &&
|
if (buyCalls.length === 1 && sellCalls.length === 1) {
|
||||||
sellCalls.length === 1 &&
|
const buyCall = buyCalls[0];
|
||||||
sellCalls[0].strike < buyCalls[0].strike
|
const sellCall = sellCalls[0];
|
||||||
) {
|
|
||||||
const spreadWidth =
|
const spreadWidth =
|
||||||
(buyCalls[0].strike - sellCalls[0].strike) * multiplier;
|
Math.abs(buyCall.strike - sellCall.strike) * multiplier;
|
||||||
// In a vertical spread, the max profit is the net premium (credit received)
|
|
||||||
// and the maximum loss equals the spread width minus the net premium.
|
if (buyCall.strike < sellCall.strike) {
|
||||||
const maxProfit = netPremium;
|
// Bull call spread: max loss is net debit, max profit is spread width - net debit
|
||||||
const maxLoss = spreadWidth - netPremium;
|
const maxLoss = -netPremium; // Net debit is negative, convert to positive
|
||||||
metrics = {
|
const maxProfit = spreadWidth - maxLoss;
|
||||||
maxProfit: `$${formatCurrency(maxProfit)}`,
|
metrics = {
|
||||||
maxLoss: `$${formatCurrency(maxLoss)}`,
|
maxProfit: `$${formatCurrency(maxProfit)}`,
|
||||||
};
|
maxLoss: `$${formatCurrency(maxLoss)}`,
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
// Bear call spread: max profit is net credit, max loss is spread width - net credit
|
||||||
|
const maxProfit = netPremium;
|
||||||
|
const maxLoss = spreadWidth - maxProfit;
|
||||||
|
metrics = {
|
||||||
|
maxProfit: `$${formatCurrency(maxProfit)}`,
|
||||||
|
maxLoss: `$${formatCurrency(maxLoss)}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
return metrics;
|
return metrics;
|
||||||
}
|
}
|
||||||
// --- END VERTICAL SPREAD HANDLING ---
|
// --- END VERTICAL SPREAD HANDLING ---
|
||||||
@ -1600,7 +1607,7 @@
|
|||||||
>
|
>
|
||||||
<span class="truncate">{selectedStrategy}</span>
|
<span class="truncate">{selectedStrategy}</span>
|
||||||
<svg
|
<svg
|
||||||
class="-mr-1 ml-1 h-5 w-5 xs:ml-2 inline-block"
|
class="-mr-1 ml-3 h-5 w-5 xs:ml-2 inline-block"
|
||||||
viewBox="0 0 20 20"
|
viewBox="0 0 20 20"
|
||||||
fill="currentColor"
|
fill="currentColor"
|
||||||
style="max-width:40px"
|
style="max-width:40px"
|
||||||
@ -1632,7 +1639,7 @@
|
|||||||
<span>{strategy.name}</span>
|
<span>{strategy.name}</span>
|
||||||
{#if strategy?.sentiment}
|
{#if strategy?.sentiment}
|
||||||
<span
|
<span
|
||||||
class="badge px-2 text-xs rounded-full {strategy.sentiment ===
|
class="ml-2 badge px-2 text-xs rounded-full {strategy.sentiment ===
|
||||||
'Bullish'
|
'Bullish'
|
||||||
? 'bg-green-100 text-green-800 dark:bg-green-300 dark:text-black'
|
? 'bg-green-100 text-green-800 dark:bg-green-300 dark:text-black'
|
||||||
: strategy?.sentiment === 'Bearish'
|
: strategy?.sentiment === 'Bearish'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user