#] #] ********************* #] "$d_web"'CompLangs/PineScript/PuetzUWS IntlStkIdxs multi-fractals notes.txt' - ??? # www.BillHowell.ca 14Apr2023 initial # view in text editor, using constant-width font (eg courier), tabWidth = 3 # fibonacci [, retracement ratio]s see "$d_Qndfs"'math - [quick, handy] stuff.ndf' #48************************************************48 #24************************24 # Table of Contents, generate with : # $ grep "^#]" "$d_web"'CompLangs/PineScript/PuetzUWS IntlStkIdxs multi-fractals notes.txt' | sed "s/^#\]/ /" # #24************************24 # Setup, ToDos, PineScript built-in functions : go to PineScript editor -> Menu -> ... (more) -> PineScript reference (pop up) -> Built-in functions #08********08 #] ??Apr2023 #08********08 #] ??Apr2023 #08********08 #] ??Apr2023 #08********08 #] 18Apr2023 revamp to simply plot SP500 1938-2022 inclined Puetz timeFractal previous version : "$d_web"'CompLangs/PineScript/230417 20h08m08s PuetzUWS IntlStkIdxs multi-fractals (noWork).txt' +-----+ olde code // ary_n_bar -> can cause scrunching of outputs!!! very finicky to set - wish I had a robust n_bars, t_start! // 27May2022 PineScript provides no bug-free means of getting n_bars. // see '0_PineScript notes.txt' : // I did it by trial & error for each time period and even then... // std TradingView timeScales ( 1D 5D 1M 3M 6M 1Y 5Y All "All, 01Feb1871") // last_bar_index (24924 21257 28294 20055 22804 4951 1000 230 ????) these vary a bit // 20Jun2022 using last_bar_index (number of datapoints on time axis) DOESN'T work! // Study Error : This study references too many candles in history (eg 5001) //n_bars = last_bar_index // 20Jun2022 couldn't get these to work - problems with : // Study Error : This study references too many candles in history (eg 5001) // 16Apr2023 normalize variances via (1 + rsd) - this is a pragmatic fudge // Symbols' [priceRsd [normal, semi-log], priceRsd[Min, Max]] // {[trend, relStdDev], priceRsd[Min, Max, Spread]Idx, etc} // refer to my webSite (good luck with the webSearch) for details // 1871-present : Wilhelm Abel ?1937?, David Fischer 1996, I've used the following split : // price equilibrium (stable prices) 1871-1926 // price revolution 1926-2020 // 11Aug2022 QNial work may show that the breakover should be in the 1950's? // (maybe Breton Woods 1944?) // calculate [priceNormalRsd, priceSemilogRsd] from priceNormal // Euler's number 2.7182818 priceNormal_regressParams_to_priceLogRsd(priceNormal, constant, slope) => priceTrend = math.pow(10, constant + slope * year_fraction) (priceNormal / priceTrend - 1) // 17Apr2023 needs verification! - guesswork for now priceLogRsd_to_priceNormal(priceLogRsd, constant, slope) => priceTrend = math.pow(10, constant + slope * year_fraction) math.pow(10, (priceLogRsd + 1) * priceTrend) // symbols - [,un] comment to [ex, in]clude // CME:CUS2! housing price futures // CUS2 = request.security("TVC:UKX", timeframe.period, close) // CUS2_detrend = 0. // CUS2_detrend := priceNormal_regressParams_to_priceLogRsd(CUS2, -23.3117, 0.012713, 0.0273817) // plot(CUS2_detrend, color=color.orange, title="CME:CUS2! housing price futures", linewidth=2) // rsdMinCUS2 = 10. // rsdMaxCUS2 = -10. // rsdMinCUS2 := smalest(CUS2_detrend, n_bars) // 14Apr2023 parameters updates to DAX40 = request.security("XETR:DAX", timeframe.period, close) rsdMinDAX40 = 10. rsdMaxDAX40 = -10. rsdDAX40 = 1. DAX40_detrend = 0. DAX40_detrend := priceNormal_regressParams_to_priceLogRsd(DAX40, -61.6481, 0.0325753) rsdMinDAX40 := smalest(DAX40_detrend, n_bars) rsdMaxDAX40 := biggest(DAX40_detrend, n_bars) rsdDAX40 := DAX40_detrend / ((rsdMaxDAX40 - rsdMinDAX40) + 1) plot(rsdDAX40, color=color.purple, title="DAX40 Germany stkIdx", linewidth=2) // GOLD = request.security("TVC:UKX", timeframe.period, close) // GOLD_detrend = 0. // GOLD_detrend := priceNormal_regressParams_to_priceLogRsd(GOLD, -29.0842, 0.015824, 0.197304) // plot(GOLD_detrend, color=color.orange, title="GOLD long term price", linewidth=2) // rsdMinGOLD = 10. // rsdMaxGOLD = -10. // rsdMinGOLD := smalest(GOLD_detrend, n_bars) // rsdMaxGOLD := biggest(GOLD_detrend, n_bars) // 14Apr2023 garbage inputs for HSSSC taken from GOLD!!! // HSSSHSC300 = request.security("HSI:HSSSHSC", timeframe.period, close) // HSSSHSC300_detrend = 0. // HSSSHSC300_detrend := priceNormal_regressParams_to_priceLogRsd(HSSSHSC300, -175.9000, -0.085201, 0.028966, 0.007881) // plot(HSSSHSC300_detrend, color=color.green, title="HSSSHSC300 China Shanghai-Shenzen-Hong Kong stkIdx", linewidth=2) // rsdMinHSSSHSC300 = 10. // rsdMaxHSSSHSC300 = -10. // rsdMinHSSSHSC300 := smalest(HSSSHSC300_detrend, n_bars) // rsdMaxHSSSHSC300 := biggest(HSSSHSC300_detrend, n_bars) INDIA50 = request.security("Vantage:INDIA50", timeframe.period, close) rsdMinINDIA50 = 10. rsdMaxINDIA50 = -10. rsdINDIA50 = 1. INDIA50_detrend = 0. INDIA50_detrend := priceNormal_regressParams_to_priceLogRsd(INDIA50, -61.6481, 0.0325753) rsdMinINDIA50 := smalest(INDIA50_detrend, n_bars) rsdMaxINDIA50 := biggest(INDIA50_detrend, n_bars) rsdINDIA50 := INDIA50_detrend / ((rsdMaxINDIA50 - rsdMinINDIA50) + 1) plot(rsdINDIA50, color=color.rgb(200, 100, 100, 0), title="INDIA50 nifty fifty stkIdx", linewidth=2) NI225 = request.security("TVC:NI225", timeframe.period, close) rsdMinNI225 = 10. rsdMaxNI225 = -10. rsdNI225 = 1. NI225_detrend = 0. NI225_detrend := priceNormal_regressParams_to_priceLogRsd(NI225, -61.6481, 0.0325753) rsdMinNI225 := smalest(NI225_detrend, n_bars) rsdMaxNI225 := biggest(NI225_detrend, n_bars) rsdNI225 := NI225_detrend / ((rsdMaxNI225 - rsdMinNI225) + 1) plot(rsdNI225, color=color.rgb(250, 200, 30, 0), title="NI225 Japan stkIdx", linewidth=2) // SHCOMP is no longer available live via TradingView // I included it in with my QNial programs (I have historical), // in which all code was initially developed, then adapted to PineScript // SHCOMP = request.security("TVC:SHCOMP", timeframe.period, close) // SHCOMP_detrend = 0. // SHCOMP_detrend := priceNormal_regressParams_to_priceLogRsd(SHCOMP, constant, slope, relStdDev) // plot(SHCOMP_detrend, color=color.darkgreen, title="SHCOMP China Shanghai-Shenzen-Hong Kong stkIdx", linewidth=2) // rsdMinSHCOMP = 10. // rsdMaxSHCOMP = -10. // rsdMinSHCOMP := smalest(SHCOMP_detrend, n_bars) // rsdMaxSHCOMP := biggest(SHCOMP_detrend, n_bars) // special setup for multi-segment regressions // 12Aug2022 may have a problem with detrends within if? SPX500 = request.security("TVC:SPX", timeframe.period, close) rsdMinSPX500Lo = 10. rsdMaxSPX500Lo = -10. rsdSPX500Lo = 1. SPX500Lo_detrend = 0. if year_fraction <= 1940.06 // yrFrac regressions [1872-1940] SPX500Lo_detrend := priceNormal_regressParams_to_priceLogRsd(SPX500, -14.9701, 0.00830613) rsdMinSPX500Lo := smalest(SPX500Lo_detrend, n_bars) rsdMaxSPX500Lo := biggest(SPX500Lo_detrend, n_bars) rsdSPX500Lo := SPX500Lo_detrend / ((rsdMaxSPX500Lo - rsdMinSPX500Lo) + 1) plot(rsdSPX500Lo, color=color.blue, title="SPX500Lo stkIdx 1871-1940", linewidth=2) rsdMinSPX500Hi = 10. rsdMaxSPX500Hi = -10. rsdSPX500Hi = 1. SPX500Hi_detrend = 0. if year_fraction > 1940.06 // yrFrac regressions [1872-1940] SPX500Hi_detrend := priceNormal_regressParams_to_priceLogRsd(SPX500, -56.7736, 0.0298315) rsdMinSPX500Hi := smalest(SPX500Hi_detrend, n_bars) rsdMaxSPX500Hi := biggest(SPX500Hi_detrend, n_bars) rsdSPX500Hi := SPX500Hi_detrend / ((rsdMaxSPX500Hi - rsdMinSPX500Hi) + 1) plot(rsdSPX500Hi, color=color.blue, title="SPX500 USA stkIdx 1926-2022", linewidth=2) // DON'T take log of interest rates! but invert them with respect to stock indexes // TNX = request.security("TVC:TNX", timeframe.period, close) // TNX_detrend = 0. // TNX_detrend := priceNormal_regressParams_to_priceLogRsd(TNX, -0.1025, 210.209000, 0.201597) // plot(TNX_detrend, color=color.red, title="TNX 10yr T-bond USA", linewidth=2) // rsdMinTNX = 10. // rsdMaxTNX = -10. // rsdMinTNX := smalest(TNX_detrend, n_bars) // rsdMaxTNX := biggest(TNX_detrend, n_bars) // USOIL = request.security("TVC:UKX", timeframe.period, close) // USOIL_detrend = 0. // USOIL_detrend := priceNormal_regressParams_to_priceLogRsd(USOIL, -25.517, 0.0145591, 0.0245999) // plot(USOIL_detrend, color=color.black, title="USOIL long term price", linewidth=2) // rsdMinUSOIL = 10. // rsdMaxUSOIL = -10. // rsdMinUSOIL := smalest(USOIL_detrend, n_bars) // rsdMaxUSOIL := biggest(USOIL_detrend, n_bars) UKX100 = request.security("TVC:UKX", timeframe.period, close) rsdMinUKX100 = 10. rsdMaxUKX100 = -10. rsdUKX100 = 1. UKX100_detrend = 0. UKX100_detrend := priceNormal_regressParams_to_priceLogRsd(UKX100, -61.6481, 0.0325753) rsdMinUKX100 := smalest(UKX100_detrend, n_bars) rsdMaxUKX100 := biggest(UKX100_detrend, n_bars) rsdUKX100 := UKX100_detrend / ((rsdMaxUKX100 - rsdMinUKX100) + 1) plot(rsdUKX100, color=color.rgb(200, 150, 250, 0), title="UKX100 long term stkIdx", linewidth=2) // FRED:WLFN - Federal Reserve, Liabilities and Capital // WLFN = request.security("FRED:WLFN", timeframe.period, close) // WLFN_detrend = 0. // WLFN_detrend := priceNormal_regressParams_to_priceLogRsd(WLFN, -61.6481, 0.0325753, 0.0351671) // plot(WLFN_detrend, color=color.green, title="WLFN Fed Liabilities, Capital", linewidth=2) // rsdMinWLFN = 10. // rsdMaxWLFN = -10. // rsdMinWLFN := smalest(WLFN_detrend, n_bars) // rsdMaxWLFN := biggest(WLFN_detrend, n_bars) // Overall priceRsd[Min, Max] over full length of t_timelength // adjust the symbolList according to selections above priceRsdMin = 10.0 priceRsdMax = -10.0 priceRsdMin := rsdMinSPX500Lo priceRsdMax := rsdMaxSPX500Hi priceRsdMin := math.min(rsdMinDAX40, rsdMinINDIA50, rsdMinNI225, rsdMinSPX500Lo, rsdMinSPX500Hi, rsdMinUKX100) // later rsdMinTNX, priceRsdMax := math.max(rsdMaxDAX40, rsdMaxINDIA50, rsdMaxNI225, rsdMaxSPX500Lo, rsdMaxSPX500Hi, rsdMaxUKX100) // later rsdMaxTNX, #08********08 #] 17Apr2023 fix priceFrac horizontal lines (they aren't plotted) AGAIN, I give up on PineScript - not made for any complexity Change : DAX40_detrend := priceNormal_regressParams_to_priceLogRsd(DAX40, -61.6481, 0.0325753, 0.0351671) To : DAX40_detrend := priceNormal_regressParams_to_priceLogRsd(DAX40, -61.6481, 0.0325753, 0.0351671, rsdMinDAX40, rsdMaxDAX40) +-----+ olde code // 03Jun2022 new "table" functions are not very good yet! // better this simple approach mat_write(string matTitle, matrix matSymbol, int n_bars, int barRightShift, float serPrice, float txtLineHeight) => rows = matrix.rows(matSymbol) cols = matrix.columns(matSymbol) rowStr = "" num = 10.0 y_offset = 0.0 y_offset := -6*txtLineHeight // barFirst_label(float barFractionFrmRight, float serPrice, float priceOffset, string txt) => barFirst_label(0.75, serPrice, y_offset, matTitle) for iRow = 0 to (rows - 1) rowStr := "" for iCol = 0 to (cols - 1) num := matrix.get(matSymbol, iRow, iCol) rowStr := rowStr + str.tostring(num, '#.000') + " " y_offset := float(-(iRow + 7)*txtLineHeight) barFirst_label(0.75, serPrice, y_offset, rowStr) // INDIA50_detrend = 0. // INDIA50_detrend := priceNormal_regressParams_to_priceLogRsd(INDIA50, 0.070385) // plot(INDIA50_detrend, color=color.rgb(200, 100, 100, 0), title="", linewidth=2) // rsdMinINDIA50 = 10. // rsdMaxINDIA50 = -10. // rsdMinINDIA50 := smalest(INDIA50_detrend, n_bars) // rsdMaxINDIA50 := biggest(INDIA50_detrend, n_bars) rsdMinINDIA50 := smalest(INDIA50, n_bars) rsdMaxINDIA50 := biggest(INDIA50, n_bars) rsdDelINDIA50 := rsdMaxINDIA50 - rsdMinINDIA50 INDIA50_detrend := priceNormal_regressParams_to_priceLogRsd(INDIA50, -96.3589, 0.0497382, rsdDelINDIA50) plot(INDIA50_detrend, color=color.rgb(200, 100, 100, 0), title="INDIA50 nifty fifty stkIdx", linewidth=2) // NI225_detrend = 0. // NI225_detrend := priceNormal_regressParams_to_priceLogRsd(NI225, -1.66838, 0.00291729, 0.0341034) // plot(NI225_detrend, color=color.rgb(250, 200, 30, 0), title="NI225 Japan stkIdx", linewidth=2) // rsdMinNI225 = 10. // rsdMaxNI225 = -10. // rsdMinNI225 := smalest(NI225_detrend, n_bars) // rsdMaxNI225 := biggest(NI225_detrend, n_bars) rsdMinNI225 := smalest(NI225, n_bars) rsdMaxNI225 := biggest(NI225, n_bars) rsdDelNI225 := rsdMaxNI225 - rsdMinNI225 NI225_detrend := priceNormal_regressParams_to_priceLogRsd(NI225, -1.66838, 0.00291729, rsdDelNI225) plot(NI225_detrend, color=color.rgb(250, 200, 30, 0), title="NI225 Japan stkIdx", linewidth=2) rsdMinSPX500Lo := smalest(SPX500, n_bars) rsdMaxSPX500Lo := biggest(SPX500, n_bars) rsdDelSPX500Lo := rsdMaxSPX500Lo - rsdMinSPX500Lo if year_fraction <= 1940.06 // yrFrac regressions [1872-1940] SPX500Lo_detrend := priceNormal_regressParams_to_priceLogRsd(SPX500, -14.9701, 0.00830613, rsdDelSPX500Lo) plot(SPX500Lo_detrend, color=color.blue, title="SPX500Lo stkIdx 1871-1940", linewidth=2) rsdMinSPX500Hi := smalest(SPX500, n_bars) rsdMaxSPX500Hi := biggest(SPX500, n_bars) rsdDelSPX500Hi := rsdMaxSPX500Hi - rsdMinSPX500Hi if year_fraction >= 1940.06 // yrFrac regressions [1926-2022, 1938-2022] SPX500Hi_detrend := priceNormal_regressParams_to_priceLogRsd(SPX500, -56.7736, 0.0298315, rsdDelSPX500Hi) plot(SPX500Hi_detrend, color=color.blue, title="SPX500 USA stkIdx 1926-2022", linewidth=2) UKX100_detrend = 0. UKX100_detrend := priceNormal_regressParams_to_priceLogRsd(UKX100, -25.517, 0.0145591, 0.0245999) plot(UKX100_detrend, color=color.rgb(200, 150, 250, 0), title="", linewidth=2) rsdMinUKX100 = 10. rsdMaxUKX100 = -10. rsdMinUKX100 := smalest(UKX100_detrend, n_bars) rsdMaxUKX100 := biggest(UKX100_detrend, n_bars) rsdMinUKX100 := smalest(UKX100, n_bars) rsdMaxUKX100 := biggest(UKX100, n_bars) rsdDelUKX100 := rsdMaxUKX100 - rsdMinUKX100 UKX100_detrend := priceNormal_regressParams_to_priceLogRsd(UKX100, -1.66838, 0.00291729, rsdDelUKX100) plot(UKX100, color=color.rgb(200, 150, 250, 0), title="UKX100 long term stkIdx", linewidth=2) #08********08 #] 17Apr2023 try old version of PuetzUWS IntlStkIdxs multi-fractals "$d_web"'CompLangs/PineScript/z_Archive/220614 13h00m10s Howell - PuetzUWS [time, price] multiFractal mirrors, SPX 1872-2020.txt' indicator(title="PuetzUWS [time, price] multiFractal mirrors, SPX 1872-2020", shorttitle="PuetzUWS 1872-2020 fractal mirrors", overlay=true) >> works well, but horizontal lines : missing lower bound not produced for priceFrac < 0 use [early version, diff] to fix current version renamed : $ path2="$d_web"'CompLangs/PineScript/PuetzUWS IntlStkIdxs multi-fractals.txt' $ pDif2="$d_temp"'PuetzUWS IntlStkIdxs diff2.txt' $ diff "$path2" "$path1" --suppress-common-lines | grep --invert-match "[,cd-]" | sed 's/< //;s/> //' >"$pDif2" >> reverse view NUTS - both diffs essentially the same, nothing substantial in diffs diff is almost useless (or the way that I am using it) Change : +-----+ priceNormal_regressParams_to_priceNormalRsd(priceNormal, constant, slope, relStdDev, yrStrtRegr) => priceNormalTrend = constant + slope * (year_fraction - yrStrtRegr) (priceNormal / priceNormalTrend - 1) / relStdDev priceNormal_regressParams_to_priceSemilogRsd(priceNormal, constant, slope, relStdDev, yrStrtRegr) => priceLogTrend = constant + slope * (year_fraction - yrStrtRegr) (math.log(priceNormal) / priceLogTrend - 1) / relStdDev priceNormalRsd_to_priceNormal(priceNormalRsd, constant, slope, relStdDev, yrStrtRegr) => priceLogTrend = constant + slope * (year_fraction - yrStrtRegr) priceLogTrend * ((priceNormalRsd * relStdDev) + 1) priceSemilogRsd_to_priceNormal(priceSemilogRsd, constant, slope, relStdDev, yrStrtRegr) => priceLogTrend = constant + slope * (year_fraction - yrStrtRegr) math.pow(10, priceLogTrend * ((priceSemilogRsd * relStdDev) + 1)) +-----+ To : +-----+ priceNormal_regressParams_to_priceNormalRsd(priceNormal, constant, slope, relStdDev, yrStrtRegr) => priceNormalTrend = math.power(10, constant + slope * (year_fraction - yrStrtRegr)) (priceNormal / priceNormalTrend - 1) / relStdDev priceNormalRsd_to_priceNormal(priceNormalRsd, constant, slope, relStdDev, yrStrtRegr) => priceLogTrend = math.power(10, constant + slope * (year_fraction - yrStrtRegr)) priceLogTrend * ((priceNormalRsd * relStdDev) + 1) // priceSemilogRsd should NOT be used? priceNormal_regressParams_to_priceSemilogRsd(priceNormal, constant, slope, relStdDev, yrStrtRegr) => priceLogTrend = math.power(10, constant + slope * (year_fraction - yrStrtRegr)) math.log( (priceNormal / priceLogTrend - 1) / relStdDev priceSemilogRsd_to_priceNormal(priceSemilogRsd, constant, slope, relStdDev, yrStrtRegr) => priceLogTrend = math.power(10, constant + slope * (year_fraction - yrStrtRegr)) math.pow(10, priceLogTrend * ((priceSemilogRsd * relStdDev) + 1)) +-----+ Oops - now output is 10^58!!! Back to : priceNormal_regressParams_to_priceNormalRsd(priceNormal, constant, slope, relStdDev, yrStrtRegr) => priceNormalTrend = constant + slope * (year_fraction - yrStrtRegr) (priceNormal / priceNormalTrend - 1) / relStdDev priceNormalRsd_to_priceNormal(priceNormalRsd, constant, slope, relStdDev, yrStrtRegr) => priceLogTrend = constant + slope * (year_fraction - yrStrtRegr) priceLogTrend * ((priceNormalRsd * relStdDev) + 1) >> now back to (0 -1000), inverted graph priceNormal_regressParams_to_priceLogRsd(priceNormal, constant, slope, relStdDev, yrStrtRegr) => priceLogTrend = constant + slope * (year_fraction - yrStrtRegr) (math.log(priceNormal) / priceLogTrend - 1) / relStdDev priceLogRsd_to_priceNormal(priceLogRsd, constant, slope, relStdDev, yrStrtRegr) => priceLogTrend = constant + slope * (year_fraction - yrStrtRegr) math.pow(10, priceLogTrend * ((priceLogRsd * relStdDev) + 1)) >> now back to where I started : SP500 at -12.25!??? What about yrStrtRegr? SPX500Hi_detrend := priceNormal_regressParams_to_priceLogRsd(SPX500, -56.7736, 0.0298315, 0.0937853, 1926.06) >> NUTS!!! arg1 not symbol, but base year!!! >> NYET! - SP500 - is the closing price CRAP! PiceScriopt : math.log is NATURAL logarithm math.log10 is log base 10 >> same problem now t -11.35 manual calc see /home/bill/web/Qnial/MY_NDFS/economics, markets/230417 priceNormal_regressParams_to_priceLogRsd.ndf priceNormal_regressParams_to_priceLogRsd IS OP priceNormal constant slope relStdDev yrStrtRegr { priceLogTrend := constant + (slope * (year_fraction - yrStrtRegr)) ; ((log priceNormal) / priceLogTrend) - 1) / relStdDev } # priceNormal_regressParams_to_priceLogRsd 2022.0 -14.9701 0.00830613 0.122382 1871.22 constant : I was using +14.9701 instead of -14.9701!! BUT - should have been using 1926-2022 parameters, not 1871-194!! Change to : priceNormal_regressParams_to_priceLogRsd(priceNormal, constant, slope, relStdDev, yrStrtRegr) => expnt = constant + slope * (year_fraction - yrStrtRegr) priceTrend = math.pow(10, expnt) (priceNormal / priceTrend - 1) / relStdDev "$d_Qmkts"'market symbol [regressSL, detrend].ndf' 'market tblWhole.dat' : >> yTrn are "log "$d_web"'CompLangs/PineScript/z_Archive/220614 13h00m10s Howell - PuetzUWS [time, price] multiFractal mirrors, SPX 1872-2020.txt' // for 1871-1926 =10^( 0.784617 + (0.000140925*(x - 1871.08))) calc_SP500Trend(y_fraction) => expnt = 0.792392+0.0289587*(y_fraction - 1926.25) SP500base = math.pow(10,expnt) but now are : if year_fraction <= 1940.06 // yrFrac regressions [1872-1940] SPX500Lo_detrend := priceNormal_regressParams_to_priceLogRsd(-14.9701, 0.00830613, 0.122382, 1871.22) if year_fraction >= 1926.06 // yrFrac regressions [1926-2022, 1938-2022] SPX500Hi_detrend := priceNormal_regressParams_to_priceLogRsd(SPX500, -56.7736, 0.0298315, 0.0937853, 1926.06) Mistake? - double log maybe? priceNormal_regressParams_to_priceLogRsd_fix IS OP year_fraction priceNormal constant slope relStdDev yrStrtRegr { % priceLogTrend := power 10 (constant + (slope * (year_fraction - yrStrtRegr))) ; priceLogTrend := constant + (slope * (year_fraction - yrStrtRegr)) ; write priceLogTrend ; ((priceNormal / priceLogTrend) - 1) / relStdDev } priceHiFix IS OP year_fraction priceNormal { priceNormal_regressParams_to_priceLogRsd_fix year_fraction priceNormal -56.7736 0.0298315 0.0937853 1926.06 } # qnial> EACH priceHiFix (2022.079 4795.490) (2000.721 1430.830) (1988.721 272.020) (1980.308 112.950) (1956.389 48.700) (1933.470 8.870) -11.3907 -11.2795 -11.1355 -11.0595 -10.9847 -10.8414 qnial> loaddefs link d_Qndfs 'economics, markets/230417 priceNormal_regressParams_to_priceLogRsd.ndf' qnial> 00.721 1430.830) (1988.721 272.020) (1980.308 112.950) (1956.389 48.700) (1933.470 8.870) -53.9092 -54.5464 -54.9043 -55.1553 -55.8688 -56.5525 -959.158 -290.359 -63.4901 -32.4982 -19.9571 -12.335 >> OK, so my regressions put out LINEAR (normal) priceTrend >> sign is WRONG!!! Change : priceNormal_regressParams_to_priceLogRsd(priceNormal, constant, slope, relStdDev, yrStrtRegr) => expnt = constant + slope * (year_fraction - yrStrtRegr) priceTrend = math.pow(10, expnt) (priceNormal / priceTrend - 1) / relStdDev To : priceNormal_regressParams_to_priceLogRsd(priceNormal, constant, slope, relStdDev, yrStrtRegr) => priceTrend = constant + slope * (year_fraction - yrStrtRegr) (priceNormal / priceTrend - 1) / relStdDev But chart back to -1000 pricing instead of -1 to 1 or something like that, inverted must have double-correcvtion somewhere? >> I was plotting 1871-1940 by left-over mixup : plot(SPX500Lo_detrend, color=color.rgb(100, 100, 255, 0), title="SPX500 USA stkIdx 1871-1940") Change : priceLogTrend := constant + (slope * (year_fraction - yrStrtRegr)) ; To : priceLogTrend := constant + (slope * (year_fraction - yrStrtRegr)) ; "$d_Qndfs" 'fit_linearRegress.ndf' : +--+ yTrn_paramL_SLRgress_xyTrnEstL IS OP yTrn paramLabelStr xTrnPhr xUnTrnPhr yTrnPhr yUnTrnPhr slope constant >> slope first, then constant? +--+ fit_SLRgress IS OP symName xObs yObs xTrnPhr yTrnPhr povr returns constant slope relStdDevObs relStdDevTrn xObsMin xObsMax yObsMin yObsMax yDetrendMin yDetrendMax # qnial> fit_SLRgress xObs yObs "pass "log (link d_temp 'fit_SLRgress quick test.txt') -56.7736 0.0298315 0.333903 0.0937853 1926.06 2022.13 4.77 4804.51 0.910925 1.29852 >> OK -56.7736 0.0298315 are constant slope priceNormal_regressParams_to_priceLogRsd(priceNormal, constant, slope, relStdDev, yrStrtRegr) => priceTrend = power 10 (constant + slope * year_fraction) (priceNormal / priceTrend - 1) / relStdDev >> OK PineScript chart looks OK, but missing fracGrid < 0 NOW, add plots of other stock indices >> similar scaling problem for others? +-----+ olde code // over a "segment" of time for symbols with multiple segments // priceNormal_regressParams_to_priceLogRsd(priceNormal, constant, slope, relStdDev, yrStrtRegr) => // expnt = constant + slope * (year_fraction - yrStrtRegr) // priceTrend = math.pow(10, expnt) // (priceNormal / priceTrend - 1) / relStdDev // priceLogRsd_to_priceNormal(priceLogRsd, constant, slope, relStdDev, yrStrtRegr) => // expnt = constant + slope * (year_fraction - yrStrtRegr) // priceTrend = math.pow(10, expnt) // math.pow(10, priceLogTrend * ((priceLogRsd * relStdDev) + 1)) // price[Min, Max] over full length of t_timelength, txtLineHeight // only used for placing labels on chart // 23May2022 do NOT declare with 'var'!!! : priceMin = smalest(close, n_bars) priceMax = biggest(close, n_bars) // priceLabel := priceRsdMax - 2*txtLineHeight simple_label(bar_2_3rds, priceLabel, "priceMin = " + str.tostring(priceMin)) simple_label(bar_1_half, priceLabel, "priceMax = " + str.tostring(priceMax)) simple_label(bar_1_qrtr, priceLabel, "midIdx = " + str.tostring(midIdx)) >> it's working fairly well right now. I should stop after fixing priceFrac horizontal lines // priceRsdMin := math.min(rsdMinDAX40, rsdMinINDIA50, rsdMinNI225, rsdMinSPX500Lo, rsdMinSPX500Hi, rsdMinUKX100) // later rsdMinTNX, // priceRsdMax := math.max(rsdMaxDAX40, rsdMaxINDIA50, rsdMaxNI225, rsdMaxSPX500Lo, rsdMaxSPX500Hi, rsdMaxUKX100) // later rsdMaxTNX, #08********08 #] 16Apr2023 what has changed in the code? 'PuetzUWS IntlStkIdxs multi-fractals (version 2).txt' "$d_web"'CompLangs/PineScript/230414 10h57m PuetzUWS IntlStkIdxs multi-fractals (version 2).txt' $ path1="$d_web"'CompLangs/PineScript/230414 10h57m PuetzUWS IntlStkIdxs multi-fractals (version 2).txt' $ path2="$d_web"'CompLangs/PineScript/PuetzUWS IntlStkIdxs multi-fractals (version 2).txt' $ pDif="$d_temp"'PuetzUWS IntlStkIdxs diff.txt' $ diff "$path1" "$path2" --suppress-common-lines | grep --invert-match "[,cd-]" | sed 's/< //;s/> //' >"$pDif" >> no real diff $ path1="$d_web"'CompLangs/PineScript/220721 07h08m Howell - PuetzUWS [time, price] multiFractal mirrors, SPX 1872-2020.txt' >> no diff? $ path1="$d_web"'CompLangs/PineScript/z_Archive/220614 13h00m10s Howell - PuetzUWS [time, price] multiFractal mirrors, SPX 1872-2020.txt' >> OK, many differences, look at next day I work on this // priceSemilogRsd should NOT be used? // calculate priceNormal from [priceNormalRsd, priceSemilogRsd] // derivation of priceSemilogRsd_to_priceNormal : // priceLogTrend = constant + slope * (year_fraction - yrStrtRegr) // priceNormalRsd = (math.log(priceNormal) / priceLogTrend - 1) / relStdDev // (math.log(priceNormal) / priceLogTrend - 1) = priceNormalRsd * relStdDev // math.log(priceNormal) / priceLogTrend ) = (priceNormalRsd * relStdDev) + 1 // math.log(priceNormal) = priceLogTrend * ((priceNormalRsd * relStdDev) + 1) // priceNormal = math.pow(10, priceLogTrend * ((priceNormalRsd * relStdDev) + 1)) // // priceNormal_regressParams_to_priceSemilogRsd(priceNormal, constant, slope, relStdDev, yrStrtRegr) => // priceLogTrend = constant + slope * (year_fraction - yrStrtRegr) // (math.log(priceNormal) / priceLogTrend - 1) / relStdDev // // // priceSemilogRsd_to_priceNormal(priceSemilogRsd, constant, slope, relStdDev, yrStrtRegr) => // priceLogTrend = constant + slope * (year_fraction - yrStrtRegr) // math.pow(10, priceLogTrend * ((priceSemilogRsd * relStdDev) + 1)) #08********08 #] 15Apr2023 why doesn't PineScript work?: 'PuetzUWS IntlStkIdxs multi-fractals (version 2).txt' "$d_web"'CompLangs/PineScript/PuetzUWS IntlStkIdxs multi-fractals (version 2).txt' +-----+ ln instead of log? myet - log is specified as "yTrnPhrL in : "$d_web"'Qnial/MY_NDFS/economics, markets/' : market symbol header.ods market tblWhole.dat +-----+ what now? #08********08 #] 15Apr2023 revamp symbol names: "$d_web"'economics, markets' 'CADUSD Jun1987-Sep2022 TradingView' 'CAEXP Jan1971-Jul2022 TradingView' 'CAGDP Dec1960-Sep2022 TradingView' ... etc geany regexpr search : ^(['a-zA-Z0-9]* )[a-zA-Z0-9\-]* ([a-zA-Z0-9,']*) replace \1\2 'CADUSD TradingView' 'CAEXP TradingView' 'CAGDP TradingView' ... etc geany regexpr search : ^(['a-zA-Z0-9]*) (.*) replace \1\' 'CADUSD' 'CAEXP' ... etc geany regexpr search : ^(['a-zA-Z0-9]*) (.*) replace \'\2 'TradingView' ... etc geany regexpr search : ^(['a-zA-Z0-9]* )([a-zA-Z0-9\-]*) ([a-zA-Z0-9,']*) replace \'\2\' doesn't quite work, manual corrections 'Jun1987-Sep2022' 'Jan1971-Jul2022' ... etc #08********08 #] 14Apr2023 Background tables for SP500 detrended Puetz [time, price] multifractals SP500 semiLog trendline 1926-2022 : 10 power (-56.7736 + (0.029831 * year)) year fraction 2000.0 2005.0 2010.0 2015.0 2022.0 2022.5 2022.75 2023.0 2025 2030 2040 2050 SP500 price 773 1090 1537 2167 3505 3627 3690 3754 4307 6071 12,068 23,985 Fibonacci [0.000 0.236 0.382 0.500 0.618 0.786 1.000] Puetz 1st level [0.000 0.333 0.666 1.000] Puetz mix [0.000 0.222 0.333 0.500 0.666 0.777 1.000] Puetz half-wave [0.000 0.167 0.333 0.500 0.666 0.833 1.000] # enddoc