Explore historical exchange rates between two currencies to understand past fluctuations and trends. This calculator allows you to input a starting date and an ending date to view the exchange rate at specific points in time.
function calculateExchangeRateHistory() {
var baseCurrency = document.getElementById("baseCurrency").value.toUpperCase();
var targetCurrency = document.getElementById("targetCurrency").value.toUpperCase();
var startDate = document.getElementById("startDate").value;
var endDate = document.getElementById("endDate").value;
var resultDiv = document.getElementById("result");
if (!baseCurrency || !targetCurrency || !startDate || !endDate) {
resultDiv.innerHTML = "Please fill in all fields.";
return;
}
// **IMPORTANT**: This is a simulated API call.
// In a real-world scenario, you would integrate with a financial data API
// (e.g., Alpha Vantage, ExchangeRate-API, Open Exchange Rates)
// to fetch actual historical exchange rate data.
// For this example, we'll use hardcoded dummy data for demonstration.
var historicalRates = {
"USD_EUR": {
"2023-01-01": 0.93,
"2023-01-15": 0.92,
"2023-02-01": 0.91,
"2023-02-15": 0.90,
"2023-03-01": 0.89,
"2023-03-15": 0.88,
"2023-04-01": 0.87,
"2023-04-15": 0.86,
"2023-05-01": 0.85,
"2023-05-15": 0.84,
"2023-06-01": 0.83,
"2023-06-15": 0.82,
"2023-07-01": 0.81,
"2023-07-15": 0.80,
"2023-08-01": 0.79,
"2023-08-15": 0.78,
"2023-09-01": 0.77,
"2023-09-15": 0.76,
"2023-10-01": 0.75,
"2023-10-15": 0.74,
"2023-11-01": 0.73,
"2023-11-15": 0.72,
"2023-12-01": 0.71,
"2023-12-15": 0.70,
"2024-01-01": 0.69,
"2024-01-15": 0.68,
"2024-02-01": 0.67,
"2024-02-15": 0.66,
"2024-03-01": 0.65,
"2024-03-15": 0.64,
"2024-04-01": 0.63,
"2024-04-15": 0.62,
"2024-05-01": 0.61,
"2024-05-15": 0.60,
"2024-06-01": 0.59,
"2024-06-15": 0.58,
"2024-07-01": 0.57,
"2024-07-15": 0.56,
"2024-08-01": 0.55,
"2024-08-15": 0.54,
"2024-09-01": 0.53,
"2024-09-15": 0.52,
"2024-10-01": 0.51,
"2024-10-15": 0.50,
"2024-11-01": 0.49,
"2024-11-15": 0.48,
"2024-12-01": 0.47,
"2024-12-15": 0.46
},
"EUR_USD": {
"2023-01-01": 1.075,
"2023-01-15": 1.087,
"2023-02-01": 1.099,
"2023-02-15": 1.111,
"2023-03-01": 1.124,
"2023-03-15": 1.136,
"2023-04-01": 1.149,
"2023-04-15": 1.163,
"2023-05-01": 1.176,
"2023-05-15": 1.190,
"2023-06-01": 1.205,
"2023-06-15": 1.220,
"2023-07-01": 1.234,
"2023-07-15": 1.250,
"2023-08-01": 1.266,
"2023-08-15": 1.282,
"2023-09-01": 1.300,
"2023-09-15": 1.316,
"2023-10-01": 1.333,
"2023-10-15": 1.351,
"2023-11-01": 1.370,
"2023-11-15": 1.389,
"2023-12-01": 1.408,
"2023-12-15": 1.428,
"2024-01-01": 1.449,
"2024-01-15": 1.470,
"2024-02-01": 1.492,
"2024-02-15": 1.515,
"2024-03-01": 1.538,
"2024-03-15": 1.562,
"2024-04-01": 1.587,
"2024-04-15": 1.613,
"2024-05-01": 1.639,
"2024-05-15": 1.667,
"2024-06-01": 1.695,
"2024-06-15": 1.724,
"2024-07-01": 1.754,
"2024-07-15": 1.786,
"2024-08-01": 1.818,
"2024-08-15": 1.852,
"2024-09-01": 1.886,
"2024-09-15": 1.923,
"2024-10-01": 1.961,
"2024-10-15": 2.000,
"2024-11-01": 2.041,
"2024-11-15": 2.083,
"2024-12-01": 2.128,
"2024-12-15": 2.174
}
// Add more currency pairs and dates as needed
};
var currencyPair = baseCurrency + "_" + targetCurrency;
var ratesForPair = historicalRates[currencyPair];
if (!ratesForPair) {
resultDiv.innerHTML = "Historical data not available for " + baseCurrency + " to " + targetCurrency + ".";
return;
}
var outputHTML = "
";
var dates = Object.keys(ratesForPair).sort(); // Sort dates chronologically
var foundData = false;
for (var i = 0; i = startDate && date <= endDate) {
var rate = ratesForPair[date];
outputHTML += "