rates = new CsvPlotReader().read("demoResources/interest-rates.csv") def f = new java.text.SimpleDateFormat("yyyy MM dd") lehmanDate = f.parse("2008 09 15") bubbleBottomDate = f.parse("2002 10 09") inversion1 = [f.parse("2000 07 22"), f.parse("2001 02 16")] inversion2 = [f.parse("2006 08 01"), f.parse("2007 06 07")] def size = rates.size() (0 ..< size).each{row = rates[it]; row.spread = row.y10 - row.m3} OutputCell.HIDDEN def ch = new Crosshair(color: Color.gray, width: 2, style: StrokeType.DOT) // The top plot has 2 lines. p1 = new TimePlot(yLabel: "Interest Rate", crosshair: ch) p1 << new Line(x: rates.time, y: rates.m3, displayName: "3 month") p1 << new Line(x: rates.time, y: rates.y10, displayName: "10 year") // The bottom plot has an area filled in. p2 = new TimePlot(yLabel: "Spread", crosshair: ch) p2 << new Area(x: rates.time, y: rates.spread, color: new Color(120, 60, 0)) // Highlight the inversion intervals def b1 = new ConstantBand(x: inversion1, color: new Color(240, 100, 100, 55)) def b2 = new ConstantBand(x: inversion2, color: new Color(240, 100, 100, 55)) // Add notation and line for Lehman Bankruptcy. p1 << new Text(x: lehmanDate, y: 7.5, text: "Lehman Brothers Bankruptcy") def l1 = new ConstantLine(x: lehmanDate, style: StrokeType.DOT, color: Color.gray) // Add notation and line for Stocks Nadir. p1 << new Text(x: bubbleBottomDate, y: 5.75, text: "Stocks Hit Bottom") def l2 = new ConstantLine(x: bubbleBottomDate, style: StrokeType.DOT, color: Color.gray) // add the notations and highlight bands to both plots p1 << l1 << l2 << b1 << b2 p2 << l1 << l2 << b1 << b2 OutputCell.HIDDEN // Then use a CombinedPlot to get stacked plots with linked X axis. def c = new CombinedPlot(title: "US Treasuries", initWidth: 1000) // add both plots to the combined plot, and including their relative heights. c.add(p1, 3) c.add(p2, 1) // The simplest chart function with all defaults: new SimpleTimePlot(rates, ["y1", "y10"]) def c = new Color(120, 120, 120, 100) new Plot() << new Points(x: rates.y1, y: rates.y30, displayName: "y1 vs y30") \ << new Points(x: rates.m3, y: rates.y5, displayName: "m3 vs y5") \ << new Line(x: rates.m3, y: rates.y5, color: c) \ << new Line(x: rates.y1, y: rates.y30, color: c) p = new Plot() p << new Line(x:[1000, 10000], y:[10000, 10000], width: 10, color: Color.orange) p << new Line(x:[5500, 5500], y:[10000, 9999], width: 10, color: Color.orange) p << new Line(x:[14000, 14000, 15002], y:[900, 901, 901], width: 1, color: Color.blue) p << new Line(x:[14000, 15002, 15002], y:[900, 900, 899], width: 1, color: Color.blue) p << new Line(x:[14000, 15002], y:[899, 899], width: 1, color: Color.blue)