Carry Trade Profitability Calculator

Trade Setup
Market Conditions & Holding Period

Interest Component: Earned ${totalInterestInBaseCcy.toFixed(2)} ${baseCcy}. Converted to ${accountCcy} at ${baseToAcctRate.toFixed(5)} (${baseCcy}/${accountCcy}).

Currency Fluctuation: Pair moved ${pipsMoved.toFixed(1)} pips. Each pip worth ${pipValueInAcctCcy.toFixed(2)} ${accountCcy}.

`; resultsContainer.style.display = 'block'; }); function displayValue(element, value, currency, isTotal = false) { const formattedValue = value.toFixed(2); element.textContent = `${formattedValue} ${currency}`; element.className = 'ctpc-value'; // Reset if (value >= 0) { element.classList.add('ctpc-profit'); } else { element.classList.add('ctpc-loss'); } if (isTotal) { // Extra class for total to apply background in CSS if needed if (value >= 0) totalPlEl.classList.add('ctpc-profit'); else totalPlEl.classList.add('ctpc-loss'); } } downloadPdfBtn.addEventListener('click', function() { if (resultsContainer.style.display === 'none') { alert("Please calculate profitability first."); return; } const pair = pairSelect.value; const accountCcy = accountCurrencySelect.value; const pdfContainer = document.createElement('div'); pdfContainer.style.padding = '20px'; pdfContainer.style.fontFamily = 'Arial, sans-serif'; pdfContainer.style.fontSize = '12px'; pdfContainer.innerHTML = `

Carry Trade Profitability Report

Inputs:

Currency Pair: ${pair}

Base Currency (${pair.substring(0,3)}) Interest Rate: ${baseRateInput.value}% p.a.

Quote Currency (${pair.substring(4,7)}) Interest Rate: ${quoteRateInput.value}% p.a.

Trade Size: ${parseFloat(tradeSizeInput.value).toLocaleString()} units of ${pair.substring(0,3)}

Account Currency: ${accountCcy}

Entry Exchange Rate: ${entryRateInput.value}

Expected Exit Exchange Rate: ${exitRateInput.value}

Holding Period: ${holdingPeriodValueInput.value} ${holdingPeriodUnitSelect.value}


Conversion Rates Used (to ${accountCcy}):

${pair.substring(0,3)}/${accountCcy}: ${baseToAcctRateGroup.style.display !== 'none' && !isNaN(parseFloat(baseToAcctRateInput.value)) ? parseFloat(baseToAcctRateInput.value).toFixed(5) : (pair.substring(0,3) === accountCcy ? '1.00000 (N/A)' : 'Error/Not Set')}

${pair.substring(4,7)}/${accountCcy}: ${quoteToAcctRateGroup.style.display !== 'none' && !isNaN(parseFloat(quoteToAcctRateInput.value)) ? parseFloat(quoteToAcctRateInput.value).toFixed(5) : (pair.substring(4,7) === accountCcy ? '1.00000 (N/A)' : 'Error/Not Set')}


Profitability Breakdown (${accountCcy}):

Interest Rate Differential P/L: ${interestPlEl.textContent}

Exchange Rate Fluctuation P/L: ${exchangeRatePlEl.textContent}

Total Estimated P/L: ${totalPlEl.textContent}

${resultDetailsEl.innerHTML}
`; // Style profit/loss in PDF pdfContainer.querySelectorAll('.ctpc-profit').forEach(el => el.style.color = '#27ae60'); pdfContainer.querySelectorAll('.ctpc-loss').forEach(el => el.style.color = '#c0392b'); const opt = { margin: 15, filename: `CarryTrade_Report_${pair.replace('/', '-')}.pdf`, image: { type: 'jpeg', quality: 0.98 }, html2canvas: { scale: 2, useCORS: true, letterRendering: true }, jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' } }; if (typeof html2pdf !== 'undefined') { html2pdf().from(pdfContainer).set(opt).save(); } else { alert('Error: PDF generation library (html2pdf.js) is not loaded.'); } }); });
Scroll to Top