-
Notifications
You must be signed in to change notification settings - Fork 0
/
CCAR_analytics.js
1872 lines (1567 loc) · 68.7 KB
/
CCAR_analytics.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
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var parseDate = d3.timeParse("%Y-%m-%d");
const ind_chart_ht = 500;
const ind_chart_wd = 500;
var margin = {top: 50, right: 50, bottom: 50, left: 100};
var width = 1880;
var height = 750;
var firstMacroLeft = 800;
var small_chart_ht = 150;
//---------COLORS-----------
var color_peers = ['#000000','#fffb00','#ff00ff','#1900ff'];
var color_scens = ['#106331', '#ed0000'];
var svg0 = d3.select("#container0").append("svg")
.attr('class','tempsvh')
.attr("height",100)
.attr("width", width);
svg0.append('rect')
.attr('x', 0)
.attr('y', 0)
.attr('width', width)
.attr('height', 90)
.attr('fill', '#054b23');
svg0.append("text")
.attr("font-size", "20px")
.attr("font-family", "Helvetica")
.attr('font-weight', 'bold')
.text('Credit Risk')
.attr("fill", "#ffffff")
.attr("transform", "translate("+30+","+35+")")
.attr("class", "left_header1");
svg0.append("text")
.attr("font-size", "20px")
.attr("font-family", "Helvetica")
.attr('font-weight', 'bold')
.text('Sample Data')
.attr("fill", "#ffffff")
.attr("transform", "translate("+20+","+65+")")
.attr("class", "left_header2");
svg0.append("text")
.attr("font-size", "40px")
.attr("font-family", "Helvetica")
.attr('font-weight', 'bold')
.text('CCAR - Credit Loss Analytics')
.attr("fill", "#ffffff")
.attr("transform", "translate("+600+","+45+")")
.attr("class", "center_header1");
svg0.append("text")
.attr("font-size", "20px")
.attr("font-family", "Helvetica")
.attr('font-weight', 'bold')
.text('Past - Present - Future')
.attr("fill", "#ffffff")
.attr("transform", "translate("+750+","+75+")")
.attr("class", "center_header2");
var logo_img = svg0.append("svg:image")
.attr("xlink:href", "lib/Dash_Logo.png")
.attr("width", 85)
.attr("height", 85)
.attr("x", width-90)
.attr("y",3);
svg0.append("text")
.attr("font-size", "14px")
.attr("font-family", "Helvetica")
.attr('font-weight', 'bold')
.text('Home')
.attr("fill", "#ffffff")
.attr("transform", "translate("+220+","+77+")")
.attr("class", "nav_btn_txt");
svg0.append("a")
.attr("xlink:href", "CCAR_analytics.html")
.append("rect")
.attr("x", 200)
.attr("y", 60)
.attr("height", 25)
.attr("width", 75)
.style("opacity", 0.2)
.style("fill", "lightgreen");
svg0.append("text")
.attr("font-size", "14px")
.attr("font-family", "Helvetica")
.attr('font-weight', 'bold')
.text('About')
.attr("fill", "#ffffff")
.attr("transform", "translate("+320+","+77+")")
.attr("class", "nav_btn_txt");
svg0.append("a")
.attr("xlink:href", "About.html")
.append("rect")
.attr("x", 300)
.attr("y", 60)
.attr("height", 25)
.attr("width", 75)
.style("opacity", 0.2)
.style("fill", "lightgreen");
//------SETTING SVG----------
var svg = d3.select("body").append("svg")
.attr('class','all_charts')
.attr("height",height)
.attr("width", width);
// ----COMMENTS SECTION-----
svg.append("text")
.text('Instructions:')
.attr("transform", "translate("+605+","+70+")")
.attr("fill", "#0c4714")
.attr("class", "comment1");
svg.append("text")
.text('- Select your Bank of interest.')
.attr("transform", "translate("+605+","+90+")")
.attr("class", "comment2");
svg.append("text")
.text('- Select your Portfolio of interest.')
.attr("transform", "translate("+605+","+110+")")
.attr("class", "comment2");
svg.append("text")
.text('- All graphs update accordingly.')
.attr("transform", "translate("+605+","+130+")")
.attr("class", "comment2");
svg.append("text")
.text('- Map shows location of selected Bank ')
.attr("transform", "translate("+605+","+150+")")
.attr("class", "comment2");
svg.append("text")
.text('\u00A0\u00A0and its peers for a selected portfolio.')
.attr("transform", "translate("+607+","+165+")")
.attr("class", "comment2");
svg.append("text")
.text('Number of Banks:')
.attr("transform", "translate("+605+","+210+")")
.attr("fill", "#0c4714")
.attr("class", "comment1");
svg.append("text")
.text('Over 400')
.attr("transform", "translate("+735+","+210+")")
.attr("class", "comment2");
svg.append("text")
.text('Number of Portfolios:')
.attr("transform", "translate("+605+","+230+")")
.attr("fill", "#0c4714")
.attr("class", "comment1");
svg.append("text")
.text('Over 1600')
.attr("transform", "translate("+760+","+230+")")
.attr("class", "comment2");
svg.append("text")
.text('Models Used:')
.attr("transform", "translate("+605+","+600+")")
.attr("fill", "#0c4714")
.attr("class", "comment1");
svg.append("text")
.text('- KNN to find Peers.')
.attr("transform", "translate("+605+","+620+")")
.attr("class", "comment2");
svg.append("text")
.text('- Exp. Smoothing to forecast balances.')
.attr("transform", "translate("+605+","+635+")")
.attr("class", "comment2");
svg.append("text")
.text('- Regressions to forecast losses.')
.attr("transform", "translate("+605+","+650+")")
.attr("class", "comment2");
svg.append("text")
.text('Main Data Sources:')
.attr("transform", "translate("+605+","+700+")")
.attr("fill", "#0c4714")
.attr("class", "comment1");
svg.append("text")
.text('- FFIEC for historical data')
.attr("transform", "translate("+605+","+720+")")
.attr("class", "comment2");
svg.append("text")
.text('- CCAR site for scenarios')
.attr("transform", "translate("+605+","+735+")")
.attr("class", "comment2");
svg.append("a")
.attr("xlink:href", "https://cdr.ffiec.gov/public/ManageFacsimiles.aspx")
.append("rect")
.attr("x", 608)
.attr("y", 710)
.attr("height", 10)
.attr("width", 32)
.style("opacity", 0.2)
.style("fill", "lightgreen");
svg.append("a")
.attr("xlink:href", "https://www.federalreserve.gov/supervisionreg/ccar.htm")
.append("rect")
.attr("x", 608)
.attr("y", 725)
.attr("height", 10)
.attr("width", 32)
.style("opacity", 0.2)
.style("fill", "lightgreen");
// -------------------------------------------------------------------------------|
var path = d3.geoPath();
var bank_info_map = d3.map();
var bank_info_map2 = d3.map();
// LINE IDs
let id = 0;
const ids = function () {
return "line-"+id++;
}
Promise.all([
d3.dsv(",", "datasets/forecast_results.csv", function(d){
return{
date: parseDate(d.date),
rssd_id: +d.rssd_id,
product: d.product,
chg_b: +d.chg_b,
chg_s: +d.chg_s,
rolling9q_b: +d.rolling9q_b,
rolling9q_s: +d.rolling9q_s
}
}),
d3.dsv(",", "datasets/bank_names_full.csv", function(d){
return{
rssd_id: d.rssd_id,
banks: d.banks,
city: d.city,
state: d.state,
book: d.book,
losses: d.losses
}
}),
d3.dsv(",", "datasets/hist_data_rolling_9q_loss_rates_with_peers.csv", function(d){
return{
date: parseDate(d.date),
rssd_id: +d.rssd_id,
product: d.product,
bank0: +d.bank0,
bank1: +d.bank1,
bank2: +d.bank2,
bank3: +d.bank3
}
}),
d3.dsv(",", "datasets/macro_variables_projections.csv", function(d){
return{
date: parseDate(d.Date),
UR_B: +d.UR_B,
DJI_B: +d.DJI_B,
HPI_B: +d.HPI_B,
UR_S: +d.UR_S,
DJI_S: +d.DJI_S,
HPI_S: +d.HPI_S
}
}),
d3.dsv(",", "datasets/forecast_with_peers.csv", function(d){
return{
date: parseDate(d.date),
rssd_id: +d.rssd_id,
product: d.product,
bank0_b: +d.bank0_b,
bank0_s: +d.bank0_s,
bank1_b: +d.bank1_b,
bank1_s: +d.bank1_s,
bank2_b: +d.bank2_b,
bank2_s: +d.bank2_s,
bank3_b: +d.bank3_b,
bank3_s: +d.bank3_s
}
}),
d3.json('datasets/USA_3_1.json'),
d3.dsv(",", "datasets/ccar_peers_geo_data.csv", function(d){
return{
rssd_id: +d.rssd_id,
portfolio: d.portfolio,
peer: d.Peer,
state: d.state,
present: +d.present,
peer_rssd_id: +d.peer_rssd_id,
assets: +d.Assets,
color: d.color,
size: +d.Size,
loc_x: +d.loc_x,
loc_y: +d.loc_y,
name: d.name
}
})
]).then(function(values){
var forecastData = values[0];
var unq_banks_info = values[1];
var historicalData = values[2];
var forecastMacros = values[3];
var forecastDataFull = values[4];
var coords_data = values[5].features;
var peer_state = values[6];
// ready(error, world, values[0]);
ready(unq_banks_info, forecastData, historicalData, forecastMacros, forecastDataFull, coords_data, peer_state);
});
function ready(bank_attr_data, fcast_data, hist_data, fcast_macro, fcast_data_full, usa, peer_loc) {
// max , min vals
var hist_date_extent = d3.extent(hist_data, function(d){return d.date;});
// enter code to extract all unique rssd_ids from fcast_data
var flags = [], unq_rssd = [], l = bank_attr_data.length, i;
for( var i=0; i<l; i++) {
if( flags[bank_attr_data[i].rssd_id]) continue;
flags[bank_attr_data[i].rssd_id] = true;
unq_rssd.push(bank_attr_data[i].rssd_id);
};
unq_rssd = unq_rssd.sort();
// enter code to extract all unique bank names from fcast_data
var flags2 = [], unq_banks = [], l = bank_attr_data.length, i;
for( var i=0; i<l; i++) {
if( flags2[bank_attr_data[i].banks]) continue;
flags2[bank_attr_data[i].rssd_id] = true;
unq_banks.push(bank_attr_data[i].banks);
};
unq_banks = unq_banks.sort();
// enter code to extract all unique RSSD IDs from forecastData
var flags2 = [], unq_prods = [], l = fcast_data.length, i;
for( var i=0; i<l; i++) {
if( flags2[fcast_data[i].product]) continue;
flags2[fcast_data[i].product] = true;
unq_prods.push(fcast_data[i].product);
};
unq_prods = unq_prods.sort();
//----------------------------------------------------------
//-----------------MAPPING BANK NAMES TO RSSD---------------
for (var k=0; k<bank_attr_data.length;k++){
bank_info_map.set(bank_attr_data[k].banks, +bank_attr_data[k].rssd_id);
};
for (var k=0; k<bank_attr_data.length;k++){
bank_info_map2.set(+bank_attr_data[k].rssd_id, bank_attr_data[k].banks);
};
//-------------------------------------------
// DROPDOWN FOR BANKS
var new_bank = bank_attr_data[0].banks;
var new_prod = "Credit Cards";
// enter code to append the rssd_id options to the dropdown
var dropdown_banks_Change = function() {
new_bank = d3.select(this).property('value')
h_remover();
r_remover();
p_remover();
c_remover();
// createMapAndLegend(world, fcast_data, new_bank, unq_prods);
createHistLossRateChart(hist_data, new_bank, hist_date_extent, peer_loc, new_prod);
createUSMap(new_bank, usa, peer_loc, new_prod);
createBankResultChart(new_bank,firstResultsLeft,fcast_date_extent,small_chart_ht,fcast_data,firstResultsTop, secondResultsLeft, secondResultsTop, new_prod);
createPeerResultChart(new_bank, firstPeerLeft, fcast_date_extent, small_chart_ht, fcast_data_full, firstPeerTop, secondPeerLeft, secondPeerTop, new_prod);
};
const padd1 = d3.select("#container")
.append("text")
.text('\u00A0\u00A0\u00A0\u00A0\u00A0')
.attr("class", "pad1");
const text_1 = d3.select("#container")
.append("text")
.text("Select Bank: ")
.attr("class", "text_dd_1");
var dropdown_banks = d3.select("#container")
.insert("select", "svg")
.attr('class','banks_dropdown');
// event listener for the dropdown_banks. Update choropleth and legend when selection changes. Call createMapAndLegend() with required arguments.
dropdown_banks.on("change", dropdown_banks_Change);
dropdown_banks.selectAll("option")
.attr("class","bank_dd")
.data(unq_banks)
.enter().append("option")
.attr("value", function (d) { return d; })
.text(function (d) {
return d;
});
//--------------------------------------------------------
// DROPDOWN FOR PRODUCTS
// enter code to append the rssd_id options to the dropdown
var dropdown_prod_Change = function() {
new_prod = d3.select(this).property('value')
h_remover();
r_remover();
p_remover();
c_remover();
createHistLossRateChart(hist_data, new_bank, hist_date_extent, peer_loc, new_prod);
createUSMap(new_bank, usa, peer_loc, new_prod);
createBankResultChart(new_bank,firstResultsLeft,fcast_date_extent,small_chart_ht,fcast_data,firstResultsTop, secondResultsLeft, secondResultsTop, new_prod);
createPeerResultChart(new_bank, firstPeerLeft, fcast_date_extent, small_chart_ht, fcast_data_full, firstPeerTop, secondPeerLeft, secondPeerTop, new_prod);
};
const padd2 = d3.select("#container")
.append("text")
.text('\u00A0\u00A0\u00A0\u00A0\u00A0')
.attr("class", "pad2");
const text_2 = d3.select("#container")
.append("text")
.text("Select Product: ")
.attr("class", "text_dd_2");
var dropdown_prod = d3.select("#container")
.insert("select", "svg")
.attr('class','prod_dropdown');
// event listener for the dropdown_prod. Update choropleth and legend when selection changes. Call createMapAndLegend() with required arguments.
dropdown_prod.on("change", dropdown_prod_Change);
dropdown_prod.selectAll("option")
.data(unq_prods)
.enter().append("option")
.attr("value", function (d) { return d; })
.text(function (d) {
return d;
});
//---------------HISTORICAL CHART-----------------------|
//---------------------CHART 1--------------------------|
// Settign title of the chart
svg.append("text")
.attr("transform", "translate("+160+","+50+")")
.attr("font-size", "18px")
.attr("font-family", "Helvetica")
.attr('font-weight', 'bold')
.text("Historical 9Q Rolling Loss Rates (bps)")
// Add the text label for Y axis
svg.append("text")
.attr('id','y_axis_label1')
.attr("text-anchor", "end")
.attr("transform", "rotate(-90)")
.attr("font-size", "12px")
.attr("font-family", "Helvetica")
.attr("x", -150)
.attr("y", -margin.left+150)
.text("Loss Rate (bps)");
// default - shows first bank in list
createHistLossRateChart(hist_data, new_bank, hist_date_extent, peer_loc, new_prod);
//---------------------------LEGEND-----------------------|
svg.append('circle')
.attr('class','peer_legend')
.attr("cx", "85")
.attr("cy", "385")
.attr("r", "5")
.attr("fill", color_peers[0]);
svg.append('circle')
.attr('class','scen_legend')
.attr("cx", "210")
.attr("cy", "385")
.attr("r", "5")
.attr("fill", color_peers[1]);
svg.append('circle')
.attr('class','scen_legend')
.attr("cx", "335")
.attr("cy", "385")
.attr("r", "5")
.attr("fill", color_peers[2]);
svg.append('circle')
.attr('class','scen_legend')
.attr("cx", "460")
.attr("cy", "385")
.attr("r", "5")
.attr("fill", color_peers[3]);
//------------------------------------------------------|
//-------------------CHOROPLETH-------------------------|
//------------------------------------------------------|
// default - shows first bank in list
createUSMap(bank_attr_data[0].banks, usa, peer_loc, new_prod);
//------------------MACRO CHARTS------------------------|
svg.append("text")
.attr("transform", "translate("+(1200)+","+10+")")
.attr("font-size", "14px")
.attr("font-family", "Helvetica")
.attr("fill", "#0c4714")
.attr('font-weight', 'bold')
.text("Macroeconomic Variables from CCAR")
var slices = fcast_macro.columns.slice(1).map(function(id){
return {
id: id.split("_")[1],
values: fcast_macro.map(function(d){
if (id.split("_")[0] == 'UR') {
return {date: d.date,
UR: +d[id]}
}
else if (id.split("_")[0] == 'DJI') {
return {date: d.date,
DJI: +d[id]}
}
else{
return {date: d.date,
HPI: +d[id]}
}
})
};
});
final_macro_fcast = []
var colm_id = 0;
for (var a1 =0; a1<slices.length; a1+=3){
let da = []
for (var a2 =0; a2<slices[colm_id].values.length; a2++){
da[a2] = {
...slices[a1].values[a2],
...slices[a1+1].values[a2],
...slices[a1+2].values[a2]
};
}
temp = {
id: slices[a1].id,
values: da
}
final_macro_fcast[colm_id] = temp
colm_id++;
}
//---------------------------LEGEND-----------------------|
svg.append('circle')
.attr('class','scen_legend1')
.attr("cx", "1600")
.attr("cy", "5")
.attr("r", "5")
.attr("fill", color_scens[0]);
svg.append('circle')
.attr('class','scen_legend')
.attr("cx", "1600")
.attr("cy", "20")
.attr("r", "5")
.attr("fill", color_scens[1]);
svg.append("text")
.attr("transform", "translate("+(1610)+","+10+")")
.attr("font-size", "12px")
.attr("font-family", "Helvetica")
.attr("fill", "#0c4714")
.attr('font-weight', 'bold')
.text("Base Scenario")
svg.append("text")
.attr("transform", "translate("+(1610)+","+25+")")
.attr("font-size", "12px")
.attr("font-family", "Helvetica")
.attr("fill", "#0c4714")
.attr('font-weight', 'bold')
.text("Severe Scenario")
//--------------------------------------------------------|
for (var j = 0; j < final_macro_fcast.length; j++) {
final_macro_fcast[j]['color'] = color_scens[j];
}
// max , min vals
var fcast_date_extent = d3.extent(fcast_macro, function(d){return d.date;});
var ur_max = d3.max(final_macro_fcast, function(c){
return d3.max(c.values, function(d){
return d.UR;});
});
var dji_max = d3.max(final_macro_fcast, function(c){
return d3.max(c.values, function(d){
return d.DJI;});
});
var hpi_max = d3.max(final_macro_fcast, function(c){
return d3.max(c.values, function(d){
return d.HPI;});
});
//---------------------CHART 2--------------------------|
//---------------------SCALES---------------------------|
var xScale2 = d3.scaleTime()
.domain(fcast_date_extent)
.range([firstMacroLeft, firstMacroLeft+250]);
var yScale2 = d3.scaleLinear()
.domain([0, ur_max])
.range([small_chart_ht+30, 30]);
// //-----------------------AXES---------------------------|
const yaxis2 = d3.axisLeft()
.scale(yScale2);
const xaxis2 = d3.axisBottom()
.ticks(d3.timeMonth.every(6))
.tickFormat(d3.timeFormat("%b %y"))
.scale(xScale2);
// creating a line generator - it generates x-y coords
var line_gen2 = d3.line()
.x(function(d) {return xScale2(d.date); }) // set the x values for the line generator
.y(function(d) {return yScale2(d.UR); }); // set the y values for the line generator
var chartGroup_2 = svg.append("g")
.attr("transform", "translate(" + margin.left + "," + (margin.top -10)+ ")");
// Settign title of the chart
chartGroup_2.append("text")
.attr("transform", "translate("+(firstMacroLeft+50)+","+15+")")
.attr("font-size", "12px")
.attr("font-family", "Helvetica")
.attr('font-weight', 'bold')
.text("US Unemployment Rate %")
// Add the X Axis
chartGroup_2.append("g")
.attr("class", "x axis2")
.attr("transform", "translate(0," + (small_chart_ht+30) + ")")
.call(xaxis2);
// Add the Y Axis
chartGroup_2.append("g")
.attr("class", "y axis 2")
.attr("transform", "translate(" + firstMacroLeft + ",0)")
.call(yaxis2);
// Add Lines
const lines_chart2 = chartGroup_2.selectAll("lines")
.data(final_macro_fcast)
.enter().append("g")
lines_chart2.append("path")
.attr("class",ids)
.attr("d",function(d){
return line_gen2(d.values);
})
.attr('stroke', function(d) {
return d.color;
})
.attr('fill','None')
.attr('stroke-width',2);
//-----CIRCLES
const circle_chart2 = chartGroup_2.selectAll(".e1_dot")
.data(final_macro_fcast)
.enter().append("g")
.attr('fill',function(d){
return d.color;
});
function e1_MouseOver(dd) {
var r = d3.select(this).attr('r', 10);
svg.append("text")
.attr('x', function() { return xScale2(dd.date) + 75; })
.attr('y', function() { return yScale2(dd.UR) + 75; })
.attr('id', 'e1_tooltip')
.text('Unemp: '+ Math.round(dd.UR*100)/100 + "%");
};
function e1_MouseOut(dd) {
var r = d3.select(this).attr('r',5);
d3.selectAll("#e1_tooltip").remove();
};
circle_chart2.append('g').selectAll("circle")
.data(function(d){
return d.values;
})
.enter().append("circle")
.attr("class", "e1_dot")
.attr("r", function(dd){
if ([5,11].indexOf(dd.date.getMonth())>=0){
return 5;}
})
.attr("cx", function(dd) {
return xScale2(dd.date); })
.attr("cy", function(dd) {
return yScale2(dd.UR);})
.on("mouseover",e1_MouseOver)
.on("mouseout",e1_MouseOut);
//---------------------CHART 3--------------------------|
var secondMacroLeft = firstMacroLeft + 350;
//---------------------SCALES---------------------------|
var xScale3 = d3.scaleTime()
.domain(fcast_date_extent)
.range([secondMacroLeft, secondMacroLeft+250]);
var yScale3 = d3.scaleLinear()
.domain([0, dji_max])
.range([small_chart_ht+30, 30]);
// //-----------------------AXES---------------------------|
const yaxis3 = d3.axisLeft()
.scale(yScale3);
const xaxis3 = d3.axisBottom()
.ticks(d3.timeMonth.every(6))
.tickFormat(d3.timeFormat("%b %y"))
.scale(xScale3);
// creating a line generator - it generates x-y coords
var line_gen3 = d3.line()
.x(function(d) {return xScale3(d.date); }) // set the x values for the line generator
.y(function(d) {return yScale3(d.DJI); }); // set the y values for the line generator
var chartGroup_3 = svg.append("g")
.attr("transform", "translate(" + margin.left + "," + (margin.top -10) + ")");
// Settign title of the chart
chartGroup_3.append("text")
.attr("transform", "translate("+(secondMacroLeft+50)+","+15+")")
.attr("font-size", "12px")
.attr("font-family", "Helvetica")
.attr('font-weight', 'bold')
.text("Stock Market - Dow Jones Index")
// Add the X Axis
chartGroup_3.append("g")
.attr("class", "x axis3")
.attr("transform", "translate(0," + (small_chart_ht+30) + ")")
.call(xaxis3);
// Add the Y Axis
chartGroup_3.append("g")
.attr("class", "y axis 3")
.attr("transform", "translate("+secondMacroLeft+",0)")
.call(yaxis3);
// Add Lines
const lines_chart3 = chartGroup_3.selectAll("lines")
.data(final_macro_fcast)
.enter().append("g")
lines_chart3.append("path")
.attr("class",ids)
.attr("d",function(d){
return line_gen3(d.values);
})
.attr('stroke', function(d) {
return d.color;
})
.attr('fill','None')
.attr('stroke-width',2);
//-----CIRCLES
const circle_chart3 = chartGroup_3.selectAll(".e2_dot")
.data(final_macro_fcast)
.enter().append("g")
.attr('fill',function(d){
return d.color;
});
function e2_MouseOver(dd) {
var r = d3.select(this).attr('r', 10);
svg.append("text")
.attr('x', function() { return xScale3(dd.date) + 75; })
.attr('y', function() { return yScale3(dd.DJI) + 75; })
.attr('id', 'e2_tooltip')
.text('Dow Jones: '+ Math.round(dd.DJI).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","));
};
function e2_MouseOut(dd) {
var r = d3.select(this).attr('r',5);
d3.selectAll("#e2_tooltip").remove();
};
circle_chart3.append('g').selectAll("circle")
.data(function(d){
return d.values;
})
.enter().append("circle")
.attr("class", "e2_dot")
.attr("r", function(dd){
if ([5,11].indexOf(dd.date.getMonth())>=0){
return 5;}
})
.attr("cx", function(dd) {
return xScale3(dd.date); })
.attr("cy", function(dd) {
return yScale3(dd.DJI);})
.on("mouseover",e2_MouseOver)
.on("mouseout",e2_MouseOut);
//---------------------CHART 4--------------------------|
var thirdMacroLeft = secondMacroLeft + 350;
//---------------------SCALES---------------------------|
var xScale4 = d3.scaleTime()
.domain(fcast_date_extent)
.range([thirdMacroLeft, thirdMacroLeft+250]);
var yScale4 = d3.scaleLinear()
.domain([0, hpi_max])
.range([small_chart_ht+30, 30]);
//-----------------------AXES---------------------------|
const yaxis4 = d3.axisLeft()
.scale(yScale4);
const xaxis4 = d3.axisBottom()
.ticks(d3.timeMonth.every(6))
.tickFormat(d3.timeFormat("%b %y"))
.scale(xScale4);
// creating a line generator - it generates x-y coords
var line_gen4 = d3.line()
.x(function(d) {return xScale4(d.date); }) // set the x values for the line generator
.y(function(d) {return yScale4(d.HPI); }); // set the y values for the line generator
var chartGroup_4 = svg.append("g")
.attr("transform", "translate(" + margin.left + "," + (margin.top -10) + ")");
// Settign title of the chart
chartGroup_4.append("text")
.attr("transform", "translate("+(thirdMacroLeft+47)+","+15+")")
.attr("font-size", "12px")
.attr("font-family", "Helvetica")
.attr('font-weight', 'bold')
.text("US House Price Index (HPI)")
// Add the X Axis
chartGroup_4.append("g")
.attr("class", "x axis4")
.attr("transform", "translate(0," + (small_chart_ht+30) + ")")
.call(xaxis4);
// Add the Y Axis
chartGroup_4.append("g")
.attr("class", "y axis 4")
.attr("transform", "translate("+thirdMacroLeft+",0)")
.call(yaxis4);
// Add Lines
const lines_chart4 = chartGroup_4.selectAll("lines")
.data(final_macro_fcast)
.enter().append("g")
lines_chart4.append("path")
.attr("class",ids)
.attr("d",function(d){
return line_gen4(d.values);
})
.attr('stroke', function(d) {
return d.color;
})
.attr('fill','None')
.attr('stroke-width',2);
//-----CIRCLES
const circle_chart4 = chartGroup_4.selectAll(".e3_dot")
.data(final_macro_fcast)
.enter().append("g")
.attr('fill',function(d){
return d.color;
});
function e3_MouseOver(dd) {
var r = d3.select(this).attr('r', 10);
svg.append("text")
.attr('x', function() { return xScale4(dd.date) + 75; })
.attr('y', function() { return yScale4(dd.HPI) + 75; })
.attr('id', 'e3_tooltip')
.text('HPI: '+ Math.round(dd.HPI));
};
function e3_MouseOut(dd) {
var r = d3.select(this).attr('r',5);
d3.selectAll("#e3_tooltip").remove();
};
circle_chart4.append('g').selectAll("circle")
.data(function(d){
return d.values;
})
.enter().append("circle")
.attr("class", "e3_dot")
.attr("r", function(dd){
if ([5,11].indexOf(dd.date.getMonth())>=0){
return 5;}
})
.attr("cx", function(dd) {
return xScale4(dd.date); })
.attr("cy", function(dd) {
return yScale4(dd.HPI);})
.on("mouseover",e3_MouseOver)
.on("mouseout",e3_MouseOut);
//------------------BANK RESULTS------------------------|
svg.append("text")
.attr("transform", "translate("+(1200)+","+(small_chart_ht+small_chart_ht-25)+")")
.attr("font-size", "14px")
.attr("font-family", "Helvetica")
.attr("fill", "#0c4714")
.attr('font-weight', 'bold')
.text("Selected Bank's performance under CCAR")
//---------------------CHART 5--------------------------|
var firstResultsLeft = firstMacroLeft;
var firstResultsTop = 400;
// Settign title of the chart
svg.append("text")
.attr("transform", "translate("+(firstResultsLeft+200)+","+(firstResultsTop-small_chart_ht+50)+")")
.attr("font-size", "12px")
.attr("font-family", "Helvetica")
.attr('font-weight', 'bold')
.text("Chargeoffs (Losses in thousands) $")
//---------------------CHART 6--------------------------|
var secondResultsLeft = firstMacroLeft+550;
var secondResultsTop = 400;
// Settign title of the chart
svg.append("text")
.attr("transform", "translate("+(secondResultsLeft+225)+","+(secondResultsTop-small_chart_ht+50)+")")
.attr("font-size", "12px")
.attr("font-size", "12px")
.attr("font-family", "Helvetica")
.attr('font-weight', 'bold')
.text("9 Quarter Rolling Loss Rate (Bps)")
// default - shows first bank in list
createBankResultChart(bank_info_map2.get(fcast_data[0].rssd_id),firstResultsLeft,fcast_date_extent,small_chart_ht,fcast_data,firstResultsTop, secondResultsLeft, secondResultsTop, new_prod);
//------------------PEER RESULTS------------------------|
svg.append("text")
.attr("transform", "translate("+(1200)+","+525+")")
.attr("font-size", "14px")
.attr("font-family", "Helvetica")
.attr("fill", "#0c4714")
.attr('font-weight', 'bold')
.text("Peer Banks' performance under CCAR")
//---------------------CHART 7--------------------------|
var firstPeerLeft = firstMacroLeft;
var firstPeerTop = 675;
// Settign title of the chart
svg.append("text")
.attr("transform", "translate("+(firstPeerLeft+175)+","+(firstPeerTop-small_chart_ht+30)+")")