#] #] ********************* #] loaddefs link d_Qndfs 'gnuplot via subFiles.ndf' - daisy-chained subFiles #] example : for detrended [time, price] multi-fractals, # www.BillHowell.ca 28Jul2022 initial from previous code # view this file in a text editor, with [constant width font, tab = 3 spaces], no line-wrap # related ndf files : "$d_Qndfs"'fit_linearRegress.ndf' "$d_Qmkts"'stock index semi-log [regression, plot]s.ndf' "$d_Qndfs"'gnuplot via subFiles.ndf' "$d_Qmkts"'220730 Puetz2011 detrended international indexes, gnuplot specs.ndf' # see also symbol_regressPlot_pPng in # "$d_Qmkts"'stock index semi-log [regression, plot]s.ndf' # massive use of global variables!! #24************************24 f_loadPuetzPlt := 'gnuplot via subFiles.ndf' ; loaddefs_start f_loadPuetzPlt ; #24************************24 # Table of Contents is in "$d_Qndfs"'gnuplot header.ndf', for ease of use while working here #24************************24 # Setup (kind of like header info) loaddefs link d_Qndfs 'gnuplot header.ndf' ; #24************************24 # Coding #08********08 #] +-----+ #] create independent pSubs : IF flag_debug THEN write '+-----+' ; ENDIF ; IF flag_debug THEN write 'create independent pSubs : ' ; write 'includes (pTmplt pWrdChg pTimeFracs pPriceFracs pParams pLinSty pCurves pPlt pPng)' ; ENDIF ; # loaddefs link d_Qmkts 'Puetz detrended specs.ndf' IF flag_debug THEN write 'loading pTmplt_insert_pWrdChg' ; ENDIF ; #] pTmplt_insert_pWrdChg IS OP symL - paramTbl sed into gnuplot template #] example symShortL = [DAX40, INDIA50, NI225, SP500, UKX100] # 06Aug2022 initial - like similar optr in # "$d_Qmkts"'stock index semi-log [regression, plot]s.ndf' # 15Aug2022 also serves as an example for other projects pTmplt_insert_pWrdChg IS OP symL { LOCAL cmd pPng pTmplt terminal datafile_separator title xlabel ylabel xRange xtics yRange ytics ; NONLOCAL d_work pWrdChg strUWS yrEnd yrStrt ; % ; symShortL := ?????????????????? symL ; % pPng MUST be from the same formula throughout the project!!! ; pTmplt := link d_Qndfs 'gnuplot via subFiles - template.plt' ; pPng := link d_work 'detrend ' symShortL ' ' strUWS '.png' ; % ; terminal := 'pngcairo enhanced font \"arial,10\" fontscale 1.0 size 1400, 400' ; % tab as column separator -> "{\t}", as comma -> "{,}", "{whitespace}" ; datafile_separator := '"{\\t}"' ; % ; title := link '{/:Bold ' strUWS ' [time, price] multi-fractals, detrended international stock market indices : [DAX40, INDIA50, NI225, SP500, UKX100]}\\n {/: for [data, software, regression coefficients, plots, etc] see http://www.BillHowell.ca/economics, markets/SP500/PuetzUWS intnl stocks/}' ; xlabel := '' ; ylabel := 'Detrended market symbol index, closing or average price' ; % ; % adjust for different strDateRange! ; % yrStrt yrEnd yrZero xtics ytics yRange ; yrStrt yrEnd := 1860 2040 ; xtics := 20 ; ytics := '-3, -2, -1, 0.0, 1, 2, 3, 4' ; yRange := ' -3. : 4. ' ; yLow yHigh := -3. 4. ; % ; % sed variables are listed in order of occurence in pTmplt ; cmd := link 'cat "' pTmplt '" | sed ' chr_apo 's||' pPng '|;s||' terminal '|;s||' datafile_separator '|;s||' title '|;s|<xlabel>|' xlabel '|;s|<ylabel>|' ylabel '|;s|<yrStrt>|' (string yrStrt) '|;s|<yrEnd>|' (string yrEnd) '|;s|<xtics>|' (string xtics) '|;s|<yRange>|' yRange '|;s|<ytics>|' ytics '|' chr_apo ' >"' pWrdChg '" ' ; write cmd ; host cmd ; } # pTmplt_insert_pWrdChg 'CUS2 May2006-Aug2022 TradingView' # olde code LOCAL yLow yHigh yrZero yrP := yrStrt yrEnd ; yrZero := 1929.75 ; '|;s|<noteL>|' noteL # loaddefs link d_Qndfs 'gnuplot via subFiles.ndf' IF flag_debug THEN write 'loading noteL_create_pNotes' ; ENDIF ; #] noteL_create_pNotes IS - create a gnuplot subFile from noteL # 28Jul2022 initial noteL_create_pNotes IS { LOCAL fout i note ; NONLOCAL pNotes ; % ; noteL := 'yDetrend = (yTrn/yEstTrn - 1) / relStdDevTrn (Trn = log transformation of [y])' 'yTrend = 10 power (<constant> + <slope> * yr) (normal, not log, yTrend)' 'price [equilibrium, revolution] cross greatly influences results (eg SP500 OR[1926, 1938]-2022)' (link 'date graphed: ' timestamp_DDMMMYYYY) ; fout := open pNotes "w ; i := 0 ; FOR note WITH noteL DO writefile fout (link chr_tab 'set label ' (string (i + 1)) ' "{' note '}" at graph 0.01, ' (string (0.95 - (0.05 * i))) ' textcolor "black"') ; i := i + 1 ; ENDFOR ; close fout ; } # loaddefs link d_Qndfs 'gnuplot via subFiles.ndf' IF flag_debug THEN write 'loading timeFracLL_create_pTimeFracs' ; ENDIF ; #] timeFracLL_create_pTimeFracs IS OP timeFracLL - #] create a gnuplot subFile of timeFracs (time fractal, vertical lines) # 28Jul2022 initial timeFracLL_create_pTimeFracs IS OP timeFracLL { LOCAL fout idxLL timeFrac timeFracL ; NONLOCAL pTimeFracs colorSpikeL lwSpikeL ; % ; fout := open pTimeFracs "w ; FOR idxLL WITH (tell (gage shape timeFracLL )) DO timeFracL := timeFracLL@idxLL ; FOR timeFrac WITH timeFracL DO writefile fout (link chr_tab 'set arrow from ' (string timeFrac) ', -3.0 to ' (string timeFrac) ', 6.0 nohead lw ' (string lwSpikeL@idxLL) ' linecolor "' colorSpikeL@idxLL '"') ; ENDFOR ; ENDFOR ; close fout ; } # timeFracLL_create_pTimeFracs timeFracLL # tests : # timeFracLL_create_pTimeFracs ( (1872.73 1879.06 1885.4 1891.73 1898.07 1904.41 1910.74 1917.08 1923.41 1929.75 1936.09 1942.42 1948.76 1955.09 1961.43 1967.77 1974.1 1980.44 1986.77 1993.11 1999.44 2005.78 2012.12 2018.45) (1872.73 1891.73 1910.74 1929.75 1948.76 1967.77 1986.77 2005.78) (1872.73 1929.75 1986.77) [1929.75] [1929.75] ) # timeFracLL_create_pTimeFracs ( (1878.63 1891.41 1904.19 1916.97 1929.75 1942.53 1955.31 1968.09 1980.87 1993.65 2006.43 2019.21) (1891.42 1929.75 1968.08 2006.41) [1929.75] [1929.75] [1929.75] ) # loaddefs link d_Qndfs 'gnuplot via subFiles.ndf' IF flag_debug THEN write 'loading priceFracLLL_create_pPriceFracs' ; ENDIF ; #] priceFracLLL_create_pPriceFracs IS OP priceFracLLL - create a subfile of horizontal gridLines #] gnuplot detrended price fractal gridLines # 30Jul2022 initial priceFracLLL_create_pPriceFracs IS OP priceFracLLL { LOCAL fout frac ffracL fracLL idxLL idxLLL ; NONLOCAL colorPriceL lwPriceL pPriceFracs yrStrt yrEnd ; % ; % priceFracLLL has 2 subLists : [above, below] midIdx ; % must adapt [lwPriceL, colorPriceL]@idxLL to different shapes [above, below] ; % including nulls ; shapes := EACH (gage shape) priceFracLLL ; shapeMax := max shapes ; tellAbove := (tell shapes@0) + (shapeMax - shapes@0) ; tellBelow := (tell shapes@1) + (shapeMax - shapes@1) ; tellShapes := tellAbove tellBelow ; % ; fout := open pPriceFracs "w ; FOR idxLLL WITH (tell (gage shape priceFracLLL)) DO fracLL := priceFracLLL@idxLLL ; tellShape := tellShapes@idxLLL ; IF (~= null fracLL) THEN FOR idxLL WITH (tell (gage shape fracLL )) DO fracL := fracLL@idxLL ; idxLwColor := tellShape@idxLL ; FOR frac WITH fracL DO writefile fout (link chr_tab 'set arrow from ' (string yrStrt) ', ' (string frac) ' to ' (string yrEnd) ', ' (string frac) ' nohead lw ' (string lwPriceL@idxLwColor) ' linecolor "' colorPriceL@idxLwColor '"') ; ENDFOR ; ENDFOR ; ENDIF ; ENDFOR ; close fout ; } # priceFracLLL_create_pPriceFracs priceFracLLL ; # tests : # priceFracLLL_create_pPriceFracs ((0.02 (0.02 0.353333 0.686666) (0.02 0.131111 0.242222 0.353333 0.464444 0.575555 0.686666 0.797777 0.908888 1.13111)) [[null]] ) # priceFracLLL_create_pPriceFracs ( (0 (0 0.333333 0.666666 0.999999) (0 0.111111 0.222222 0.333333 0.444444 0.555555 0.666666 0.777777 0.888888 0.999999 1.22222)) [0 -0.222222] ) # priceFracLLL_create_pPriceFracs ( (0 (0 0.333333 0.666666 0.999999) (0 0.111111 0.222222 0.333333 0.444444 0.555555 0.666666 0.777777 0.888888 0.999999 1.22222)) (0 (0 -0.999999 -0.666666 -0.333333) (0 -1.22222 -0.999999 -0.888888 -0.777777 -0.666666 -0.555555 -0.444444 -0.333333 -0.222222 -0.111111)) ) # loaddefs link d_Qndfs 'gnuplot via subFiles.ndf' IF flag_debug THEN write 'loading paramTbl_create_pParams' ; ENDIF ; #] paramTbl_create_pParams IS - create a gnuplot subFile, regression parameters etc #] create a subFile for placement in .plt files, show up in png plot # 30Jul2022 initial # this is tricky. While params are calculated during regressions etc, # they are loaded from "stable" file 'stock index header.ndf' # which has to be updated via copy-paste from log file '???' # balance between safety and convenience # paramTbl defined in "$d_Qndfs"'economics, markets/stock index header.ndf' paramTbl_create_pParams IS { LOCAL fout i paramPhrTbl paramPicStrL row ; NONLOCAL colorParamCurveL paramTbl pParams ; % ; paramPhrTbl := EACH phrase paramTbl|[, 0 2 3 4 5] ; paramPicStrL := picture paramPhrTbl ; % ; fout := open pParams "w ; i := 0 ; FOR row WITH (rows paramPicStrL) DO row := link chr_tab 'set label ' (string (10 + i)) ' "{/courier=8 ' row '}" at graph 0.01, ' (string (0.40 - (i * 0.05))) ' textcolor "' colorParamCurveL@i '"' ; writefile fout row ; i := i + 1 ; ENDFOR ; close fout ; } # loaddefs link d_Qndfs 'gnuplot via subFiles.ndf' IF flag_debug THEN write 'loading colorLwL_create_pLinSty' ; ENDIF ; #] colorLwL_create_pLinSty IS - create gnuplot subfile, lineStyles #] indirectly uses colorParamCurveL, all curves same thickness etc # 31Jul2022 initial colorLwL_create_pLinSty IS { LOCAL fout i row shaper ; NONLOCAL colorParamCurveL pLinSty symName_dateRangeL ; % ; fout := open pLinSty "w ; shaper := gage shape symName_dateRangeL ; FOR i WITH (tell shaper) DO row := link 'set style line ' (string (100 + i)) ' ps 0 lw 2 lt rgb "' colorParamCurveL@i '"' ; writefile fout row ; ENDFOR ; close fout ; } # loaddefs link d_Qndfs 'gnuplot via subFiles.ndf' IF flag_debug THEN write 'loading paramTbl_create_pCurves' ; ENDIF ; #] paramTbl_create_pCurves IS - create gnuplot subfile of curves #] for placement in .plt files, appear within png plot #] ', \' added to last line must be manually removed!! # 30Jul2022 initial # this is tricky. While params are calculated during regressions etc, # they are loaded from "stable" file 'stock index header.ndf' # which has to be updated via copy-paste from log file '???' # balance between safety and convenience # paramTbl defined in "$d_Qndfs"'economics, markets/stock index header.ndf' paramTbl_create_pCurves IS { LOCAL colYr_colDetrend fout i row shaper ; NONLOCAL d_work colorParamCurveL pCurves symName_dateRangeL ; % ; % [colYr, colDetrend] MUST be the same throughout the project!!! ; colYr_colDetrend := '1:9' ; shaper := gage shape symName_dateRangeL ; strCurveL := shaper reshape [null] ; FOR i WITH (tell shaper) DO strCurveL@i := link chr_tab chr_apo d_work 'semi-log ' symName_dateRangeL@i ' regression fit.txt' chr_apo ' using ' colYr_colDetrend ' w lp ls ' (string (100 + i)) ', \' ; ENDFOR ; strCurveL@(shaper - 1) := 3 dropright strCurveL@(shaper - 1) ; strCurveL := link ['plot \'] strCurveL ; % ; fout := open pCurves "w ; FOR strCurve WITH strCurveL DO writefile fout strCurve ; ENDFOR ; close fout ; } #08********08 #] +-----+ #] insert pSubs into pTmplt, daisy-chained : IF flag_debug THEN write '+-----+' ; ENDIF ; IF flag_debug THEN write 'insert pSubs into pTmplt, daisy-chained :' ; ENDIF ; # loaddefs link d_Qndfs 'gnuplot via subFiles.ndf' IF flag_debug THEN write 'loading pTmplt_add_pSub' ; ENDIF ; #] pTmplt_add_pSub IS OP pTmplt pData pOut lineInsertPoint - #] common optr to insert pData into pTmplt after lineInsertPoint, save as pout # 31Jul2022 initial pTmplt_add_pSub IS OP pTmplt pData pOut lineInsertPoint { LOCAL fTmplt fData fOut line ; % ; IF (NAND (EACH pth_typ_exists (pTmplt "pinn) (pData "pinn) (pOut "povr))) THEN write 'pTmplt_add_pSub error: pth_typ_exists OR(pTmplt pData pOut)' ; ELSE fTmplt := open pTmplt "r ; fData := open pData "r ; fout := open pOut "w ; WHILE (~= ??eof (line := readfile fTmplt)) DO writefile fout line ; IF (= line lineInsertPoint) THEN WHILE (~= ??eof (line2 := readfile fData)) DO writefile fout line2 ; ENDWHILE ; ENDIF ; ENDWHILE ; EACH close fTmplt fData fout ; ENDIF ; } # loaddefs link d_Qndfs 'gnuplot via subFiles.ndf' IF flag_debug THEN write 'loading pTmplt_pSubs_create_pPlt' ; ENDIF ; #] pTmplt_pSubs_create_pPlt IS OP symList - create a gnuplot file #] for detrended [time, price] multi-fractals, daisy-chained subFiles # 28Jul2022 initial pTmplt_pSubs_create_pPlt IS OP symList { LOCAL cmd insertLine pTmpltTmp pWrdChgTmp pTimeFracsTmp pPriceFracsTmp pParamsTmp pLinStyTmp pCurvesTmp pPlotCmd pPngTmp ; NONLOCAL pTmplt pWrdChg pTimeFracs pPriceFracs pParams pLinSty pCurves pPlt pPng d_temp cmdGnuplotTemplateInsertVariables ; % ; % write cmdGnuplotTemplateInsertVariables ; host cmdGnuplotTemplateInsertVariables ; % ; pWrdChgTmp := link d_temp 'pTmplt_insert_wrdChgs.txt' ; pTmplt_insert_pWrdChg symList pWrdChgTmp ; % ; pNotesTmp := link d_temp 'pTmplt_insert_pNotes.txt' ; insertLine := '# notes (auto-added by QNial)' ; pTmplt_add_pSub pWrdChgTmp pNotes pNotesTmp insertLine ; % ; pTimeFracsTmp := link d_temp 'pTmplt_insert_pTimeFracs.txt' ; insertLine := '# PuetzUWS vertical timeSpikes (auto-added by QNial)' ; pTmplt_add_pSub pNotesTmp pTimeFracs pTimeFracsTmp insertLine ; % ; pPriceFracsTmp := link d_temp 'pTmplt_insert_pPriceFracs.txt' ; insertLine := '# PuetzUWS horizontal priceDetrend (auto-added by QNial)' ; pTmplt_add_pSub pTimeFracsTmp pPriceFracs pPriceFracsTmp insertLine ; % ; pParamsTmp := link d_temp 'pTmplt_insert_pParams.txt' ; insertLine := '# PuetzUWS table of parameters (auto-added by QNial)' ; pTmplt_add_pSub pPriceFracsTmp pParams pParamsTmp insertLine ; % ; pLinStyTmp := link d_temp 'pTmplt_insert_pLinSty.txt' ; insertLine := '# lineStyles for curve plots (auto-added by QNial)' ; pTmplt_add_pSub pParamsTmp pLinSty pLinStyTmp insertLine ; % ; insertLine := '# PuetzUWS curvePlots (auto-added by QNial)' ; pTmplt_add_pSub pLinStyTmp pCurves pPlt insertLine ; } #08********08 #] +-----+ #] do all steps : subFiles through pPng file : IF flag_debug THEN write '+-----+' ; ENDIF ; IF flag_debug THEN write 'do all steps : subFiles through pPng file :' ; ENDIF ; # loaddefs link d_Qndfs 'gnuplot via subFiles.ndf' IF flag_debug THEN write 'loading sym_timePriceFrac_gnuplot_pPng' ; ENDIF ; #] sym_timePriceFrac_gnuplot_pPng IS OP symList timeFracLL priceFracLLL - #] process through gnuplot [subFiles, pPlt, pPng] # 30Jul2022 initial # warning!! before running create_pPng manually, edit pPlt (see instructions) : # ', \' added to last curve must be manually removed!! (05Aug2022 OK?) # put quotes around font in pTmplt (05Aug2022 OK?) # replace {t} in 'set datafile separator {t}' with "{\t}" # reset title to : set title "{/:Bold PuetzUWS2011 [time, price] multi-fractals, detrended international stock market indices : [DAX40, INDIA50, NI225, SP500, UKX100]}\n {/: for [data, software, regression coefficients, plots, etc] see http://www.BillHowell.ca/economics, markets/SP500/PuetzUWS intnl stocks/}" # example : sym_timePriceFrac_gnuplot_pPng IS OP symList timeFracLL priceFracLLL { pTmplt_insert_pWrdChg symList ; noteL_create_pNotes ; timeFracLL_create_pTimeFracs timeFracLL ; priceFracLLL_create_pPriceFracs priceFracLLL ; paramTbl_create_pParams ; colorLwL_create_pLinSty ; paramTbl_create_pCurves ; pTmplt_pSubs_create_pPlt symList ; host link 'gnuPlot "' pPlt '" ' ; } # test : # timeFracLL := ( (1872.73 1879.06 1885.4 1891.73 1898.07 1904.41 1910.74 1917.08 1923.41 1929.75 1936.09 1942.42 1948.76 1955.09 1961.43 1967.77 1974.1 1980.44 1986.77 1993.11 1999.44 2005.78 2012.12 2018.45) (1872.73 1891.73 1910.74 1929.75 1948.76 1967.77 1986.77 2005.78) (1872.73 1929.75 1986.77) [1929.75] [1929.75] ) ; # priceFracLLL := ( (0 (0 0.333333 0.666666 0.999999) (0 0.111111 0.222222 0.333333 0.444444 0.555555 0.666666 0.777777 0.888888 0.999999 1.22222)) (0 (0 -0.999999 -0.666666 -0.333333) (0 -1.22222 -0.999999 -0.888888 -0.777777 -0.666666 -0.555555 -0.444444 -0.333333 -0.222222 -0.111111)) ) ; # sym_timePriceFrac_gnuplot_pPng >> OK # loaddefs link d_Qndfs 'gnuplot via subFiles.ndf' #**************************** #] +-----+ #] Instructions - copy-paste optrs to qnial command line, note manual steps! : IF flag_debug THEN write '+-----+' ; ENDIF ; IF flag_debug THEN write 'Instructions - copy-paste optrs to qnial command line, note manual step! : ' ; ENDIF ; # loaddefs link d_Qmkts 'gnuplot via subFiles.ndf' #] Normal actions, some are manual!!! : #> +-----+ #> "$d_Qmkts"'gnuplot via subFiles.ndf' #> check that ALL previous steps have been done : #> [mktSymbol, data, regression, PuetzUWS [params, selection], globals] #> gnuplot [template, variables, noteL, colorLs, lwLs]s #> +--+ #> doFrom_calcFracs_To_pPng #> # loaddefs link d_Qndfs 'gnuplot via subFiles.ndf' #] detailed stages, some are manual!!! : # +--+ # create independent pSubs : # timeFracLL_create_pTimeFracs timeFracLL - create a gnuplot subFile of timeFracs # priceFracLLL_create_pPriceFracs priceFracLLL - create a gnuplot subFile, horizontal gridLines # paramTbl_create_pParams - create a gnuplot subFile, regression parameters etc # colorLwL_create_pLinSty - create gnuplot subfile, lineStyles # paramTbl_create_pCurves - create gnuplot subfile of curves # sym_timePriceFrac_gnuplot_pPng timeFracLL priceFracLLL - create subFiles for a gnuplot # +--+ # insert pSubs into pTmplt, daisy-chained : # pTmplt_add_pSub pTmplt pData pOut lineInsertPoint - # common optr to insert pData into pTmplt after lineInsertPoint, save as pout # pTmplt_pSubs_create_pPlt - create a gnuplot file # for detrended [time, price] multi-fractals, daisy-chained subFiles # +--+ # warning!! before running : # ', \' of the last line of pPlt must be manually removed!! # create_pPng pPlt - generate plot # loaddefs link d_Qmkts 'gnuplot via subFiles.ndf' loaddefs_ended f_loadPuetzPlt ; # enddoc