-
Notifications
You must be signed in to change notification settings - Fork 12
/
investments.js
221 lines (218 loc) · 5.89 KB
/
investments.js
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
// CREATES PERFORMANCE TOGGLE
$("#line_total").click(function() {
$("#total_performance").show();
$("#all_performance").hide();
$("#allocation").hide();
});
$("#line_individual").click(function() {
$("#total_performance").hide();
$("#all_performance").show();
$("#allocation").hide();
});
$("#pie").click(function() {
$("#total_performance").hide();
$("#all_performance").hide();
$("#allocation").show();
});
// CREATES PERFORMANCE LINE GRAPHS
$(function () {
$('#total_performance').highcharts({
chart: {
type: 'area',
backgroundColor: '#eee'
},
title: {
text: 'Total Portfolio Performance'
},
xAxis: {
categories: dates,
tickInterval: 125
},
yAxis: {
title: {
text: 'Percent Change'
}
},
tooltip: {
pointFormat: '{series.name}: <b>{point.y:,.4f}</b>'
},
credits: {
enabled: false
},
series: [{
name: 'Total',
data: total_performance
}]
});
});
$(function () {
Highcharts.setOptions({
colors: ['#7cb5ec', '#434348', '#576E7F', '#88B0BF', '#B2B2B2']
});
$('#all_performance').highcharts({
chart: {
type: 'area',
backgroundColor: '#eee'
},
title: {
text: 'Individual Fund Performance'
},
xAxis: {
categories: dates,
tickInterval: 125
},
yAxis: {
title: {
text: 'Percent Change'
}
},
tooltip: {
pointFormat: '{series.name}: <b>{point.y:,.4f}</b>'
},
credits: {
enabled: false
},
series: [{
name: prof_ticker_data[1][0],
data: ticker_query_1
}, {
name: prof_ticker_data[1][1],
data: ticker_query_2
}, {
name: prof_ticker_data[1][2],
data: ticker_query_3
}, {
name: prof_ticker_data[1][3],
data: ticker_query_4
}, {
name: prof_ticker_data[1][4],
data: ticker_query_5
}]
});
});
// CREATES ALLOCATION PIE CHART
chart_categories = Object.keys(chart_ticker_data);
chart_stock_data = chart_ticker_data["Stocks"];
chart_stock_funds = Object.keys(chart_stock_data);
chart_stock_weights = chart_stock_funds.map(function(key){
return chart_stock_data[key];
});
// Creates inner circle of total stock allocation
var chart_stock_sum = 0;
var len = chart_stock_weights.length
for(var i = 0; i < len; i++){
chart_stock_sum = chart_stock_sum + chart_stock_weights[i]
}
chart_bond_data = chart_ticker_data["Bonds"];
chart_bond_funds = Object.keys(chart_bond_data);
chart_bond_weights = chart_bond_funds.map(function(key){
return chart_bond_data[key];
});
// Creates inner circle of total bond allocation
var chart_bond_sum = 0;
var len = chart_bond_weights.length
for(var i = 0; i < len; i++){
chart_bond_sum = chart_bond_sum + chart_bond_weights[i]
}
$(function () {
var colors = Highcharts.getOptions().colors,
categories = chart_categories,
data = [{
y: chart_stock_sum,
color: colors[0],
drilldown: {
name: "Stocks Funds",
categories: chart_stock_funds,
data: chart_stock_weights,
color: colors[0]
}
}, {
y: chart_bond_sum,
color: colors[1],
drilldown: {
name: "Bonds Funds",
categories: chart_bond_funds,
data: chart_bond_weights,
color: colors[1]
}
}],
browserData = [],
versionsData = [],
i,
j,
dataLen = data.length,
drillDataLen,
brightness;
// Build the data arrays
for (i = 0; i < dataLen; i += 1) {
// add browser data
browserData.push({
name: categories[i],
y: data[i].y,
color: data[i].color
});
// add version data
drillDataLen = data[i].drilldown.data.length;
for (j = 0; j < drillDataLen; j += 1) {
brightness = 0.2 - (j / drillDataLen) / 5;
versionsData.push({
name: data[i].drilldown.categories[j],
y: data[i].drilldown.data[j],
color: Highcharts.Color(data[i].color).brighten(
brightness).get()
});
}
}
// Create the chart
$('#allocation').highcharts({
chart: {
type: 'pie',
backgroundColor: '#eee'
},
title: {
text: 'Recommended Allocation'
},
yAxis: {
title: {
text: 'Total percent allocation'
}
},
credits: {
enabled: false
},
plotOptions: {
pie: {
shadow: false,
center: ['50%', '50%']
}
},
tooltip: {
valueSuffix: '%'
},
series: [{
name: 'Category',
data: browserData,
size: '60%',
dataLabels: {
formatter: function () {
return this.y > 5 ? this.point.name : null;
},
color: 'white',
distance: -50
}
}, {
name: 'Fund',
data: versionsData,
size: '80%',
innerSize: '60%',
dataLabels: {
formatter: function () {
// display only if larger than 1
return this.y > 1 ? '<b>' + this.point.name +
':</b> ' + this.y + '%' : null;
},
distance: 10
}
}]
});
});