-
Notifications
You must be signed in to change notification settings - Fork 0
/
indextemplate.html
132 lines (123 loc) · 6.02 KB
/
indextemplate.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
<html>
<title>Overview of MSCI Indizes from {{indexstart}} to {{indexend}}</title>
<style>
.winner {
color: green;
}
.loser {
color: red;
}
</style>
<script src="chart.js"></script>
<body>
<h1>Overview of MSCI Indizes from {{indexstart}} to {{indexend}}</h1>
<p>Sorted by 1 year Perf/Vol Ratio</p>
<canvas id="chart_visualization"></canvas>
<table>
<tr>
<td>ID</td>
<th>Name</th>
<th>Stats. 7 Days</th>
<th>Stats. 30 Days</th>
<th>Stats. 3 Months</th>
<th>Stats. 6 Months</th>
<th>Stats. 1 Year</th>
<th>Stats. 2 Years</th>
<th>Stats. 3 Years</th>
</tr>
{{#each sorted}}
<tr>
<td><a href="{{id}}.html">{{id}}</td>
<td>{{name}} ({{currency}}/{{indexvariant}})</td>
{{#if stats_7days}}<td class="{{#if stats_7days.winner}}winner{{else}}loser{{/if}}">Perf: {{stats_7days.performance}} % / Vol: {{stats_7days.volatility}} %<br>Perf/Vol Ratio : {{stats_7days.perfvolratio}}</td>{{/if}}
{{#if stats_30days}}<td class="{{#if stats_30days.winner}}winner{{else}}loser{{/if}}">Perf: {{stats_30days.performance}} % / Vol: {{stats_30days.volatility}} %<br>Perf/Vol Ratio : {{stats_30days.perfvolratio}}</td>{{/if}}
{{#if stats_90days}}<td class="{{#if stats_90days.winner}}winner{{else}}loser{{/if}}">Perf: {{stats_90days.performance}} % / Vol: {{stats_90days.volatility}} %<br>Perf/Vol Ratio : {{stats_90days.perfvolratio}}</td>{{/if}}
{{#if stats_180days}}<td class="{{#if stats_180days.winner}}winner{{else}}loser{{/if}}">Perf: {{stats_180days.performance}} % / Vol: {{stats_180days.volatility}} %<br>Perf/Vol Ratio : {{stats_180days.perfvolratio}}</td>{{/if}}
{{#if stats_365days}}<td class="{{#if stats_365days.winner}}winner{{else}}loser{{/if}}">Perf: {{stats_365days.performance}} % / Vol: {{stats_365days.volatility}} %<br>Perf/Vol Ratio : {{stats_365days.perfvolratio}}</td>{{/if}}
{{#if stats_730days}}<td class="{{#if stats_730days.winner}}winner{{else}}loser{{/if}}">Perf: {{stats_730days.performance}} % / Vol: {{stats_730days.volatility}} %<br>Perf/Vol Ratio : {{stats_730days.perfvolratio}}</td>{{/if}}
{{#if stats_1095days}}<td class="{{#if stats_1095days.winner}}winner{{else}}loser{{/if}}">Perf: {{stats_1095days.performance}} % / Vol: {{stats_1095days.volatility}} %<br>Perf/Vol Ratio : {{stats_1095days.perfvolratio}}</td>{{/if}}
</tr>
{{/each}}
</table>
<script>
function fetchJSON(res, func) {
fetch(res, {cache: 'no-cache'}).then(function(response) {return response.json()}).then(func);
}
function ratioToRadius(r) {
const x = parseFloat(r);
if (x > 0) {
return 20 + (x * 5);
}
return 10;
}
fetchJSON('stockdata.json', function(stock) {
const referenceid = '990100';
const refstock = stock.stocks[referenceid];
const stockdataset = [
{
label: refstock.id + ' ' + refstock.name,
data: [{
x: refstock.stats_365days.volatility,
y: refstock.stats_365days.performance,
r: ratioToRadius(refstock.stats_365days.perfvolratio),
xold: refstock.stats_365days.volatility,
yold: refstock.stats_365days.performance,
}],
backgroundColor: ['#808080']
}
];
var keys = Object.keys(stock.stocks);
for (var i = 0; i < keys.length; i++) {
const key = keys[i];
if (key !== referenceid) {
const s = stock.stocks[keys[i]];
stockdataset.push({
label: s.id + ' ' + s.name,
data: [{
x: s.stats_365days.volatility,
y: s.stats_365days.performance,
r: ratioToRadius(s.stats_365days.perfvolratio),
xold: s.stats_365days.volatility,
yold: s.stats_365days.performance,
}],
});
}
}
const data = {
datasets: stockdataset,
};
const config = {
type: 'bubble',
data: data,
options: {
responsive: true,
scales: {
x: {
title: {
display: true,
text: 'Risk / Volatility'
}
},
y: {
title: {
display: true,
text: 'Return / Performance'
}
}
},
plugins: {
legend: {
display: false,
},
title: {
display: true,
text: 'Rist / Return Comparison 1 Year'
}
}
}
};
const c = new Chart(document.getElementById('chart_visualization'), config);
});
</script>
</body>
</html>