-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomCurrencyBasket.html
286 lines (246 loc) · 9.1 KB
/
CustomCurrencyBasket.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Custom Currency Basket</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<style>
body {
font-family: 'Roboto', sans-serif;
margin: 0;
padding: 0;
background: linear-gradient(to right, #b488e4, #9cbef8);
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
color: #333;
}
header {
background-color: #4a55ab;
color: #fff;
padding: 20px;
text-align: center;
margin-bottom: 15px;
border-radius: 10px 10px 0 0;
width: 100%;
max-width: 900px;
}
h1 {
margin: 0;
font-size: 2.0em;
}
main {
background: #fff;
padding: 20px;
max-width: 900px;
width: 100%;
border-radius: 10px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
overflow: hidden;
margin: 0 15px 20px;
}
.form-row {
display: flex;
flex-direction: column;
margin-bottom: 15px;
gap: 15px;
}
.form-group {
flex: 1;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #283593;
}
select,
input {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 1em;
transition: all 0.3s;
box-sizing: border-box;
}
select:focus,
input:focus {
border-color: #4caf50;
box-shadow: 0 0 5px rgba(76, 175, 80, 0.5);
outline: none;
}
button {
background-color: #4a55ab;
color: #fff;
padding: 10px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 1em;
transition: background-color 0.3s, transform 0.2s;
width: 100%;
margin-top: 10px;
}
button:hover {
background-color: #388e3c;
transform: scale(1.05);
}
#riskIndicator {
font-size: 1.5em;
margin-top: 20px;
text-align: center;
}
#basketValueDisplay {
font-size: 1.5em;
margin-top: 10px;
text-align: center;
}
#chartContainer {
height: 400px;
margin-top: 20px;
border: 1px solid #ccc;
border-radius: 10px;
padding: 10px;
background: #f7f7f7;
}
canvas {
max-width: 100%;
height: auto;
}
@media (max-width: 600px) {
h1 {
font-size: 1.8em;
}
.form-row {
flex-direction: column;
}
button {
width: 100%;
}
}
</style>
</head>
<body>
<header>
<h1>Custom Currency Basket</h1>
</header>
<main>
<form id="basketForm">
<div class="form-row">
<label for="base_currency">Base Currency:</label>
<select id="base_currency" name="base_currency" required>
<option value="INR">INR</option>
<option value="USD">USD</option>
</select>
</div>
<div class="form-row">
<label for="usd_weight">USD Weight (%):</label>
<input type="number" id="usd_weight" name="usd_weight" step="0.01" required>
</div>
<div class="form-row">
<label for="eur_weight">EUR Weight (%):</label>
<input type="number" id="eur_weight" name="eur_weight" step="0.01" required>
</div>
<div class="form-row">
<label for="jpy_weight">JPY Weight (%):</label>
<input type="number" id="jpy_weight" name="jpy_weight" step="0.01" required>
</div>
<div class="form-row">
<label for="start_date">Start Date:</label>
<input type="date" id="start_date" name="start_date" required>
</div>
<div class="form-row">
<label for="end_date">End Date:</label>
<input type="date" id="end_date" name="end_date" required>
</div>
<button type="submit">Calculate Basket Value</button>
<button type="button" id="riskButton">Check Risk Indicator</button>
</form>
<div id="basketValueDisplay"></div>
<div id="riskIndicator"></div>
<canvas id="riskChart" width="400" height="200"></canvas>
</main>
<script>
const ctxRisk = document.getElementById('riskChart').getContext('2d');
let riskChart;
let basketValue = 0; // Initialize basket value
// Mock exchange rates for demonstration purposes
const exchangeRates = {
USD: { INR: 74, USD: 1, EUR: 0.85, JPY: 110 }, // Rates relative to USD
INR: { INR: 1, USD: 0.013, EUR: 0.011, JPY: 1.34 } // Rates relative to INR
};
// Function to calculate and display basket value
function calculateBasketValue() {
const baseCurrency = document.getElementById('base_currency').value;
const usdWeight = parseFloat(document.getElementById('usd_weight').value) / 100;
const eurWeight = parseFloat(document.getElementById('eur_weight').value) / 100;
const jpyWeight = parseFloat(document.getElementById('jpy_weight').value) / 100;
// Retrieve exchange rates based on base currency
const rates = exchangeRates[baseCurrency];
// Calculate basket value based on weights and exchange rates
basketValue = (usdWeight * rates.USD) + (eurWeight * rates.EUR) + (jpyWeight * rates.JPY);
document.getElementById('basketValueDisplay').textContent = `Basket Value: ${basketValue.toFixed(2)} ${baseCurrency}`;
}
document.getElementById('basketForm').addEventListener('submit', function(event) {
event.preventDefault(); // Prevent form submission
calculateBasketValue(); // Calculate basket value on form submission
});
document.getElementById('riskButton').addEventListener('click', function() {
const riskValues = [Math.random() * 100, Math.random() * 100, Math.random() * 100, Math.random() * 100, Math.random() * 100];
const labels = ['Day 1', 'Day 2', 'Day 3', 'Day 4', 'Day 5'];
// Update the risk indicator display
const currentRiskValue = riskValues[riskValues.length - 1];
const riskCategory = getRiskCategory(currentRiskValue);
document.getElementById('riskIndicator').textContent = `Current Risk Indicator: ${riskCategory}`;
// Update the risk chart
updateRiskChart(labels, riskValues);
});
function getRiskCategory(value) {
if (value < 33) return "Low";
else if (value < 66) return "Medium";
else return "High";
}
function updateRiskChart(labels, data) {
if (riskChart) {
riskChart.destroy(); // Destroy previous chart if it exists
}
riskChart = new Chart(ctxRisk, {
type: 'line',
data: {
labels: labels,
datasets: [{
label: 'Risk Indicator Over Time',
data: data,
borderColor: 'rgba(255, 99, 132, 1)',
backgroundColor: 'rgba(255, 99, 132, 0.2)',
borderWidth: 2,
fill: true
}]
},
options: {
responsive: true,
scales: {
x: {
title: {
display: true,
text: 'Days'
}
},
y: {
title: {
display: true,
text: 'Risk Value'
},
suggestedMin: 0,
suggestedMax: 100,
}
}
}
});
}
</script>
</body>
</html>