Exchange Rate Calculator History

Exchange Rate History Calculator

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 = "

Historical Exchange Rates: " + baseCurrency + " to " + targetCurrency + "

"; outputHTML += "(Note: This data is simulated for demonstration purposes.)"; outputHTML += ""; 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 += ""; foundData = true; } } if (!foundData) { outputHTML += ""; } outputHTML += "
DateRate (1 " + baseCurrency + " = ? " + targetCurrency + ")
" + date + "" + rate + "
No historical data found within the selected date range.
"; resultDiv.innerHTML = outputHTML; } .calculator-container { font-family: Arial, sans-serif; border: 1px solid #ccc; padding: 20px; border-radius: 8px; max-width: 600px; margin: 20px auto; background-color: #f9f9f9; } .calculator-container h2 { text-align: center; color: #333; margin-bottom: 20px; } .calculator-container p { text-align: center; color: #555; line-height: 1.6; } .input-section { display: grid; grid-template-columns: 1fr 2fr; gap: 15px; align-items: center; margin-top: 20px; } .input-section label { font-weight: bold; color: #444; } .input-section input[type="text"], .input-section input[type="date"] { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; } .input-section button { grid-column: 1 / -1; padding: 12px 20px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; transition: background-color 0.3s ease; } .input-section button:hover { background-color: #0056b3; } #result { margin-top: 25px; padding: 15px; border: 1px solid #eee; border-radius: 4px; background-color: #fff; text-align: center; } #result h3 { color: #007bff; margin-bottom: 10px; } #result table { margin-left: auto; margin-right: auto; border-collapse: collapse; } #result th, #result td { padding: 8px 12px; text-align: left; } #result th { background-color: #e9ecef; color: #333; }

Leave a Comment