Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sherwind/4e399d4b1886bf690c14ae9fc243b498 to your computer and use it in GitHub Desktop.
Save sherwind/4e399d4b1886bf690c14ae9fc243b498 to your computer and use it in GitHub Desktop.
10Y Bond Yield Spread (beta)
//@version=3
//
// 10-Year Bond Yield Spread using Quandl data
//
// See also:
// - https://seekingalpha.com/article/3697846-drives-foreign-exchange-rate-differentials
// - https://www.babypips.com/learn/forex/interest-rates-101
// - https://www.forexfactory.com/showthread.php?p=3382194#post3382194
//
// -----------------------------------------------------------------------------
// Copyright 2018 sherwind
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// The GNU General Public License can be found here
// <http://www.gnu.org/licenses/>.
//
// -----------------------------------------------------------------------------
//
study("10Y Bond Yield Spread (beta)", overlay=true, scale=scale.left)
// Based on the code of @Greeny (Thanks!)
quandl(code, index) =>
quandl_ticker = "QUANDL:" + code + (index == 0 ? "" : "|" + tostring(index))
security(quandl_ticker, "D", close)
// 10Y Bond Yields
usd_yield = quandl("FRED/DGS10", 0)
gbp_yield = quandl("BOE/IUDMNZC", 0)
eur_yield = quandl("BUNDESBANK/BBK01_WT1010", 0)
jpy_yield = quandl("MOFJ/INTEREST_RATE_JAPAN_10Y", 0)
cad_yield = quandl("BOC/V39055", 0)
aud_yield = quandl("RBA/F17_0_FZCY1000D", 0) // Zero-coupon yield - 10 yrs - Per cent per annum (FZCY1000D)
chf_yield = quandl("SNB/RENDOBLID", 9) // Spot interest rates with different maturities for Confederation bond issues; euro-denominated bond issues and US treasury bond issues - CHF Swiss Confederation bond issues - 10 years
yield_spread = ticker == "EURUSD" ? eur_yield - usd_yield :
ticker == "GBPUSD" ? gbp_yield - usd_yield :
ticker == "AUDUSD" ? aud_yield - usd_yield :
ticker == "USDJPY" ? usd_yield - jpy_yield :
ticker == "USDCHF" ? usd_yield - chf_yield :
ticker == "USDCAD" ? usd_yield - cad_yield :
ticker == "JPYUSD" ? jpy_yield - usd_yield :
ticker == "CHFUSD" ? chf_yield - usd_yield :
ticker == "CADUSD" ? cad_yield - usd_yield :
na
plot(yield_spread)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment