Sunday, August 9, 2015

get the fed-wind at your back with sdi_corLabel - correlation percent in a chart label. (thinkscript included)

'don't fight the fed' is the watch-phrase of wallstreet. but, how do you know if your investment is fighting the fed? the fed controls the inter-bank overnight loan rate which forms a low-bound on interest rates overall. when this rate is changed all the other interest rates tend to change in lockstep. of particular influence on stocks is the ten-year treasury yield which forms the basis of home mortgage rates (e.g. 10 year treasury yield + 2 pts is a common recipe for a mortgage quote.) so it behooves one to know how ones investments are affected by interest rates, which can be understood by the correlation to the tnx 10-year treasury index. here's the picture: 


Spy with 60-day correlation to TNX in the label.
the chart label shows that the correlation of the broad-market etf, spy, is negative 14%. these numbers range from -100 (complete anti-correlation) to +100 (complete correlation.) correlations generally considered notable are ones that have absolute value greater than 80 (-100 to -80 and +80 to +100.) 

so i have to ask who's afraid of a rate-increase!? the broad market doesn't have that strong of a negative correlation at the current time. now, mind you, correlations are fickle and can change. you can see the recent variation by adding the tos correlation study like so:
Spy with correlation study.
this shows that correlation with tnx has been mostly positive and ranging up to +55% (.55 in the study) or so. all of that is weak and by weak i mean that interest rates don't seem to have the effect that people are fearing. at least not now.

so what people are fearing, maybe, is that a rate increase makes the dollar trade stronger against other currencies. this is because of what is called the carry trade, whereby, one borrows currency of a low interest paying country and exchanges it for currency of a higher interest paying country. the nightly mark-to-market in forex compounds this interest differential on a daily basis. a stronger dollar makes US goods and services more expensive to foreigners and that is perceived to be bad for US stocks. however, this effect is mitigated by the reduction of the price of commodities such as oil, which are usually traded in dollars.

here's the code:

# sdi_corLabel - correlation label
# author: allen everhart
# date: 9aug2015
#hint: displays the correlation as a +/- percent in a chart label. source: http://smalldoginvestor.com rev:1.0.0
input sym = "TNX";
#hint sym: symbol to correlate. source: http://smalldoginvestor.com rev:1.0.0
input length = 60;
#hint length: number of chart aggregation periods to use in correlation calculation.
def cor= round(Correlation(close,close(sym),length = length),2);
plot labelColor=double.nan;
labelColor.hideTitle();
# copylefts reserved. This is free software. That means you are free
# to use or modify it for your own usage but not for resale or reprinting. 
# Help me get the word out about my blog by keeping notices of origin in place.
#hint threshold: the minimum price change to display. rev: 1.0.0 from http://www.smallDogInvestor.com

labelColor.setDefaultColor(color.BLUE);
AddLabel(1, 
    Concat("~", 
    Concat(sym, 
# copylefts reserved. This is free software. That means you are free
# to use or modify it for your own usage but not for resale or reprinting. 
# Help me get the word out about my blog by keeping notices of origin in place.
#hint threshold: the minimum price change to display. rev: 1.0.0 from http://www.smallDogInvestor.com
    Concat("=", 
    concat( if cor>0 then "+" else "(",
    concat( AsPercent(cor), if cor<0 then ")" else ""
    ))))),
    labelColor.takeValueColor()

);




1 comment:

  1. Thanks again...didn't know any of this...will forward to others.

    ReplyDelete