Skip to content

Instantly share code, notes, and snippets.

@yanofsky
Last active January 1, 2016 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yanofsky/8199176 to your computer and use it in GitHub Desktop.
Save yanofsky/8199176 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>Perfect sp 500 graphic</title>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<script src="http://www.datejs.com/build/date.js" charset="utf-8"></script>
</head>
<body>
<style type="text/css">
@font-face {
font-family: 'PT Serif';
src: url('http://app.qz.com/fonts/PTSerif/PTF55F-webfont.eot');
src: url('http://app.qz.com/fonts/PTSerif/PTF55F-webfont.eot?#iefix') format('embedded-opentype'),
url('http://app.qz.com/fonts/PTSerif/PTF55F-webfont.woff') format('woff'),
url('http://app.qz.com/fonts/PTSerif/PTF55F-webfont.ttf') format('truetype'),
url('http://app.qz.com/fonts/PTSerif/PTF55F-webfont.svg#PTSerifRegular') format('svg');
font-weight: normal;
font-style: normal;
}
@font-face{font-family:'AdelleSansWeb';src:url('http://app.qz.com/fonts/AdelleSansWeb/AdelleSansBasic_Bold.eot?#iefix') format('embedded-opentype'),
url('http://app.qz.com/fonts/AdelleSansWeb/AdelleSansBasic_Bold.woff') format('woff'),
url('http://app.qz.com/fonts/AdelleSansWeb/AdelleSansBasic_Bold.ttf') format('truetype');font-weight:700;}
body {
height: 5000px;
}
</style>
<script>
d3.csv("perfectspdaybyday.csv", function(data) {
var datetoday = {}
for (var i = data.length - 1; i >= 0; i--) {
datetoday[data[i].date] = data[i]
};
alldata = []
var cur_date = new Date("1/1/2013")
var prev_date = new Date("12/31/2012")
var end_date = new Date("12/30/2013")
var o
while(cur_date < end_date) {
date_string = cur_date.toString("yyyy-MM-dd")
try {
o = datetoday[date_string]
o.tradingDay = true;
}
catch (e) {
o = {};
o.date = date_string
o.tradingDay = false
}
o.weekNumber = cur_date.getWeek()
o.dayofweek = cur_date.getDay()
if(o.dayofweek == 0) {
o.weekNumber += 1;
}
o.dateObj = new Date(cur_date.getTime())
alldata.push(o)
prev_date = cur_date
cur_date = cur_date.add(1).day()
}
var w = 600
var h = 5000
var canvas = d3.select("body").append("svg").attr("width",w).attr("height",h)
w = 400
var days = canvas.selectAll("g").data(alldata)
.enter()
.append("g")
//.filter(function(d){return d.dayofweek < 5})
.attr("class","day")
.attr("transform",function(d){console.log(d);return "translate(" + (d.dayofweek * (w/7)) + "," + (d.weekNumber * (w/7) + d.dateObj.getMonth() * (w/7*2.5)) + ")"})
//.attr("opacity",function(d){return d.tradingDay?1:0})
days.append("rect")
.attr("width",w/7)
.attr("height",w/7)
.attr("fill","none")
.attr("stroke","#999")
.attr("stroke-width",1)
var yscale = d3.scale.linear()
.domain([0,75])
.range([0,-w/7])
days.filter(function(d){return d.tradingDay}).append("path")
.attr("transform","translate(0,"+w/7+")")
.attr("d",function(d){
return "M" + [0,0].join(",") +
"L" + [w/7,yscale(d.rate)].join(",") +
"L" + [w/7,0].join(",") +
"Z"
})
.attr("fill","#87CC9E")
days.append("text")
.text(function(d){return d.dateObj.getDate()})
.style("font-size","10")
.style("font-family","PT Serif")
.attr("y", 13)
.attr("x", 5)
.attr("fill","#666")
days.append("text")
.text(function(d){return d.ticker})
.style("font-size","12")
.style("font-family","AdelleSansWeb")
.style("fill","")
.attr("y", w/7/3 + 8)
.attr("x", w/7/2)
.attr("text-anchor","middle")
.attr("fill","#666")
days.append("text")
.text(function(d){return d.tradingDay?"+" + d.rate + "%":""})
.style("font-size","12")
.style("font-family","PT Serif")
.attr("y", w/7/3 + 20)
.attr("x", w/7/2)
.attr("text-anchor","middle")
.attr("fill","#666")
var addCommas = d3.format("0,000")
days.append("text")
.text(function(d){return d.dayofweek==5 ? "$" + addCommas(Math.round(d.value)) + "":""})
.style("font-size","16")
.style("font-family","AdelleSansWeb")
.attr("y", w/7/2 + 6)
.attr("x", w/7*4.5)
.attr("text-anchor","end")
.attr("fill","#666")
})
</script>
</body>
</html>
date value val rate ticker price
2013-01-02 1085.53 1.09 8.55 X 25.89
2013-01-03 1172.07 1.17 7.97 ROST 58.78
2013-01-04 1234.93 1.23 5.36 DG 44.60
2013-01-07 1289.69 1.29 4.43 CELG 85.73
2013-01-08 1375.13 1.38 6.63 CELG 91.41
2013-01-09 1466.51 1.47 6.64 STX 33.48
2013-01-10 1552.75 1.55 5.88 TSO 42.85
2013-01-11 1807.09 1.81 16.38 BBY 14.21
2013-01-14 1895.43 1.90 4.89 HPQ 16.95
2013-01-15 1994.25 1.99 5.21 DNR 17.76
2013-01-16 2170.86 2.17 8.86 GNW 8.85
2013-01-17 2343.09 2.34 7.93 CBS 40.95
2013-01-18 2591.16 2.59 10.59 LIFE 60.79
2013-01-22 2774.99 2.77 7.09 STX 37.89
2013-01-23 3034.94 3.03 9.37 ISRG 567.06
2013-01-24 4316.40 4.32 42.22 NFLX 146.86
2013-01-25 4983.58 4.98 15.46 NFLX 169.56
2013-01-28 5286.48 5.29 6.08 HES 62.48
2013-01-29 5962.11 5.96 12.78 VLO 39.98
2013-01-30 6355.08 6.36 6.59 RHI 35.74
2013-01-31 7644.13 7.64 20.28 PBI 14.41
2013-02-01 8135.07 8.14 6.42 GME 24.69
2013-02-04 8625.74 8.63 6.03 NFLX 174.74
2013-02-05 9416.07 9.42 9.16 CSC 45.75
2013-02-06 10100.70 10.10 7.27 FSLR 31.13
2013-02-07 11103.09 11.10 9.92 FLIR 26.03
2013-02-08 11904.58 11.90 7.22 MCHP 36.39
2013-02-11 12672.11 12.67 6.45 FSLR 32.36
2013-02-12 15246.14 15.25 20.31 AVP 20.79
2013-02-13 16007.49 16.01 4.99 FTI 50.46
2013-02-14 21967.62 21.97 37.23 STZ 43.75
2013-02-15 24720.51 24.72 12.53 MWV 35.65
2013-02-19 27965.67 27.97 13.13 SPLS 14.65
2013-02-20 28718.29 28.72 2.69 JOY 65.25
2013-02-21 32769.95 32.77 14.11 SWY 22.97
2013-02-22 36794.33 36.79 12.28 HPQ 19.20
2013-02-25 37951.30 37.95 3.14 AMGN 89.55
2013-02-26 40120.55 40.12 5.72 PHM 19.05
2013-02-27 44329.89 44.33 10.49 DLTR 45.39
2013-02-28 45943.57 45.94 3.64 MYL 29.61
2013-03-01 49864.04 49.86 8.53 ISRG 553.40
2013-03-04 53200.01 53.20 6.69 GNW 9.09
2013-03-05 55736.69 55.74 4.77 TRIP 47.68
2013-03-06 58034.01 58.03 4.12 FCX 32.84
2013-03-07 62463.46 62.46 7.63 JDSU 15.23
2013-03-08 68214.70 68.21 9.21 HRB 27.28
2013-03-11 72790.08 72.79 6.71 GNW 10.50
2013-03-12 76306.19 76.31 4.83 STX 34.94
2013-03-13 80601.06 80.60 5.63 NFLX 192.36
2013-03-14 84819.43 84.82 5.23 CHK 22.52
2013-03-15 90916.80 90.92 7.19 CNP 23.41
2013-03-18 96078.51 96.08 5.68 ISRG 485.52
2013-03-19 101309.27 101.31 5.44 WAG 44.74
2013-03-20 107313.59 107.31 5.93 FSLR 29.49
2013-03-21 111029.14 111.03 3.46 YHOO 22.86
2013-03-22 123312.77 123.31 11.06 NKE 59.53
2013-03-25 128658.70 128.66 4.34 CLF 21.66
2013-03-26 135647.08 135.65 5.43 NFLX 190.61
2013-03-27 141457.13 141.46 4.28 GILD 47.72
2013-03-28 149586.24 149.59 5.75 GME 27.97
2013-04-01 162378.23 162.38 8.55 HUM 75.02
2013-04-02 172250.11 172.25 6.08 DVA 63.60
2013-04-03 178843.06 178.84 3.83 ANF 47.20
2013-04-04 207590.12 207.59 16.07 BBY 25.13
2013-04-05 219850.47 219.85 5.91 NBR 15.78
2013-04-08 231557.68 231.56 5.33 WPX 17.01
2013-04-09 336974.66 336.97 45.53 FSLR 39.35
2013-04-10 355108.61 355.11 5.38 MU 10.09
2013-04-11 376125.67 376.13 5.92 ROST 63.80
2013-04-12 398432.49 398.43 5.93 NTAP 35.46
2013-04-15 428373.52 428.37 7.51 LIFE 73.11
2013-04-16 459082.80 459.08 7.17 GWW 241.88
2013-04-17 472090.30 472.09 2.83 DG 51.90
2013-04-18 507832.15 507.83 7.57 BTU 20.46
2013-04-19 822213.58 822.21 61.91 VRTX 85.60
2013-04-22 877574.72 877.57 6.73 NFLX 174.37
2013-04-23 1092073.97 1092.07 24.44 NFLX 216.99
2013-04-24 1221206.16 1221.21 11.82 FSLR 45.11
2013-04-25 1437457.55 1437.46 17.71 AKAM 42.48
2013-04-26 1562275.51 1562.28 8.68 DHI 26.66
2013-04-29 1691803.79 1691.80 8.29 MCO 59.69
2013-04-30 1816941.34 1816.94 7.40 BBY 25.99
2013-05-01 2004006.75 2004.01 10.30 REGN 237.29
2013-05-02 2169079.94 2169.08 8.24 HAR 47.83
2013-05-03 2322013.91 2322.01 7.05 REGN 266.16
2013-05-06 2450301.97 2450.30 5.52 CLF 21.01
2013-05-07 2671165.89 2671.17 9.01 FOSL 107.88
2013-05-08 3128209.48 3128.21 17.11 EA 21.56
2013-05-09 3367036.43 3367.04 7.63 PCP 206.68
2013-05-10 3778419.50 3778.42 12.22 ACT 119.86
2013-05-13 3981230.93 3981.23 5.37 NFLX 229.38
2013-05-14 4231314.19 4231.31 6.28 EW 71.57
2013-05-15 4444834.67 4444.83 5.05 BMY 44.34
2013-05-16 5005835.25 5005.84 12.62 CSCO 23.89
2013-05-17 5355159.61 5355.16 6.98 TSO 62.24
2013-05-20 5881246.72 5881.25 9.82 FSLR 54.89
2013-05-21 6171242.05 6171.24 4.93 MDT 52.35
2013-05-22 6556706.15 6556.71 6.25 MJN 85.90
2013-05-23 7677800.98 7677.80 17.10 HPQ 24.86
2013-05-24 8048003.02 8048.00 4.82 ISRG 501.53
2013-05-28 8388500.47 8388.50 4.23 TRIP 64.30
2013-05-29 8663318.74 8663.32 3.28 NEM 33.10
2013-05-30 9230719.25 9230.72 6.55 FSLR 55.15
2013-05-31 9445321.04 9445.32 2.32 EW 66.46
2013-06-03 9818776.90 9818.78 3.95 INTC 25.24
2013-06-04 10845053.80 10845.05 10.45 MNST 59.60
2013-06-05 11562236.77 11562.24 6.61 JNPR 18.54
2013-06-06 12696608.81 12696.61 9.81 REGN 252.17
2013-06-07 13491083.74 13491.08 6.26 MS 27.00
2013-06-10 14332211.77 14332.21 6.23 FSLR 56.40
2013-06-11 15450443.78 15450.44 7.80 GME 37.72
2013-06-12 17162630.17 17162.63 11.08 SE 33.68
2013-06-13 22998789.04 22998.79 34.01 GCI 26.60
2013-06-14 24859741.49 24859.74 8.09 TWC 103.93
2013-06-17 26630209.56 26630.21 7.12 NFLX 229.23
2013-06-18 28268581.17 28268.58 6.15 FLIR 26.49
2013-06-19 29846301.79 29846.30 5.58 ADBE 45.78
2013-06-20 31713148.08 31713.15 6.25 GME 40.94
2013-06-21 33050709.42 33050.71 4.22 CRM 38.30
2013-06-24 34535424.69 34535.42 4.49 THC 43.73
2013-06-25 37239653.09 37239.65 7.83 FSLR 44.48
2013-06-26 39085239.01 39085.24 4.96 HAR 51.25
2013-06-27 41265090.22 41265.09 5.58 CVC 16.28
2013-06-28 44600846.34 44600.85 8.08 NEM 29.95
2013-07-01 48896528.32 48896.53 9.63 CVC 18.44
2013-07-02 52968945.99 52968.95 8.33 X 19.25
2013-07-03 54813798.79 54813.80 3.48 CMG 384.47
2013-07-05 57778309.27 57778.31 5.41 LNC 38.98
2013-07-08 60617925.84 60617.93 4.91 BTU 15.37
2013-07-09 65195762.10 65195.76 7.55 DHI 21.22
2013-07-10 69834397.25 69834.40 7.11 FDO 68.50
2013-07-11 76237265.97 76237.27 9.17 DHI 22.98
2013-07-12 85872141.27 85872.14 12.64 ALXN 114.26
2013-07-15 90593757.43 90593.76 5.50 FSLR 50.27
2013-07-16 94360778.02 94360.78 4.16 NWSA 15.28
2013-07-17 104119816.82 104119.82 10.34 YHOO 29.66
2013-07-18 112736052.33 112736.05 8.28 JCI 40.43
2013-07-19 122377341.26 122377.34 8.55 CMG 408.97
2013-07-22 129458079.72 129458.08 5.79 NEM 30.35
2013-07-23 135962713.63 135962.71 5.02 BTU 17.14
2013-07-24 145007872.12 145007.87 6.65 EA 25.41
2013-07-25 182047006.40 182047.01 25.54 OKE 53.77
2013-07-26 195906826.90 195906.83 7.61 SBUX 73.36
2013-07-29 218961055.70 218961.06 11.77 CF 202.30
2013-07-30 246926190.53 246926.19 12.77 PBI 16.60
2013-07-31 270554035.45 270554.04 9.57 SYMC 26.68
2013-08-01 304451959.64 304451.96 12.53 PXD 174.15
2013-08-02 331533769.54 331533.77 8.90 SEE 30.36
2013-08-05 348085899.96 348085.90 4.99 MU 14.17
2013-08-06 410071891.21 410071.89 17.81 FOSL 126.55
2013-08-07 444873829.13 444873.83 8.49 CSC 54.20
2013-08-08 492533461.46 492533.46 10.71 HAR 64.90
2013-08-09 544897309.70 544897.31 10.63 CLF 24.35
2013-08-12 570563431.71 570563.43 4.71 NEM 30.90
2013-08-13 617594690.72 617594.69 8.24 MU 14.97
2013-08-14 655783724.13 655783.72 6.18 NEM 31.94
2013-08-15 693122432.58 693122.43 5.69 DHI 19.12
2013-08-16 711500678.90 711500.68 2.65 WPX 18.97
2013-08-19 733468109.80 733468.11 3.09 DG 54.09
2013-08-20 830611461.80 830611.46 13.24 BBY 34.80
2013-08-21 870143814.86 870143.81 4.76 GRMN 40.28
2013-08-22 948533503.35 948533.50 9.01 GME 51.91
2013-08-23 1021517813.87 1021517.81 7.69 ADSK 38.91
2013-08-26 1100356546.67 1100356.55 7.72 AMGN 113.75
2013-08-27 1122198387.99 1122198.39 1.98 GT 19.01
2013-08-28 1171194950.96 1171194.95 4.37 GT 19.84
2013-08-29 1222180911.87 1222180.91 4.35 GRMN 41.23
2013-08-30 1375618515.47 1375618.52 12.55 CRM 49.13
2013-09-03 1471220908.28 1471220.91 6.95 REGN 259.15
2013-09-04 1589606634.73 1589606.63 8.05 ETFC 15.71
2013-09-05 1685315934.73 1685315.93 6.02 FAST 48.60
2013-09-06 1762779183.51 1762779.18 4.60 AMT 71.91
2013-09-09 1928510559.74 1928510.56 9.40 DAL 21.76
2013-09-10 2052488580.08 2052488.58 6.43 NFLX 313.06
2013-09-11 2206531021.97 2206531.02 7.51 NFX 26.07
2013-09-12 2316966269.18 2316966.27 5.00 WAG 53.29
2013-09-13 2457530451.33 2457530.45 6.07 GME 52.45
2013-09-16 2656673680.36 2656673.68 8.10 ATI 30.95
2013-09-17 2915379509.72 2915379.51 9.74 SWY 30.99
2013-09-18 3184267856.69 3184267.86 9.22 ADBE 52.58
2013-09-19 3331954488.05 3331954.49 4.64 PBI 18.50
2013-09-20 3425010089.02 3425010.09 2.79 TDC 60.73
2013-09-23 3595231060.69 3595231.06 4.97 AAPL 490.64
2013-09-24 3922131564.86 3922131.56 9.09 AMAT 17.45
2013-09-25 4116361525.13 4116361.53 4.95 STX 43.87
2013-09-26 4303705768.65 4303705.77 4.55 REGN 305.53
2013-09-27 4646377190.41 4646377.19 7.96 CERN 52.61
2013-09-30 4757775935.98 4757775.94 2.40 ISRG 376.27
2013-10-01 4994887695.54 4994887.70 4.98 NFLX 324.62
2013-10-02 5300352183.57 5300352.18 6.12 THC 43.90
2013-10-03 5586498759.31 5586498.76 5.40 THC 46.27
2013-10-04 5786313916.13 5786313.92 3.58 JNPR 20.85
2013-10-07 6051739702.72 6051739.70 4.59 ISRG 380.99
2013-10-08 6279046092.33 6279046.09 3.76 MNST 53.59
2013-10-09 6838864659.59 6838864.66 8.92 HPQ 22.60
2013-10-10 7355645938.34 7355645.94 7.56 BBY 39.00
2013-10-11 7863574609.41 7863574.61 6.91 SWY 33.75
2013-10-14 8478132014.53 8478132.01 7.82 NFLX 324.36
2013-10-15 8925947402.94 8925947.40 5.28 X 23.52
2013-10-16 9505829479.85 9505829.48 6.50 ABT 35.90
2013-10-17 10345556392.90 10345556.39 8.83 SNDK 68.50
2013-10-18 12010713361.70 12010713.36 16.10 CMG 509.74
2013-10-21 12950274669.10 12950274.67 7.82 FSLR 53.88
2013-10-22 14455223744.90 14455223.74 11.62 WHR 146.19
2013-10-23 16498730945.40 16498730.95 14.14 GLW 17.52
2013-10-24 17656016029.70 17656016.03 7.01 PHM 17.85
2013-10-25 19805661704.70 19805661.70 12.18 FLS 71.22
2013-10-28 21125497680.50 21125497.68 6.66 BMY 52.02
2013-10-29 23754318684.70 23754318.68 12.44 XYL 32.53
2013-10-30 25595204550.40 25595204.55 7.75 EA 26.00
2013-10-31 30208591599.60 30208591.60 18.02 EXPE 58.97
2013-11-01 35513380256.80 35513380.26 17.56 FSLR 59.14
2013-11-04 38232962758.30 38232962.76 7.66 VMC 57.78
2013-11-05 41031555914.40 41031555.91 7.32 REGN 302.32
2013-11-06 43275469128.50 43275469.13 5.47 FTR 4.73
2013-11-07 46294072114.80 46294072.11 6.98 RIG 52.45
2013-11-08 50806977687.90 50806977.69 9.75 GPS 41.43
2013-11-11 53107128528.70 53107128.53 4.53 BBY 44.33
2013-11-12 55606633470.60 55606633.47 4.71 DHI 18.91
2013-11-13 60827631864.60 60827631.86 9.39 M 50.68
2013-11-14 65519063585.00 65519063.59 7.71 IRM 28.49
2013-11-15 71210173382.00 71210173.38 8.69 A 54.93
2013-11-18 72873815799.90 72873815.80 2.34 DNB 116.08
2013-11-19 76505927709.60 76505927.71 4.98 DVN 62.77
2013-11-20 79890928679.10 79890928.68 4.42 VRTX 65.14
2013-11-21 84947854483.80 84947854.48 6.33 MU 19.99
2013-11-22 96115621781.30 96115621.78 13.15 BIIB 285.62
2013-11-25 104632411048.00 104632411.05 8.86 DVA 61.55
2013-11-26 113714592177.00 113714592.18 8.68 TIF 88.02
2013-11-27 124002839457.00 124002839.46 9.05 HPQ 27.36
2013-11-29 127337128937.00 127337128.94 2.69 ALXN 124.50
2013-12-02 139770553532.00 139770553.53 9.76 FRX 56.32
2013-12-03 147864262834.00 147864262.83 5.79 ANF 35.99
2013-12-04 163659278165.00 163659278.17 10.68 CF 237.07
2013-12-05 173646645858.00 173646645.86 6.10 DG 59.81
2013-12-06 183812537072.00 183812537.07 5.85 EA 22.24
2013-12-09 201545544875.00 201545544.88 9.65 SYY 37.62
2013-12-10 209911586361.00 209911586.36 4.15 WPX 19.32
2013-12-11 225951342129.00 225951342.13 7.64 SNI 81.00
2013-12-12 233998579689.00 233998579.69 3.56 LUV 18.61
2013-12-13 263952825441.00 263952825.44 12.80 ADBE 60.89
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment