Calculate the daily overnight rollover cost or earnings based on interest rate differentials.
Standard Lot = 100,000 units
Long (Buy Base / Sell Quote)
Short (Sell Base / Buy Quote)
Annual rate of the currency you buy/sell
Annual rate of the secondary currency
Admin fee deducted from rate differential
Net Interest Rate Differential:0.00%
Daily Swap (Base Currency):0.00
Annualized Swap Cost/Gain:0.00
Direction:–
How is Swap Rate Calculated?
The swap rate, often referred to as the rollover rate or overnight financing rate in foreign exchange markets, is determined by the difference in interest rates between the two currencies involved in a pair. When you hold a position overnight, you effectively borrow one currency to buy another.
Understanding the calculation allows traders to estimate holding costs for long-term positions (carry trades). If the interest rate of the currency you bought is higher than the currency you sold, you may earn a positive swap (credit). Conversely, if the purchased currency has a lower rate, you pay a negative swap (debit).
The Mathematical Formula
The theoretical calculation for the daily swap rate uses the following logic:
Trade Size: The notional value of your position (e.g., 100,000 units for 1 standard lot).
Base Rate: The central bank interest rate of the first currency in the pair.
Quote Rate: The central bank interest rate of the second currency in the pair.
Markup: Fees charged by the broker for providing the leverage and overnight service.
Calculation Logic Steps
Identify the Differential: Calculate the difference between the Base Currency Rate and the Quote Currency Rate.
Adjust for Position Direction:
If Long (Buy Base/Sell Quote): You earn the Base Rate and pay the Quote Rate.
If Short (Sell Base/Buy Quote): You pay the Base Rate and earn the Quote Rate.
Apply Broker Markup: Brokers generally subtract a markup from the differential to cover their costs. This often shifts positive differentials to be smaller (or negative) and negative differentials to be larger.
Convert to Daily Value: Divide the annualized percentage result by 365 (or 360 depending on the currency convention) to find the daily cost or earnings.
Example Calculation
Imagine you are Long 1 Standard Lot (100,000 units) of USD/JPY.
USD Rate (Base): 5.50%
JPY Rate (Quote): -0.10% (hypothetical)
Broker Fee: 0.50%
Since you are Long, you earn USD rates and pay JPY rates:
It is important to note that swap rates are calculated based on the settlement date (T+2). Therefore, on Wednesdays, the swap rate is typically charged at three times the daily rate to account for the weekend holding period (Saturday and Sunday), during which markets are closed but interest still accrues.
function calculateSwap() {
// 1. Get input values
var units = document.getElementById("tradeUnits").value;
var position = document.getElementById("positionType").value;
var baseRate = document.getElementById("baseRate").value;
var quoteRate = document.getElementById("quoteRate").value;
var brokerFee = document.getElementById("brokerFee").value;
// 2. Validate inputs
if (units === "" || baseRate === "" || quoteRate === "") {
alert("Please enter values for Units and Interest Rates.");
return;
}
var unitsNum = parseFloat(units);
var baseRateNum = parseFloat(baseRate);
var quoteRateNum = parseFloat(quoteRate);
var brokerFeeNum = parseFloat(brokerFee);
if (isNaN(unitsNum) || isNaN(baseRateNum) || isNaN(quoteRateNum)) {
alert("Please enter valid numbers.");
return;
}
if (isNaN(brokerFeeNum)) {
brokerFeeNum = 0;
}
// 3. Calculation Logic
// Interest Rate Differential (Raw)
var rateDiff = 0;
// Logic:
// Long: Receive Base, Pay Quote
// Short: Pay Base, Receive Quote
if (position === "long") {
// Differential = Base – Quote
rateDiff = baseRateNum – quoteRateNum;
} else {
// Differential = Quote – Base
rateDiff = quoteRateNum – baseRateNum;
}
// Apply Broker Fee (Markup reduces profit or increases cost)
// The markup is usually subtracted from the differential regardless of direction in retail forex
// to shift the advantage to the broker.
var netDiff = rateDiff – brokerFeeNum;
// Convert percentage to decimal
var netDiffDecimal = netDiff / 100;
// Annual Calculation
var annualSwap = unitsNum * netDiffDecimal;
// Daily Calculation (using 365 days convention)
var dailySwap = annualSwap / 365;
// 4. Update UI
var resultArea = document.getElementById("resultsArea");
var resDiff = document.getElementById("resDiff");
var resDailyBase = document.getElementById("resDailyBase");
var resAnnual = document.getElementById("resAnnual");
var resDirection = document.getElementById("resDirection");
resultArea.style.display = "block";
resDiff.innerText = netDiff.toFixed(2) + "%";
// Formatting numbers with commas
resDailyBase.innerText = dailySwap.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2}) + " Units";
resAnnual.innerText = annualSwap.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2}) + " Units";
if (dailySwap > 0) {
resDirection.innerText = "Credit (You Earn)";
resDirection.style.color = "green";
resDailyBase.style.color = "green";
} else if (dailySwap < 0) {
resDirection.innerText = "Debit (You Pay)";
resDirection.style.color = "red";
resDailyBase.style.color = "red";
} else {
resDirection.innerText = "Neutral";
resDirection.style.color = "#555";
resDailyBase.style.color = "#555";
}
}