GB Gilt Yield Curve
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © PigsMightFly

//@version=5
indicator('GB Gilt Yield Curve', 'GBTYC', false, precision=4)
width = input(15, 'Spacing between labels in bars:')

symbols = 11
gb50y = request.security('GB50Y', timeframe.period, close)
gb40y = request.security('GB40Y', timeframe.period, close)
gb30y = request.security('GB30Y', timeframe.period, close)
gb20y = request.security('GB20Y', timeframe.period, close)
gb15y = request.security('GB15Y', timeframe.period, close)
gb10y = request.security('GB10Y', timeframe.period, close)
gb7y = request.security('GB07Y', timeframe.period, close)
gb5y = request.security('GB05Y', timeframe.period, close)
gb3y = request.security('GB03Y', timeframe.period, close)
gb2y = request.security('GB02Y', timeframe.period, close)
gb1y = request.security('GB01Y', timeframe.period, close)
gb6m = request.security('GB06MY', timeframe.period, close)
gb3m = request.security('GB03MY', timeframe.period, close)
gb1m = request.security('GB01MY', timeframe.period, close)

pos(idx) =>
    bar_index - (symbols - idx) * width

draw_label(idx, src, txt) =>
    var label la = na
    label.delete(la)
    la := label.new(pos(idx), src, text=txt, color=color.black, style=label.style_label_up, textcolor=color.white)
    la

draw_line(idx1, src1, idx2, src2) =>
    var line li = na
    line.delete(li)
    li := line.new(pos(idx1), src1, pos(idx2), src2, color=color.red, width=3)
    li

draw_label(0, gb1m, 'GB 1M (' + str.tostring(gb1m) + ')')
draw_label(1, gb3m, 'GB 3M (' + str.tostring(gb3m) + ')')
draw_label(2, gb6m, 'GB 6M (' + str.tostring(gb6m) + ')')
draw_label(3, gb1y, 'GB 1Y (' + str.tostring(gb1y) + ')')
draw_label(4, gb2y, 'GB 2Y (' + str.tostring(gb2y) + ')')
draw_label(5, gb3y, 'GB 3Y (' + str.tostring(gb3y) + ')')
draw_label(6, gb5y, 'GB 5Y (' + str.tostring(gb5y) + ')')
draw_label(7, gb7y, 'GB 7Y (' + str.tostring(gb7y) + ')')
draw_label(8, gb10y, 'GB 10Y (' + str.tostring(gb10y) + ')')
draw_label(9, gb15y, 'GB 15Y (' + str.tostring(gb15y) + ')')
draw_label(10, gb20y, 'GB 20Y (' + str.tostring(gb20y) + ')')
draw_label(11, gb30y, 'GB 30Y (' + str.tostring(gb30y) + ')')
draw_label(12, gb40y, 'GB 40Y (' + str.tostring(gb40y) + ')')
draw_label(13, gb50y, 'GB 50Y (' + str.tostring(gb50y) + ')')

draw_line(0, gb1m, 1, gb3m)
draw_line(1, gb3m, 2, gb6m)
draw_line(2, gb6m, 3, gb1y)
draw_line(3, gb1y, 4, gb2y)
draw_line(4, gb2y, 5, gb3y)
draw_line(5, gb3y, 6, gb5y)
draw_line(6, gb5y, 7, gb7y)
draw_line(7, gb7y, 8, gb10y)
draw_line(8, gb10y, 9, gb15y)
draw_line(9, gb15y, 10, gb20y)
draw_line(10, gb20y, 11, gb30y)
draw_line(11, gb30y, 12, gb40y)
draw_line(12, gb40y, 13, gb50y)



gb10y3m = (gb10y - gb3m) * 100
gb10y2y = (gb10y - gb2y) * 100

p = 'Important spreads:\n\n'
p += '10Y/03M: ' + str.tostring(gb10y3m) + ' bps\n'
p += '10Y/02Y: ' + str.tostring(gb10y2y) + ' bps\n'

draw_label(14, gb30y, p)