Skip to content

Instantly share code, notes, and snippets.

@theclaymethod
theclaymethod / IV_Z_SCORE.ts
Last active August 23, 2020 16:29
Rolling Quarterly Z Score of IV.
declare lower;
declare hide_on_intraday;
# Z-normalized of log(IV)
def vol = if (GetSymbol() == "/ES") then close("VIX") / 100
else if (GetSymbol() == "/CL") then close("OIV") / 100
else if (GetSymbol() == "/GC") then close("GVX") / 100
else if (GetSymbol() == "/SI") then close("VXSLV") / 100
else if (GetSymbol() == "/NQ") then close("VXN") / 100
else if (GetSymbol() == "/TF") then close("RVX") / 100
@theclaymethod
theclaymethod / General_IV_STUDY.ts
Last active August 22, 2020 23:05
Displays Rolling Median IV , rolling ±1 stdev IV.
declare lower;
declare hide_on_intraday;
#IVPercentile
def vol = if (GetSymbol() == "/ES") then close("VIX") / 100
else if (GetSymbol() == "/CL") then close("OIV") / 100
else if (GetSymbol() == "/GC") then close("GVX") / 100
else if (GetSymbol() == "/SI") then close("VXSLV") / 100
else if (GetSymbol() == "/NQ") then close("VXN") / 100
else if (GetSymbol() == "/TF") then close("RVX") / 100
declare lower;
declare hide_on_intraday;
#IVPercentile
def vol = if (GetSymbol() == "/ES") then close("VIX") / 100
else if (GetSymbol() == "/CL") then close("OIV") / 100
else if (GetSymbol() == "/GC") then close("GVX") / 100
else if (GetSymbol() == "/SI") then close("VXSLV") / 100
else if (GetSymbol() == "/NQ") then close("VXN") / 100
else if (GetSymbol() == "/TF") then close("RVX") / 100
# This displays the day's change in IV Percentile
declare lower;
declare hide_on_intraday; # do not display when using intra-day plots
input days_back = 252; # it is most common to use 1-year (or 252 trading days)
def df = if (GetSymbol() == "/ES") then close("VIX") / 100
else if (GetSymbol() == "/CL") then close("OIV") / 100
else if (GetSymbol() == "/GC") then close("GVX") / 100
else if (GetSymbol() == "/SI") then close("VXSLV") / 100
else if (GetSymbol() == "/NQ") then close("VXN") / 100
declare lower;
# Adapted from Mark Laczynski: https://pdvwrt.blogspot.com/2014/03/think-or-swim-tos-iv-percentile.html
# look at 1 year of history
input length = 252;
declare hide_on_intraday; # do not display when using intra-day plots
#clean up the IV data from TOS
{
"IAB1": "Arts & Entertainment",
"IAB1-1": "Books & Literature",
"IAB1-2": "Celebrity Fan/Gossip",
"IAB1-3": "Fine Art",
"IAB1-4": "Humor",
"IAB1-5": "Movies",
"IAB1-6": "Music",
"IAB1-7": "Television",
"IAB2": "Automotive",
@theclaymethod
theclaymethod / Left Join Custom Function for Google Spreadsheets
Last active January 31, 2017 19:06
SQL style Left Join for Google Spreadsheets Scripts
//Copy and paste this into a new script for you spreadsheets
function leftJoin(left, right, left_index, right_index, header, results_sheet) {
var ss = SpreadsheetApp.getActiveSpreadsheet();
left = right || ss.getRangeByName("range1").getValues();
right = right || ss.getRangeByName("range2").getValues();
left_index=left_index || 0;
right_index=right_index ||0;
header = header || true;
results_sheet = results_sheet || "join_output"
/**
* Retrieves all the rows in the active spreadsheet that contain data and logs the
* values for each row.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();