## [Interest, exchange] rate models

### Table of Contents

### Key [results, comments]

Standard & Poor's index of stock market prices for 500 large capitalisation companies (SP500) from 1872 through 2020 is shown in the semi-log plot below. Two "eyeballed" linear trend lines are shown for the periods [1872-1926, 1926-2020].

### Play with the [time, mind]-bending perspective yourself

.
Download data :
Trading View data :
Do NOT use existing graphs - just doubles the work
https://www.tradingview.com/ -> click on "ssearch markets here" enter desired symbol
-> Advanced chart -> New format ->
// All manually-provided constants for del[Min, Max]_10Y will become inaccurate with time!!
// ONLY time.periods [3M, 6M, 1Y, 5Y] work.
// time.periods [1D, 5D, 1M, ALL] do NOT work - I haven't manually provided values from charts.
// there are some errors in my manually [read, record] of the 5Y time-periods
// additionally, this Pine Script was thrown together in a day, no rigorous testing
// exchange rates are shown by darker colors, interest rates lighter similar colors
// China - green, Euro - purple, Great Britain - blue, Japan - orange (you can see this in the4 code below!)
// stable rates : [JP10Y, CN10Y]
// https://www.tradingview.com/x/OXFvIi7I/
// policy-manipulated rates : [TNX, EU10Y, GB10Y]
// https://www.tradingview.com/x/V4LOppCz/
// at some future point:
// more factors will be added
// a Multiple Linear Regression (Lasso) will be done for more aqccurate results
// https://www.tradingview.com/pine-script-docs/en/v4/appendix/HOWTOs.html#count-bars-in-a-dataset
// Find the highest and lowest values for the entire dataset
// 20Mar2021 Howell - adapt this for viewable data
// 20Sep2022 WARNING!!
// PineScript fails at providing functions that work over the full length of the visible stock period.
// One cannot accurately determine the start time bar
// functions like [big, small]est below give WRONG results!! - best to hand-craft answers
biggest(series,size) =>
max = 0.0
for j = 0 to size
if series[j] > max
max := series[j]
max
smalest(series,size) =>
min = 100000.
for j = size to 0
if series[j] < min
min := series[j]
min
//+-----+
// Setup - data specifics for this script
// 25Sep2022 "lingua franca" approach, using USA [interest, GDP] rates and [oil imports/GDP, ] as basis
// 21Sep2022 WARNING!
// hand-crafted off chart, typed in!! To read the values :
// set params like this for ?[the maximum, a given]? time.period, example CNYUSD
// comment out section below for specific del[Min, Max]_CN10Y
// now delMin_CN10Y = 0., delMax_CN10Y = 1.
// enter [min, max] values shown on graph for the given time.period of :
// intDiff_CN10Y = (v_TNX - v_CN10Y - delMin_CN10Y)/(delMax_CN10Y - delMin_CN10Y)
// = (v_TNX - v_CN10Y)
// = del_CN10Y
// comment out line plot(x_CNYUSD, ....
// uncomment line plot(intDiff_CN10Y, ...
// Now, read [min, max] of intDiff_CN10Y = del[Min, Max]_CN10Y for time.periods [3M, 6M, 1Y, 5Y]
// YES - this is STUPID work, but only if PineScript could do well...
v_USOIL = security("TVC:USOIL", timeframe.period, close)
USOIL_detrend = v_USOIL / pow(10, -1.6684 + (0.00291 * yrFrac))
// 21Sep2022 eyeballed averages from TradingView charts
// not terribly useful, as all script plots go to an un-named axis where they share the same scale
// it is best to arrange for all script plots to have the same [range, average]
// that way all plots will scale [min, max] the same as each other,
// and the same scale (visually) as plots that are not part of the script.
avg_INRUSD = 0.01731
delMin_IN10Y = -2.49478
delMax_IN10Y = 0.98706
constCoeff = 0.0004
// avg_USD - note that time.periods [1D, 5D, 1M, All] are NOT included and those timescales don't work
// time.periods [3M, 6M, 1Y, 5Y] do work
// current estimates eyeballed from graph 24Sep2022 (no regression yet!)
// note that constCoeff doesn't vary by much!
// doesn't even need this - except 5Y time.period, but leave it at that
//if (timeframe.period == "60") // 3 months
// avg_INRUSD := 0.007264
//else if (timeframe.period == "120") // 6 months
// avg_INRUSD := 0.007264
//else if (timeframe.period == "D") // 1 year
// avg_INRUSD := 0.007264
//else if (timeframe.period == "W") // 5 years
// avg_INRUSD := 0.007264
//+-----------------------------------------------------------------+
//+-----------------------------------------------------------------+
// Code adapted from my previous PineScript, only using one symbol!
// simple search (same case!) replace CN with OR[CA, EU, JP] in this section ONLY
v_TNX = security("TVC:TNX", timeframe.period, close)
v_IN10Y = security("TVC:CN10Y", timeframe.period, close) // 01Jul2002-24Sep2022
intDiff_IN10Y = v_TNX - v_IN10Y
intRatio_IN10Y = (v_TNX - v_IN10Y - delMin_IN10Y)/(delMax_IN10Y - delMin_IN10Y)
// 21Sep2022 need regression for each currency to add in oil price effect
// for now, just guess
// 21Sep2022 eyeballed averages from TradingView charts
// not terribly useful, as all script plots go to an un-named axis where they share the same scale
// it is best to arrange for all script plots to have the same [range, average]
// that way all plots will scale [min, max] the same as each other,
// and the same scale (visually) as plots that are not part of the script.
// use the maximum time.period (i.e. 5Y) to visually fit the [actual, estimate] echange rate
oilCoeff = -0.003
intCoeff = -0.003
x_INRUSD = avg_INRUSD + (oilCoeff * USOIL_detrend) + (intCoeff * intRatio_IN10Y) + constCoeff
// standard named colors :
// https://www.tradingview.com/pine-script-reference/v5/#var_color{dot}black
// "see also" list of named colors
// color.[black, silver, gray, white, red, purple, fuchsia, green, lime, olive, yellow, navy, blue, teal, aqua, orange]
// 21Sep2022 is there some way to plot against the corresponding currency exchange rate axis?
// Initially, use a separate axis for the plot(x_INRUSD), then adjust [oil, int] Coeff for incomplete "fit"
// uncomment this line when determining del[Min, Max]_10Y, comment out afterwords
//plot(intDiff_IN10Y, color=color.purple, linewidth=1, title="d_IN10Y") // green
// Next, put plot(x_INRUSD) on the same axis as the exchange rate
// AFTER determining the del[Min, Max]_10Y in the step above, comment out that line
// uncomment this line to proceed :
plot(x_INRUSD, color=color.green, linewidth=1, title="d_IN10Y") // green
17Sep2020 initial posting