"$d_Qroot""code develop_test/economics, markets/options- develop.txt" www.BillHowell.ca 24Apr2021 initial https://www.tradingview.com/symbols/NASDAQ-TSLA/ 08********08 24May2021 # loaddefs link d_Qndfs 'economics, markets/options data [download, process].ndf' IF flag_debug THEN write 'loading symbol_processOptions' ; ENDIF ; #] symbol_processOptions IS OP symbol dateDwnLoadL dateStrikerL sharePriceL shareDaterL #] - plot options curves as per specified dates (not used, best manual for now) # yahooOptions_downLoad : link 'https://finance.yahoo.com/quote/' symbol '/options?date=' htmlDateCode ; IF flag_break THEN BREAK ; ENDIF ; symbol_processOptions IS OP symbol dateDwnLoadL dateStrikerL sharePriceL shareDaterL { LOCAL args d_symbol d_symDat dateDwnLoadNow dateStriker EnddStrt ; NONLOCAL d_options p_templt_Strike p_templt_dwnLoad ; % ; d_symbol := link d_options symbol '/' ; d_symDat := link d_symbol 'data/' ; % make sure last date of download (including today if doing yahooOptions_downLoad today) ; % is last of allSymbols_processOptions -> dateDwnLoadL ; dateDwnLoadNow := last dateDwnLoadL ; dateDwnLoadChk := timestamp_YYMMDD ; % ; % check that dateDwnLoadNow is today - if not, a lot of previous would be [redone, <=disrupted] ; IF (~= dateDwnLoadNow dateDwnLoadChk) THEN write '?symbol_processOptions error : ~= dateDwnLoadNow dateDwnLoadChk' ; ELSE % [download, process, plot] data from yahoo finance webPages ; args := cart [d_symbol] [symbol] dateStrikerL ; EACH yahooOptions_downLoad args ; args := cart [d_symbol] [symbol] [dateDwnLoadNow] dateStrikerL ; EACH symbolYahoo_extract_callPutFiles args ; % ; % Plot strikDateL [call,putt] prices - only [most recent dateDwnLoadL, future dateStrikerL] are plotted ; args := cart ['strike'] ['price'] [d_symbol] [symbol] [dateDwnLoadNow] [dateDwnLoadL] dateStrikerL ; EACH gnuplot_optionsData_striker args ; args := cart ['strike'] ['volum'] [d_symbol] [symbol] [dateDwnLoadNow] [dateDwnLoadL] dateStrikerL ; EACH gnuplot_optionsData_striker args ; % ; % Plot dwnLoadDate [call,putt] volumes - only [future dateStrikerL] are plotted ; args := 'dwnLod' 'price' d_symbol symbol dateDwnLoadNow dateStrikerL ; gnuplot_optionsData_dwnLoad args ; args := 'dwnLod' 'volum' d_symbol symbol dateDwnLoadNow dateStrikerL ; gnuplot_optionsData_dwnLoad args ; % ; % [process, plot] options value ratios from dateStrt to dateEndd ; dateDwnLoadStrt dateDwnLoadEndd := [last front, last] dateDwnLoadL ; args := 'ratio' d_symbol symbol dateDwnLoadStrt dateDwnLoadEndd dateStrikerL sharePriceL shareDaterL ; option_calc_ratioOrDiffs args ; args := 'dummy_strikeOrDwnload' 'ratio' d_symbol symbol dateDwnLoadStrt dateDwnLoadEndd dateStrikerL ; gnuplot_optionsData_ratioDiffeValues args ; ENDIF ; } htmlDateL := EACH string (947116800 + ((EACH YYMMDD_to_days dateStrikerL) *60*60*24)) ; olde code % +---------------+ ; % prepare legend ; % do calls first to keep legend collected together by [call,putt]s ; i := 0 ; curveL := null ; FOR dateDwnLoad WITH (tell (gage shape dateDwnLoads)) DO %dateDwnLoad := YYMMDD_to_DDMMMYYYY dateDwnLoads@i ; curveL := append curveL ( link chr_tab chr_apo d_symDat dateDwnLoad ' ' symbol ' calls for ' dateStriker '.dat' chr_apo ' using ' cols_data ' w lp ls 10' (string i) ' title "calls ' dateStriker '", \' ) ; i := i + 1 ; ENDFOR ; % ; % now do putts, do NOT zero curve counter i! ; i := 0 ; FOR dateDwnLoad WITH (tell (gage shape dateDwnLoads)) DO %dateDwnLoad := YYMMDD_to_DDMMMYYYY dateDwnLoads@i ; curveL := append curveL ( link chr_tab chr_apo d_symDat dateDwnLoad ' ' symbol ' putts for ' dateStriker '.dat' chr_apo ' using ' cols_data ' w lp ls 10' (string i) ' title "putts ' dateStriker '", \' ) ; i := i + 1 ; ENDFOR ; ENDIF ; % noErrors after check directories ; in gnuplot_optionsData_dwnLoad : dwnLoadDate := YYMMDD_to_DDMMMYYYY strikerDates@i ; dwnLoadDate := YYMMDD_to_DDMMMYYYY strikerDates@i ; title := link ' [call,put] last transaction prices for strike date : ' ; %pngFile := link '/media/bill/Dell2/Website - raw/economics, markets/options// prices, dateStriker .png' ; title := link ' [call,put] last transaction volumes for strike date : ' ; %pngFile := link '/media/bill/Dell2/Website - raw/economics, markets/options// volums, dateStriker .png' ; title := link ' [call,put] last transaction prices for download date : ' ; %pngFile := link '/media/bill/Dell2/Website - raw/economics, markets/options//price dateDwnLoadNow .png' ; title := link ' [call,put] last transaction volumes for download date : ' ; %pngFile := link '/media/bill/Dell2/Website - raw/economics, markets/options//volum dateDwnLoadNow .png' ; title := link ' [call,put] ratios of to , based on option net values' ; title := link ' [call,put] differences of - , based on option net values' ; title := link ' [call,put] value ratios of to , based on option net values' ; 08********08 21May2021 olde code curveL := make_legend_striker d_symDat symbol dateDwnLoadNow dwnLoadDates strikerDates cols_data ; 08********08 21May2021 get rid of "unified" optr - this is poison, and too complex for me!!! split gnuplot_optionsData $ find "$d_webRawe"'economics, markets/options/' -maxdepth 1 -type f -name "*.plt" | tr \\n \\0 | xargs -0 -IFILE grep --with-filename --line-number '' "FILE" /media/bill/Dell2/Website - raw/economics, markets/options/6_dwnLoadDate [call,putt] volums gnuplot template.plt:29:set label "legend dates are for most recent date" at graph noenhanced /media/bill/Dell2/Website - raw/economics, markets/options/6_strikeDate [call,putt] volums gnuplot template.plt:28:set label "legend dates are for most recent date" at graph noenhanced /media/bill/Dell2/Website - raw/economics, markets/options/6_dwnLoadDate [call,putt] prices gnuplot template.plt:29:set label "legend dates are for most recent date" at graph noenhanced /media/bill/Dell2/Website - raw/economics, markets/options/6_strikeDate [call,putt] prices gnuplot template.plt:28:set label "legend dates are for most recent date" at graph noenhanced # loaddefs link d_Qndfs 'economics, markets/options data [download, process].ndf' IF flag_debug THEN write 'loading make_legend_striker' ; ENDIF ; #] make_legend_striker IS OP d_symDat symbol dateDwnLoadNow dwnLoadDates strikerDates cols_data #] - build gnuplot legend # 16May2021 initial taken out of gnuplot_optionsData etc # 20May2021 [legendDates, fileDates] must correspond pair-by-pair IF flag_break THEN BREAK ; ENDIF ; make_legend_striker IS OP d_symDat symbol dateDwnLoadNow dwnLoadDates strikerDate cols_data { LOCAL curveL i dateDwnLoad ; % ; % do calls first to keep legend collected together by [call,putt]s ; i := 0 ; curveL := null ; FOR i WITH (tell (gage shape dwnLoadDates)) DO dateDwnLoad := YYMMDD_to_DDMMMYYYY strikerDates@i ; curveL := append curveL ( link chr_tab chr_apo d_symDat dateDwnLoad ' ' symbol ' calls for ' strikerDate '.dat' chr_apo ' using ' cols_data ' w lp ls 10' (string i) ' title "calls ' dateDwnLoad '", \' ) ; i := i + 1 ; ENDFOR ; % ; % now do putts, do NOT zero curve counter i! ; i := 0 ; FOR i WITH (tell (gage shape dwnLoadDates)) DO dateDwnLoad := YYMMDD_to_DDMMMYYYY strikerDates@i ; curveL := append curveL ( link chr_tab chr_apo d_symDat dateDwnLoad ' ' symbol ' putts for ' strikerDate '.dat' chr_apo ' using ' cols_data ' w lp ls 10' (string i) ' title "putts ' dateDwnLoad '", \' ) ; i := i + 1 ; ENDFOR ; curveL } # loaddefs link d_Qndfs 'economics, markets/options data [download, process].ndf' IF flag_debug THEN write 'loading make_legend_dwnLoad' ; ENDIF ; #] make_legend_dwnLoad IS OP d_symDat symbol dateDwnLoadNow dwnLoadDates strikerDates cols_data #] - build gnuplot legend # 16May2021 initial taken out of gnuplot_optionsData etc # 20May2021 [legendDates, fileDates] must correspond pair-by-pair IF flag_break THEN BREAK ; ENDIF ; make_legend_dwnLoad IS OP d_symDat symbol dateDwnLoadNow dwnLoadDate strikerDates cols_data { LOCAL curveL i dateLegend ; % ; % do calls first to keep legend collected together by [call,putt]s ; i := 0 ; curveL := null ; FOR i WITH (tell (gage shape strikerDates)) DO strikerDate := YYMMDD_to_DDMMMYYYY strikerDates@i ; curveL := append curveL ( link chr_tab chr_apo d_symDat dateDwnLoadNow ' ' symbol ' calls for ' strikerDate '.dat' chr_apo ' using ' cols_data ' w lp ls 10' (string i) ' title "downLoadDate ' strikerDate '", \' ) ; i := i + 1 ; ENDFOR ; curveL } 08********08 20May2021 'options data [download, process].ndf' +-----+ olde code % check that inputs are consistent with typeStr ; IF (NAND (1 = (gage shape dateStrikerL)) (1 <= (gage shape dateDwnLoadL)) ) THEN write link '?gnuplot_optionsData error : date[r,L] shapes are inconsistent' ; noErrors := o ; ENDIF ; % check that inputs are consistent with typeStr ; IF (NAND (1 <= (gage shape dateStrikerL)) (1 = (gage shape dateDwnLoadL)) ) THEN write link '?gnuplot_optionsData error : date[r,L] shapes are inconsistent' ; noErrors := o ; ENDIF ; % args := cart ['strike'] ['volum'] [d_symbol] [symbol] % [dateDwnLoadNow] [dateDwnLoads] [dateStrikerL] dateStrikers [EnddStrt] ; 08********08 19May2021 'options data [download, process].ndf' { LOCAL cmd curveL d_symDat finn fout i line noErrors pCall pPutt pPlot pTmpl dateDwnLoads dateStrikers dateStriker dateHuman dateLegend is_templt_dateDwnLoad is_templt_dateStriker ; NONLOCAL chr_apo chr_tab p_templt_dwnLod2Ratio p_templt_strikePrice p_templt_strikeVolum ; +-----+ olde code % dateStriker basis ; ELSEIF (= 'ratio' priceVolumRatioDiffeValue) THEN cols_data := '1:2' ; pTmpl := p_templt_dwnLod2Ratio ; pPlot := link d_symDat EnddStrt ' ' symbol ' gnuPlotScript ratios.plt' ; title := link ' [call,put] of to , based on option net values' ; pngFile := link '/media/bill/Dell2/Website - raw/economics, markets/options// ratios.png' ; ELSEIF (= 'diffe' priceVolumRatioDiffeValue) THEN cols_data := '1:3' ; pTmpl := p_templt_dwnLod2Ratio ; pPlot := link d_symDat EnddStrt ' ' symbol ' gnuPlotScript diffes.plt' ; title := link ' [call,put] of to , based on option net values' ; pngFile := link '/media/bill/Dell2/Website - raw/economics, markets/options// diffes.png' ; ELSEIF (= 'value' priceVolumRatioDiffeValue) THEN cols_data := '1:4' ; pTmpl := p_templt_dwnLod2Ratio ; pPlot := link d_symDat EnddStrt ' ' symbol ' gnuPlotScript valRatios.plt' ; title := link ' [call,put] value ratios of to , based on option net values' ; pngFile := link '/media/bill/Dell2/Website - raw/economics, markets/options// values.png' ; # loaddefs link d_Qndfs 'economics, markets/options data [download, process].ndf' IF flag_debug THEN write 'loading option_calc_returnRatio_simpleTest' ; ENDIF ; #] option_calc_returnRatio_simpleTest IS - tests for option_calc_returnRatio # 08May2021 initial IF flag_break THEN BREAK ; ENDIF ; option_calc_returnRatio_simpleTest IS { LOCAL col_Strike col_price d_symDat dateEndd dateNoww dateStrt dateStrikerL n_dateStrikes n_strikes noError ratioL StrikeLoL strkCommonCullSortL strkIndxL strkNumCommonL p_strt p_endd p_outt strt_Strike strt_price endd_Strike endd_price strt_StrikeL strt_priceL endd_StrikeL endd_priceL col_titles table_ratios table_selects table_selStd ; % ; dateStrt dateEndd := '210430' '210504' ; dateStrikerL := '210528' '210604' '210611' '210618' ; n_dateStrikes := gage shape dateStrikerL ; % ; % calls example ; callOrPuttStr := 'calls' ; StrikeLoL := ('1020.00' '1030.00' '1040.00' '1050.00') ('1020.00' '1040.00' '1050.00' '1120.00') ('1050.00' '1040.00' '1030.00' '1020.00') ('1040.00' '1020.00' '1030.00' '1050.00') ; strt_priceL := ('642.53' '690.97' '610.00' '582.90') ('500.50' '1501.28' '531.15' '674.21') ('638.93' '492.60' '629.20' '492.60' '629.20') ('500.50' '1501.28' '531.15' '674.21') ; endd_priceL := ('824.30' '538.45' '335.00' '365.60') ('377.85' '564.00' '563.00' '562.00') ('561.00' '635.55' '696.00' '826.50') ('824.30' '538.45' '335.00' '365.60') ; % note that for listOfLists_findCommonItemsByCol_indexes, keyColIndxL = ; % 0 for option_calc_returnRatio_test ; % 2 for option_calc_returnRatio ; strkCommonCullSortL strkIndxL := listOfLists_linkSortCullTo_aryCommonKeyIndexs StrikeLoL ; n_strikes := gage shape strkIndxL ; % interesting shortcut - given that all StrikeLoL should have same strike prices, but perhaps at different columns ; strkNumCommonL := EACH tonumber strkCommonCullSortL ; strt_priceL := TWIG tonumber (strkIndxL EACHBOTH EACHLEFT pick strt_priceL) ; endd_priceL := TWIG tonumber (strkIndxL EACHBOTH EACHLEFT pick endd_priceL) ; table_selects := transpose mix link [strkNumCommonL] strt_priceL ; table_selStd := 3 5 reshape 1020. 642.53 500.5 492.6 1501.28 1040. 610. 1501.28 492.6 500.5 1050. 582.9 531.15 638.93 674.21 ; IF (= table_selStd table_selects) THEN write 'option_calc_returnRatio_develop , table_selects result is OK' ; ELSE write '?option_calc_returnRatio_develop error, table_selects result is WRONG' ; ENDIF ; ratioL := endd_priceL EACHBOTH / strt_priceL ; table_ratios := aryMatTab_join_horizontal ((gage shape strkNumCommonL) 1 reshape strkNumCommonL) (transpose mix ratioL) ; col_titles := link ['strikePrice'] ((callOrPuttStr link '_') EACHRIGHT link (EACH YYMMDD_to_DDMMMYYYY dateStrikerL)) ; EACH write '' 'option_calc_returnRatio_test - table of call ratios' ; write table_addColTitles col_titles table_ratios ; % ; % putts example ; callOrPuttStr := 'putts' ; StrikeLoL := ('1020.00' '1030.00' '1040.00' '1050.00') ('1020.00' '1040.00' '1050.00' '1120.00') ('1050.00' '1040.00' '1030.00' '1020.00') ('1040.00' '1020.00' '1030.00' '1050.00') ; strt_priceL := ('172.15' '183.38' '189.10' '195.00') ('212.00' '218.85' '229.35' '238.85') ('125.10' '120.00' '63.87 64.' '70.40' '66.') ('277.15' '281.45' '273.80' '278.18') ; endd_priceL := ('344.60' '307.00' '309.15' '376.30') ('379.30' '401.05' '410.30' '362.00') ('396.08' '385.60' '417.55' '430.60' '429.30') ('443.85' '435.30' '435.65' '467.55' '464.85' '495.63') ; % note that for listOfLists_findCommonItemsByCol_indexes, keyColIndxL = ; % 0 for option_calc_returnRatio_test ; % 2 for option_calc_returnRatio ; strkCommonCullSortL strkIndxL := listOfLists_linkSortCullTo_aryCommonKeyIndexs StrikeLoL ; n_strikes := gage shape strkIndxL ; % interesting shortcut - given that all StrikeLoL should have same strike prices, but perhaps at different columns ; strkNumCommonL := EACH tonumber strkCommonCullSortL ; strt_priceL := TWIG tonumber (strkIndxL EACHBOTH EACHLEFT pick strt_priceL) ; endd_priceL := TWIG tonumber (strkIndxL EACHBOTH EACHLEFT pick endd_priceL) ; table_selects := transpose mix link [strkNumCommonL] strt_priceL ; table_selStd := 3 5 reshape 1020. 642.53 500.5 492.6 1501.28 1040. 610. 1501.28 492.6 500.5 1050. 582.9 531.15 638.93 674.21 ; IF (= table_selStd table_selects) THEN write 'option_calc_returnRatio_develop , table_selects result is OK' ; ELSE write '?option_calc_returnRatio_develop error, table_selects result is WRONG' ; ENDIF ; ratioL := endd_priceL EACHBOTH / strt_priceL ; table_ratios := aryMatTab_join_horizontal ((gage shape strkNumCommonL) 1 reshape strkNumCommonL) (transpose mix ratioL) ; col_titles := link ['strikePrice'] ((callOrPuttStr link '_') EACHRIGHT link (EACH YYMMDD_to_DDMMMYYYY dateStrikerL)) ; EACH write '' 'option_calc_returnRatio_test - table of call ratios' ; write table_addColTitles col_titles table_ratios ; } # loaddefs link d_Qndfs 'economics, markets/options data [download, process].ndf' IF flag_debug THEN write 'loading gnuplot_options_examples' ; ENDIF ; #] gnuplot_options_examples IS - # 30Apr2021 initial gnuplot_options_examples IS { LOCAL d_symbol d_symDat symbol ; NONLOCAL dateDwnLoadL dateStrikerL ; % ; symbol := 'TSLA' ; d_symbol := link d_options symbol '/' ; dateDwnLoadL := '210407' '210418' '210422' '210424' '210430' ; dateStrikerL := '210507' '210514' '210521' '210528' '210604' '210611' '210618' ; % ; % gnuplot_optionsData 'price' d_symbol symbol ['210511'] dateStrikerL ; % gnuplot_optionsData strikeOrDwnload priceVolumRatioDiffeValue % d_symbol symbol dateDwnLoadL dateStrikerL EnddStrt ; } # examples gnuplot_optionsData 'price' d_symbol symbol ['210424'] dateStrikerL ; gnuplot_optionsData 'price' d_symbol symbol ['210430'] dateStrikerL ; gnuplot_optionsData 'price' d_symbol symbol ['210504'] dateStrikerL ; gnuplot_optionsData 'price' d_symbol symbol ['210511'] dateStrikerL ; gnuplot_optionsData 'volum' d_symbol symbol ['210511'] dateStrikerL ; # examples gnuplot_optionsData 'price' d_symbol symbol dateDwnLoadL '210507' ; gnuplot_optionsData 'price' d_symbol symbol dateDwnLoadL '210514' ; gnuplot_optionsData 'price' d_symbol symbol dateDwnLoadL '210521' ; gnuplot_optionsData 'price' d_symbol symbol dateDwnLoadL '210528' ; gnuplot_optionsData 'price' d_symbol symbol dateDwnLoadL '210604' ; gnuplot_optionsData 'price' d_symbol symbol dateDwnLoadL '210611' ; gnuplot_optionsData 'price' d_symbol symbol dateDwnLoadL '210618' ; gnuplot_optionsData 'volum' d_symbol symbol dateDwnLoadL '210618' ; # loaddefs link d_Qndfs 'economics, markets/options data [download, process].ndf' IF flag_debug THEN write 'loading option_gnuplot_returnRatios_example' ; ENDIF ; #] option_gnuplot_returnRatios_example IS - res ipsa loquitor # 11May2021 initial IF flag_break THEN BREAK ; ENDIF ; option_gnuplot_returnRatios_example IS { LOCAL d_symbol symbol dateDwnLoadStrt dateDwnLoadEndd dateStrikerL ; symbol := 'TSLA' ; d_symbol := link d_options symbol '/' ; dateDwnLoadStrt := '210504' ; dateDwnLoadEndd := '210511' ; dateStrikerL := '210514' '210521' '210528' '210604' '210611' '210618' '210625' ; gnuplot_optionsData d_symbol symbol dateDwnLoadStrt dateDwnLoadEndd dateStrikerL ; } 08********08 15-16May2021 # loaddefs link d_Qndfs 'economics, markets/options data [download, process].ndf' IF flag_debug THEN write 'loading priceOrVolum_gnuplotFor_strikeDate' ; ENDIF ; #] priceOrVolum_gnuplotFor_strikeDate IS OP priceOrVolumStr d_symbol symbol dateDwnLoadL dateStrike - #] create script for [call, putt] gnuplots, date[DwnLoadL, Strike]L MUST be lists! # 22Apr2021 initial # 24Apr2021 must handle missing [call,putt]s .dat files IF flag_break THEN BREAK ; ENDIF ; priceOrVolum_gnuplotFor_strikeDate IS OP priceOrVolumStr d_symbol symbol dateDwnLoadL dateStrike IF noErrors THEN IF flag_break THEN BREAK ; ENDIF ; % ; % Legend - do calls first to keep legend collected together by [call,putt]s ; i := 0 ; curveL := null ; FOR dateDwnLoad WITH dateDwnLoads DO dateLegend := YYMMDD_to_DDMMMYYYY dateDwnLoad ; curveL := append curveL ( link chr_tab chr_apo d_symDat dateDwnLoad ' ' symbol ' calls for ' dateStrike '.dat' chr_apo ' using ' cols_data ' w lp ls 10' (string i) ' title "calls ' dateLegend '", \' ) ; i := i + 1 ; ENDFOR ; % ; % now do putts, do NOT zero curve counter i! ; i := 0 ; FOR dateDwnLoad WITH dateDwnLoads DO dateLegend := YYMMDD_to_DDMMMYYYY dateDwnLoad ; curveL := append curveL ( link chr_tab chr_apo d_symDat dateDwnLoad ' ' symbol ' putts for ' dateStrike '.dat' chr_apo ' using ' cols_data ' w lp ls 10' (string i) ' title "putts ' dateLegend '", \' ) ; i := i + 1 ; ENDFOR ; % ; % +---------------+ ; % set up gnuplot files ; % dateDwnLoad already set to last dateDwnLoadL in FOR above ; pTmpl := p_templt_strikePrice ; pPlot := link d_symDat dateDwnLoad ' ' symbol ' [call,putt] ' priceOrVolumStr ' for ' dateStrike ' gnuPlotScript.plt' ; finn := open pTmpl "r ; fout := open pPlot "w ; dateStrikeHuman := YYMMDD_to_DDMMMYYYY dateStrike ; WHILE ( ~= ??eof (line := readfile finn)) DO IF (= '' line) THEN % insert [date, plotCurve]s into gnuTemplate file ; fout EACHRIGHT writefile curveL ; ELSE line := str_replace_subStr '' symbol line ; line := str_replace_subStr '' dateStrike line ; line := str_replace_subStr '' dateStrikeHuman line ; line := str_replace_subStr '' priceOrVolumStr line ; writefile fout line ; ENDIF ; ENDWHILE ; EACH close finn fout ; % ; % create plot image ; cmd := link 'gnuplot "' pPlot '"' ; % write cmd ; % host cmd ; ENDIF ; } # loaddefs link d_Qndfs 'economics, markets/options data [download, process].ndf' IF flag_debug THEN write 'loading priceOrVolum_gnuplotFor_dwnLoadDate' ; ENDIF ; #] priceOrVolum_gnuplotFor_dwnLoadDate IS OP priceOrVolumStr d_symbol symbol dateDwnLoadL dateStrikeL - #] create script for [call, putt] gnuplots, date[DwnLoad, StrikeL] # Only (last dateDwnLoadL) is plotted (new one)! # 22Apr2021 initial # 24Apr2021 must handle missing [call,putt]s .dat files IF flag_break THEN BREAK ; ENDIF ; priceOrVolum_gnuplotFor_dwnLoadDate IS OP typeStr priceOrVolumStr d_symbol symbol dateDwnLoad dateStrikeL { LOCAL cmd curveL d_symDat i line noErrors finn fout pCall pPutt pPlot pTmpl dateDwnLoadHuman dateLegend dateStrike dateStrikes ; NONLOCAL chr_apo chr_tab p_templt_dwnLoadPrice p_templt_dwnLoadPrice ; % ; % checks of consistency before proceeding ; noErrors := l ; d_symDat := link d_symbol 'data/' ; IF (NAND (EACH path_exists ("w d_symbol) ("w d_symDat))) THEN EACH write '?gnuplot_option_dwnLoadL_prices- path_backupTo_dir error, dir unknown, one of : ' d_symbol d_symDat '' ; noErrors := o ; ENDIF ; % ; IF noErrors THEN % 13May2021 NYET! (one-based) - gnuplot has zero-based column indexing... ; IF (= 'price' priceOrVolumStr) THEN cols_data := '3:4' ; ELSE cols_data := '3:9' ; ENDIF ; % strikeDates are limited to those >= than dateDwnLoad ; dateStrikes := ((tonumber dateDwnLoad) EACHRIGHT >= (EACH tonumber dateStrikeL)) sublist dateStrikeL ; % ; % Legend - do calls first to keep legend collected together by [call,putt]s ; i := 0 ; curveL := null ; FOR dateStrike WITH dateStrikes DO dateLegend := YYMMDD_to_DDMMMYYYY dateStrike ; curveL := append curveL ( link chr_tab chr_apo d_symDat dateDwnLoad ' ' symbol ' calls for ' dateStrike '.dat' chr_apo ' using ' cols_data ' w lp ls 10' (string i) ' title "calls ' dateLegend '", \' ) ; i := i + 1 ; ENDFOR ; % ; % now do putts, do NOT zero curve counter i! ; i := 0 ; FOR dateStrike WITH dateStrikes DO dateLegend := YYMMDD_to_DDMMMYYYY dateStrike ; curveL := append curveL ( link chr_tab chr_apo d_symDat dateDwnLoad ' ' symbol ' putts for ' dateStrike '.dat' chr_apo ' using ' cols_data ' w lp ls 10' (string i) ' title "putts ' dateLegend '", \' ) ; i := i + 1 ; ENDFOR ; % ; % set up gnuplot files, dateStrike already set to last dateStrikeL in FOR above ; pTmpl := p_templt_dwnLoadPrice ; pPlot := link d_symDat dateDwnLoad ' ' symbol ' [call,putt] ' priceOrVolumStr ' gnuPlotScript.plt' ; finn := open pTmpl "r ; fout := open pPlot "w ; dateDwnLoadHuman := YYMMDD_to_DDMMMYYYY dateDwnLoad ; WHILE ( ~= ??eof (line := readfile finn)) DO IF (= '' line) THEN % insert [date, plotCurve]s into gnuTemplate file ; fout EACHRIGHT writefile curveL ; ELSE line := str_replace_subStr '' symbol line ; line := str_replace_subStr '' dateDwnLoad line ; line := str_replace_subStr '' dateDwnLoadHuman line ; line := str_replace_subStr '' priceOrVolumStr line ; writefile fout line ; ENDIF ; ENDWHILE ; EACH close finn fout ; % ; % create plot image ; cmd := link 'gnuplot "' pPlot '"' ; % write cmd ; % host cmd ; ENDIF ; } # loaddefs link d_Qndfs 'economics, markets/options data [download, process].ndf' IF flag_debug THEN write 'loading option_calc_returnRatios_example' ; ENDIF ; #] option_calc_returnRatios_example IS - tests for development of option_calc_returnRatio # 10May2021 initial # must remove "junk sentence" at end of list of putts - code later sometime IF flag_break THEN BREAK ; ENDIF ; option_calc_returnRatios_example IS { LOCAL callOrPuttStr d_symbol dateEndd dateStrikeL dateStrt symbol priceShareEndd ; NONLOCAL d_options ; % ; symbol := 'TSLA' ; d_symbol := link d_options symbol '/' ; dateStrt dateEndd := '210430' '210504' ; dateStrikeL := '210514' '210521' '210528' '210604' '210618' ; priceShareEndd := 500 ; % ; callOrPuttStr := 'calls' ; option_calc_returnRatios d_symbol symbol dateStrt dateEndd dateStrikeL callOrPuttStr priceShareEndd ; callOrPuttStr := 'putts' ; option_calc_returnRatios d_symbol symbol dateStrt dateEndd dateStrikeL callOrPuttStr priceShareEndd ; } # loaddefs link d_Qndfs 'economics, markets/options data [download, process].ndf' IF flag_debug THEN write 'loading ratios_gnuplotOf_2dwnLoadDates' ; ENDIF ; #] ratios_gnuplotOf_2dwnLoadDates IS OP d_symbol symbol dateStrt dateEndd dateStrikeL #] - res ipsa loquitor # 06May2021 initial few lines # 11May2021 adapt gnuplot_option_dwnLoadL_prices from download sections above IF flag_break THEN BREAK ; ENDIF ; ratios_gnuplotOf_2dwnLoadDates IS OP priceOrVolumStr ratioOrDiffStr d_symbol symbol dateDwnLoadStrt dateDwnLoadEndd dateStrikeL { LOCAL cmd curveL d_symDat dateEnddHuman dateLegend dateStrike dateStrtHuman finn fout i line noErrors pPlot pTmpl ratioOrValue ; NONLOCAL chr_apo chr_tab p_templt_dwnLod2Ratio ; % ; % checks of consistency before proceeding ; noErrors := l ; d_symDat := link d_symbol 'data/' ; IF (NAND (EACH path_exists ("w d_symbol) ("w d_symDat))) THEN EACH write '?gnuplot_option_dwnLoadL_prices- path_backupTo_dir error, dir unknown, one of : ' d_symbol d_symDat '' ; noErrors := o ; ENDIF ; % ; IF noErrors THEN IF flag_break THEN BREAK ; ENDIF ; EnddStrt := link dateDwnLoadEndd '<-' dateDwnLoadStrt ; % If ratioOrDiffStr != 'ratio', it is assumed that 'values' are desired ; % 13May2021 NYET! (one-based) - gnuplot has zero-based column indexing... ; IF (= 'ratio' ratioOrDiffStr) THEN cols_data := '1:2' ; ELSE cols_data := '1:3' ; ENDIF ; % strikeDates are limited to those >= than dwnLoadDate ; dateStrikes := ((tonumber dateDwnLoad) EACHRIGHT >= (EACH tonumber dateStrikeL)) sublist dateStrikeL ; % ; % ; % +---------------+ ; % legend ; i := 0 ; curveL := null ; FOR dateStrike WITH dateStrikeL DO dateLegend := YYMMDD_to_DDMMMYYYY dateStrike ; curveL := append curveL ( link chr_tab chr_apo d_symDat EnddStrt ' ' symbol ' ratios for ' dateStrike '.dat' chr_apo ' using 1:2 w lp ls 10' (string i) ' title "calls ' dateLegend '", \' ) ; i := i + 1 ; ENDFOR ; % ; % now do putts, do NOT zero curve counter i! ; i := 0 ; FOR dateStrike WITH dateStrikeL DO dateLegend := YYMMDD_to_DDMMMYYYY dateStrike ; curveL := append curveL ( link chr_tab chr_apo d_symDat EnddStrt ' ' symbol ' values for ' dateStrike '.dat' chr_apo ' using 1:2 w lp ls 20' (string i) ' title "putts ' dateLegend '", \' ) ; i := i + 1 ; ENDFOR ; % ; % +---------------+ ; % set up gnuplot files ; pTmpl := p_templt_dwnLod2Ratio ; pPlot := link d_symDat EnddStrt ' ' symbol ' ' priceOrVolumStr ' ' ratioOrDiffStr ' gnuPlotScript.plt' ; finn := open pTmpl "r ; fout := open pPlot "w ; dateStrtHuman := YYMMDD_to_DDMMMYYYY dateDwnLoadStrt ; dateEnddHuman := YYMMDD_to_DDMMMYYYY dateDwnLoadEndd ; WHILE ( ~= ??eof (line := readfile finn)) DO IF (= '' line) THEN % insert [date, plotCurve]s into gnuTemplate file ; fout EACHRIGHT writefile curveL ; ELSE line := str_replace_subStr '' EnddStrt line ; line := str_replace_subStr '' symbol line ; line := str_replace_subStr '' dateStrtHuman line ; line := str_replace_subStr '' dateEnddHuman line ; line := str_replace_subStr '' ratioOrDiffStr line ; writefile fout line ; ENDIF ; ENDWHILE ; EACH close finn fout ; % ; % create plot image ; cmd := link 'gnuplot "' pPlot '"' ; % write cmd ; % host cmd ; ENDIF ; } # olde code p_strt := link d_symDat dateStrt ' ' symbol ' ' callOrPuttStr ' for ' dateStrike '.dat' ; p_endd := link d_symDat dateEndd ' ' symbol ' ' callOrPuttStr ' for ' dateStrike '.dat' ; 08********08 13May2021 priceOrVolum_gnuplotFor_strikeDate IS OP priceOrVolumStr d_symbol symbol dateDwnLoadL dateStrike { LOCAL cmd curveL d_symDat i line noErrors finn fout pCall pPutt pPlot pTmpl dateDwnLoad dateDwnLoads dateLegend dateStrikeHuman ; NONLOCAL chr_apo chr_tab p_templt_strikePrice p_templt_strikeVolum ; % ; % checks of consistency before proceeding ; noErrors := l ; d_symDat := link d_symbol 'data/' ; IF (NAND (EACH path_exists ("w d_symbol) ("w d_symDat))) THEN EACH write '?gnuplot_option_dwnLoadL_prices- path_backupTo_dir error, dir unknown, one of : ' d_symbol d_symDat '' ; noErrors := o ; ENDIF ; % ; IF noErrors THEN IF flag_break THEN BREAK ; ENDIF ; % If priceOrVolumStr != 'prices', it is assumed that 'volums' are desired ; % 13May2021 NYET! (one-based) - gnuplot has zero-based column indexing... ; IF (= 'price' priceOrVolumStr) THEN cols_data := '3:4' ; ELSE cols_data := '3:9' ; ENDIF ; % dwnLoadDates are limited to those <= than date ; dateDwnLoads := ((EACH tonumber dateDwnLoadL) EACHLEFT <= (tonumber dateStrike)) sublist dateDwnLoadL ; % ; % Legend - do calls first to keep legend collected together by [call,putt]s ; i := 0 ; curveL := null ; FOR dateDwnLoad WITH dateDwnLoads DO dateLegend := YYMMDD_to_DDMMMYYYY dateDwnLoad ; curveL := append curveL ( link chr_tab chr_apo d_symDat dateDwnLoad ' ' symbol ' calls for ' dateStrike '.dat' chr_apo ' using ' cols_data ' w lp ls 10' (string i) ' title "calls ' dateLegend '", \' ) ; i := i + 1 ; ENDFOR ; % ; % now do putts, do NOT zero curve counter i! ; i := 0 ; FOR dateDwnLoad WITH dateDwnLoads DO dateLegend := YYMMDD_to_DDMMMYYYY dateDwnLoad ; curveL := append curveL ( link chr_tab chr_apo d_symDat dateDwnLoad ' ' symbol ' putts for ' dateStrike '.dat' chr_apo ' using ' cols_data ' w lp ls 10' (string i) ' title "putts ' dateLegend '", \' ) ; i := i + 1 ; ENDFOR ; % ; % set up gnuplot files ; pTmpl := p_templt_strikePrice ; pPlot := link d_symDat dateStrike ' ' symbol ' dateStrike [call,putt] prices gnuPlotScript.plt' ; finn := open pTmpl "r ; fout := open pPlot "w ; dateStrikeHuman := YYMMDD_to_DDMMMYYYY dateStrike ; WHILE ( ~= ??eof (line := readfile finn)) DO IF (= '' line) THEN % insert [date, plotCurve]s into gnuTemplate file ; fout EACHRIGHT writefile curveL ; ELSE line := str_replace_subStr '' symbol line ; line := str_replace_subStr '' dateStrike line ; line := str_replace_subStr '' dateStrikeHuman line ; line := str_replace_subStr '' priceOrVolumStr line ; writefile fout line ; ENDIF ; ENDWHILE ; EACH close finn fout ; % ; % create plot image ; cmd := link 'gnuplot "' pPlot '"' ; % write cmd ; host cmd ; ENDIF ; } 08********08 10May2021 webPage '210514' 1620950400 '210618' 1623974400 # 604800 / 24 / 60 / 60 = 7. qnial> (1620950400 1623974400) - ((EACH YYMMDD_to_days '210514' '210618') *60*60*24) 947116800 947116800 try : qnial> 947116800 + ((EACH YYMMDD_to_days '210514' '210521' '210528' '210604' '210611' '210618' '210625') *60*60*24) 1620950400 1621555200 1622160000 1622764800 1623369600 1623974400 1624579200 >> Finally, codes seem OK (I am incompetent! should not have struggled with this!!!) +-+ qnial> 811745280 - (72*60*24) 811848960 qnial> (1620345600 - 1620241920) (1623974400 - 1623870720) 103680 103680 qnial> 811641600 + 103680 811745280 qnial> 811745280 + ((EACH YYMMDD_to_days '210514' '210521' '210528' '210604' '210611' '210618' '210625') *72*60*24) 1620345600 1621071360 1621797120 1622522880 1623248640 1623974400 1624700160 qnial> 811641600 + ((EACH YYMMDD_to_days '210514' '210521' '210528' '210604' '210611' '210618' '210625') *72*60*24) 1620241920 1620967680 1621693440 1622419200 1623144960 1623870720 1624596480 (1620345600 - 1620241920) (1623974400 - 1623870720) # why don't 14May2021 TESLA options show on webpage 11May2021 (during week of 14May2021)? >> I buggered the coding +-----+ qnial> allSymbols_processOptions +-----------------------------+------------------------------------------------------------+ |yahooOptions_downLoad, URL = |https://finance.yahoo.com/quote/TSLA/options?date=1620950400| +-----------------------------+------------------------------------------------------------+ https://finance.yahoo.com/quote/TSLA/options?date=1620950400 # htmlDate 1620345600 = dateStrikers '210514' ; # htmlDate 1623974400 = dateStrikers '210618' ; # yahooOptios options webPage dateNumber # 1620345600 + ((- EACH YYMMDD_to_days '210618' '210514') *72*60*24) + (604800 * (0 1 2 3 4 5 6)) # (- 1623974400 1620345600) / 35 = 103680 # (- 1623974400 1620345600) / 35 / 24 = 4320 # (- 1623974400 1620345600) / 35 / 24 / 60 = 72 # (- 1623974400 1620345600) / 35 / 24 / 60 / 72 = 1. # 604800 / 35 / 24 / 60 / 72 = 0.1667 # 1620345600 - ((EACH YYMMDD_to_days '210521' '210528' '210604' '210611' '210618' '210625') *72*60*24) # 604800 / 24 / 60 / 72 = 5.83333 # 604800 / 24 / 60 / 60 = 7. # qnial> a := ((EACH YYMMDD_to_days '210521' '210528' '210604' '210611' '210618' '210625') *72*60*24) 809326080 810051840 810777600 811503360 812229120 812954880 qnial> - [rest, front] a 725760 725760 725760 725760 725760 qnial> 725760 / 24 / 60 / 72 7. # for '210618' : qnial> 1623974400 - 812229120 811745280 +-----+ # qnial> EACH (gage shape) strt_strikerLoL 127 128 115 83 414 # qnial> EACH (gage shape) endd_strikerLoL 129 128 117 106 414 # qnial> a := (EACH solitary strt_strikerLoL) EACHBOTH append endd_strikerLoL # qnial> EACH (gage shape) a 2 2 2 2 2 # qnial> EACH EACH (gage shape) a +-------+-------+-------+------+-------+ |127 129|128 128|115 117|83 106|414 414| +-------+-------+-------+------+-------+ # qnial> b := EACH listOfLists_linkSortCullTo_commonL_indexsLoL a ; # qnial> EACH EACH (gage shape) b +-----+-----+-----+----+-----+ |127 2|128 2|115 2|83 2|414 2| +-----+-----+-----+----+-----+ # qnial> EACH EACH (gage shape) (EACH second b) +-------+-------+-------+-----+-------+ |127 127|128 128|115 115|83 83|414 414| +-------+-------+-------+-----+-------+ # qnial> b@@(0 1 0) 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 >> strange re-ordering. Is this because of text format? # qnial> EACH listOfLists_linkSortCullTo_commonL_indexsLoL ((EACH solitary strt_strikerLoL) EACHBOTH append endd_strikerLoL) >> seems OK? # olde code LOCALs : n_dateStrikers n_strikes n_strikes := gage shape strkIndxL ; % interesting shortcut - given that all strikerLoL should have same strike prices, but perhaps at different columns ; strkNumCommonLoL := TWIG tonumber strkCommonCullSortLoL ; % strt_strikerLoL := TWIG tonumber strt_strikerLoL ; % endd_strikerLoL := TWIG tonumber endd_strikerLoL ; % strt_priceLoL := TWIG tonumber (strkIndxLoL EACHBOTH EACHLEFT pick strt_priceLoL) ; % endd_priceLoL := TWIG tonumber (strkIndxLoL EACHBOTH EACHLEFT pick endd_priceLoL) ; +-----+ # olde code strkCommonLoL strkIndxStrtLoL strkIndxEnddLoL := EACH second strkIndx_StrtEndd_LoL ; # listOfLists_linkSortCullTo_aryCommonKeyIndexs ((EACH solitary strt_strikerLoL) EACHBOTH append endd strkCommonLoL strkIndxStrtLoL strkIndxEnddLoL := EACH second strkIndx_StrtEndd_LoL ; _strikerLoL) IF noError THEN % 10May2021 DO NOT combine data from date[Strt,Endd] for all dateStrikerL!! ; % Instead, find [strt,endd] common strikes for each dateStrikeL ; listOf_aryCommonKeyIndexs := EACH listOfLists_linkSortCullTo_aryCommonKeyIndexs ((EACH solitary strt_strikerLoL) EACHBOTH append endd_strikerLoL) ; ENDIF ; strt_strikerLoL endd_strikerLoL strt_priceLoL endd_priceLoL := strt_strikerLoL endd_strikerLoL strt_priceLoL endd_priceLoL EACHBOTH append (TWIG tonumber strt_striker endd_striker strt_price endd_price ) ; # olde stuff % +---------------------+ ; % Tesla options ; symbol := 'TSLA' ; d_symbol := link d_options symbol '/' ; d_symDat := link d_symbol 'data/' ; dateDwnLoadL := '210407' '210418' '210422' '210424' '210430' '210504' '210510' ; dateStrikerL := '210514' '210521' '210528' '210604' '210611' '210618' '210625' ; % yahooOptions_downLoad : link 'https://finance.yahoo.com/quote/' symbol '/options?date=' htmlDateCode ; % htmlDate 1620345600 = dateStrikers '210514' ; % htmlDate 1623974400 = dateStrikers '210618' ; % htmlDateStart := 1620345600 ; htmlDateStart := 1620345600 + (((first dateStrikerL) - ( htmlDateL := EACH string (htmlDateStart + (604800 * (0 1 2 3 4 5 6))) ; FOR dateStriker WITH dateStrikerL DO symbolYahoo_extract_callPutFiles d_symbol symbol dateDwnLoad dateStriker ; ENDFOR ; 08********08 09May2021 +-----+ 10May2021 Working version - needs some "true" table results and comparison tests. #] option_calc_returnRatio_test IS - tests for development of option_calc_returnRatio # 08May2021 initial IF flag_break THEN BREAK ; ENDIF ; option_calc_returnRatio_test IS { LOCAL col_striker col_price d_symDat dateEndd dateNoww dateStrt dateStrikerL n_dateStrikers n_strikes noError ratioL strikerLoL strkCommonCullSortL strkIndxL strkNumCommonL p_strt p_endd p_strt p_endd p_outt strt_striker strt_price endd_striker endd_price strt_strikerL strt_priceL endd_strikerL endd_priceL col_titles table_ratios table_selects table_selStd ; % ; dateStrt dateEndd := '210430' '210504' ; dateStrikerL := '210528' '210604' '210611' '210618' ; n_dateStrikers := gage shape dateStrikerL ; % ; % calls example ; callOrPuttStr := 'calls' ; strikerLoL := ('1020.00' '1030.00' '1040.00' '1050.00') ('1020.00' '1040.00' '1050.00' '1120.00') ('1050.00' '1040.00' '1030.00' '1020.00') ('1040.00' '1020.00' '1030.00' '1050.00') ; strt_priceL := ('642.53' '690.97' '610.00' '582.90') ('500.50' '1501.28' '531.15' '674.21') ('638.93' '492.60' '629.20' '492.60' '629.20') ('500.50' '1501.28' '531.15' '674.21') ; endd_priceL := ('824.30' '538.45' '335.00' '365.60') ('377.85' '564.00' '563.00' '562.00') ('561.00' '635.55' '696.00' '826.50') ('824.30' '538.45' '335.00' '365.60') ; % note that for listOfLists_findCommonItemsByCol_indexes, keyColIndxL = ; % 0 for option_calc_returnRatio_test ; % 2 for option_calc_returnRatio ; strkCommonCullSortL strkIndxL := listOfLists_findCommonItems_commonL_indexsL strikerLoL ; n_strikes := gage shape strkIndxL ; % interesting shortcut - given that all strikerLoL should have same strike prices, but perhaps at different columns ; strkNumCommonL := EACH tonumber strkCommonCullSortL ; strt_priceL := TWIG tonumber (strkIndxL EACHBOTH EACHLEFT pick strt_priceL) ; endd_priceL := TWIG tonumber (strkIndxL EACHBOTH EACHLEFT pick endd_priceL) ; table_selects := transpose mix link [strkNumCommonL] strt_priceL ; table_selStd := 3 5 reshape 1020. 642.53 500.5 492.6 1501.28 1040. 610. 1501.28 492.6 500.5 1050. 582.9 531.15 638.93 674.21 ; IF (= table_selStd table_selects) THEN write ' option_calc_returnRatio_develop , table_selects result is OK' ; ELSE write '?option_calc_returnRatio_develop error, table_selects result is WRONG' ; ENDIF ; ratioL := endd_priceL EACHBOTH / strt_priceL ; table_ratios := aryMatTab_join_horizontal ((gage shape strkNumCommonL) 1 reshape strkNumCommonL) (transpose mix ratioL) ; col_titles := link ['strikePrice'] ((callOrPuttStr link '_') EACHRIGHT link (EACH YYMMDD_to_DDMMMYYYY dateStrikerL)) ; EACH write '' 'option_calc_returnRatio_test - table of call ratios' ; write table_addColTitles col_titles table_ratios ; % ; % putts example ; callOrPuttStr := 'putts' ; strikerLoL := ('1020.00' '1030.00' '1040.00' '1050.00') ('1020.00' '1040.00' '1050.00' '1120.00') ('1050.00' '1040.00' '1030.00' '1020.00') ('1040.00' '1020.00' '1030.00' '1050.00') ; strt_priceL := ('172.15' '183.38' '189.10' '195.00') ('212.00' '218.85' '229.35' '238.85') ('125.10' '120.00' '63.87 64.' '70.40' '66.') ('277.15' '281.45' '273.80' '278.18') ; endd_priceL := ('344.60' '307.00' '309.15' '376.30') ('379.30' '401.05' '410.30' '362.00') ('396.08' '385.60' '417.55' '430.60' '429.30') ('443.85' '435.30' '435.65' '467.55' '464.85' '495.63') ; % note that for listOfLists_findCommonItemsByCol_indexes, keyColIndxL = ; % 0 for option_calc_returnRatio_test ; % 2 for option_calc_returnRatio ; strkCommonCullSortL strkIndxL := listOfLists_findCommonItems_commonL_indexsL strikerLoL ; n_strikes := gage shape strkIndxL ; % interesting shortcut - given that all strikerLoL should have same strike prices, but perhaps at different columns ; strkNumCommonL := EACH tonumber strkCommonCullSortL ; strt_priceL := TWIG tonumber (strkIndxL EACHBOTH EACHLEFT pick strt_priceL) ; endd_priceL := TWIG tonumber (strkIndxL EACHBOTH EACHLEFT pick endd_priceL) ; table_selects := transpose mix link [strkNumCommonL] strt_priceL ; table_selStd := 3 5 reshape 1020. 642.53 500.5 492.6 1501.28 1040. 610. 1501.28 492.6 500.5 1050. 582.9 531.15 638.93 674.21 ; IF (= table_selStd table_selects) THEN write ' option_calc_returnRatio_develop , table_selects result is OK' ; ELSE write '?option_calc_returnRatio_develop error, table_selects result is WRONG' ; ENDIF ; ratioL := endd_priceL EACHBOTH / strt_priceL ; table_ratios := aryMatTab_join_horizontal ((gage shape strkNumCommonL) 1 reshape strkNumCommonL) (transpose mix ratioL) ; col_titles := link ['strikePrice'] ((callOrPuttStr link '_') EACHRIGHT link (EACH YYMMDD_to_DDMMMYYYY dateStrikerL)) ; EACH write '' 'option_calc_returnRatio_test - table of call ratios' ; write table_addColTitles col_titles table_ratios ; } +-----+ olde code : +--+ link d_Qroot 'setup.ndf' : # sidelined code : indexesL := EACH tell (EACH (gage shape) ListOfLists) ; indexesIn_listAll := indexesL EACHLEFT in listAll ; addressListSorted := gradeup A ; addressListSorted EACHRIGHT choose ListOfLists indexLsSortedUniqueL := cull sortup link ListOfLists ; subListL := fullSortedUniqueList EACHLEFT EACHRIGHT in ListOfLists ; subListL EACHBOTH choose keysEach_indxsFor_keysAll := (keysAll EACHLEFT find keysEach) EACHBOTH pick (rowIndexes) ; keysEach_in_keysAll EACHBOTH sublist rowIndexes keysEach_in_keysAll := cols mix (keysAll EACHLEFT EACHRIGHT in keysEach) ; keysEach_indxsFor_keysAll := (keysAll EACHLEFT find keysEach) EACHBOTH pick (rowIndexes) ; listOfLists_findCommonItems_indexes IS OP listOfLists keyColIndxL { LOCAL keysAll keysAll_in_keysEach keysAll_indxsIn_keysEach keysEach rowIndexesL ; rowIndexesL := EACH (tell first) (EACH (gage shape) listOfLists) ; keysEach := keyColIndxL EACHBOTH pick (EACH cols listOfLists) ; keysAll := cull sortup link keysEach ; keysAll_in_keysEach := EACH AND (keysAll EACHLEFT EACHRIGHT in keysEach) ; keysAll := keysAll_in_keysEach sublist keysAll ; keysAll_indxsIn_keysEach := cols mix (keysAll EACHLEFT EACHRIGHT find keysEach) ; keysAll keysAll_indxsIn_keysEach } +--+ link d_Qndfs 'economics, markets/options data [download, process].ndf' stikerL stuff ('1060.00' '1070.00' '1080.00' '1090.00') ('1100.00' '1110.00' '1120.00' '1130.00' '1140.00' '1150.00') ('1160.00' '1170.00' '1180.00' '1190.00' '1200.00' '1220.00') ; strikerL strt_calls_priceL endd_calls_priceL strt_putts_priceL endd_putts_priceL := TWIG (strkIndxL pick) strikerL strt_calls_priceL endd_calls_priceL strt_putts_priceL endd_putts_priceL ; transpose mix ratio_callsL aryMatTab_join_horizontal (n_strikeSames 1 reshape strikerL) (aryMatTab_join_horizontal (EACH (transpose mix) ratio_callsL ratio_puttsL)) % tab_tit := (n_strikeSames 1 reshape strikerL) (EACH (transpose mix) ratio_callsL ratio_puttsL) ; transpose mix strt_calls_priceL transpose mix endd_calls_priceL transpose mix strt_putts_priceL transpose mix endd_putts_priceL 08********08 06May2021 qnial> add_ISOP_debug link d_Qroot 'setup.ndf' >> big oops!! wrong path! will have to fix later qnial> add_ISOP_debug link d_Qndfs 'email - mass response processing/email - split Thunderbird email folder.ndf' $ find "$d_Qroot" -maxdepth 2 -type f -name "*" | tr \\n \\0 | xargs -0 -IFILE grep --with-filename --line-number "gradeup" "FILE" >> after removing manual contes and other stuff : /media/bill/Dell2/Website - raw/Qnial/setup.ndf:1199: addressListSorted := gradeup A ; /media/bill/Dell2/Website - raw/Qnial/setup.ndf:1219: addressListSorted := gradeup A ; /media/bill/Dell2/Website - raw/Qnial/setup.ndf:1240: addressListSorted := gradeup A ; /media/bill/Dell2/Website - raw/Qnial/MY_NDFS/list searches - [sequential, bisections].ndf:44: IF ((gradeup a lister@addr) = (1 0)) THEN sgn := +1 ; ELSE sgn := -1 ; ENDIF ; /media/bill/Dell2/Website - raw/Qnial/setup Lenovo.ndf:454: addressListSorted := gradeup A ; $ find "$d_Qroot" -maxdepth 2 -type f -name "*" | tr \\n \\0 | xargs -0 -IFILE grep --with-filename --line-number "listsUniqueSorted_findCommonItems_indexes" "FILE" /media/bill/Dell2/Website - raw/Qnial/setup.ndf:1279:#] listsUniqueSorted_findCommonItems_indexes IS OP ListOfLists - find indexes having commons in ListOfLists 08********08 01May2021 08:32 - OK, basically works!! I can't see how to make mey on options - they decay too fast!! Even for insurance - very expensive, better to use sell stop limits +-----+ olde code is_templt_dateDwnLoad := 'downloadDate' subStr_in_str p_templt_dwnLoad ; is_templt_dateStriker := 'date' subStr_in_str p_templt_striker ; IF (XOR (1 EACHRIGHT = shape_dateDwnLoadL shape_dateStrikerL)) THEN write link '?gnuplot_options error : only ONE of date[DwnLoad,Striker]L is a string' ; noErrors := o ; ENDIF ; 08********08 30Apr2021 +-----+ olde code # loaddefs link d_Qndfs 'economics, markets/winURL yahoo finance options download.ndf' IF flag_debug THEN write 'loading yahooOptions_downLoad' ; ENDIF ; #] yahooOptions_downLoad IS OP d_symbol symbol dateDwnLoad dateStriker f_download #] text of url_strikes to [call,putt] files, gnuplot new dateStrike # 29Apr2021 initial # winIDorName_copyAllTextTo_ptemp - from # How do I handle strike dates? IF flag_break THEN BREAK ; ENDIF ; yahooOptions_downLoad IS OP d_symbol symbol dateDwnLoad dateStriker f_download { LOCAL winID_yahooOptionsTesla d_Markets d_start dateDwnLoad delay_brs f_temp p_current URL winName_yahooOptionsTesla ; NONLOCAL d_bin d_webRawe ; % ; % [dir, file, etc] definitions - specific for this optr ; d_start := link d_bin 'starter/' ; URL_base := link 'https://finance.yahoo.com/quote/' symbol '/options/' ; f_temp := 'yahooOptions_downLoad temp.txt' ; d_symArc := link d_symbol 'z_Archive/' ; FOR strike WITH strikeL DO URL := URL_base ; % URL := link URL_base url_strike ; winName_yahooOptionsTesla := link symbol ' ' ; path_backupDatedTo_dir p_strike (link d_symbol 'z_Archive/') ; p_callPutts := link d_symArc dateDwnLoad ' ' symbol ' calls&putts at dateDwnLoad ' dateDwnLoad '.txt' ; p_strike_call := link d_symArc dateDwnLoad ' ' symbol ' calls for ' strike '.dat' ; p_strike_putt := link d_symArc dateDwnLoad ' ' symbol ' putts for ' strike '.dat' ; % ; % open yahoo financial options URL in browser, code from "$d_bin""starter/start_Markets.sh" ; delay_brs := ' 3s ' ; cmd := link 'bash "' d_start '""start_app.sh" ' delay_brs ' "browser" "' url '" ""' ; IF flag_debug THEN write cmd ; ENDIF ; host cmd ; host 'sleep 5s' ; winID_yahooOptionsTesla := winTitle_get_winID (5 take winName_yahooOptionsTesla) ; host 'sleep 3s' ; IF flag_debug THEN write 'winID_yahooOptionsTesla = ' winID_yahooOptionsTesla ; ENDIF ; p_current := winIDorName_copyAllTextTo_ptemp winName_yahooOptionsTesla f_temp ; % YIKES!!! this might close ALL browser [tab,window]s ; % host link 'xdotool key --window ' winID_yahooOptionsTesla ' ctrl+q' ; % ; % ToDo - p_current extract calls and putts ; p_cleaned := link p_current ' cleaned.txt' ; % host link 'rm "' p_cleaned '"' ; pinn_yahooOptionsExtract_pCalls_pPutts p_callPutts p_strike_call p_strike_putt ; ENDFOR ; } loaddefs link d_Qndfs 'economics, markets/options data [download, process].ndf' IF flag_debug THEN write 'loading symbolYahoo_updates' ; ENDIF ; #] symbolYahoo_updates IS - add new [call, putt] files from dateDwnLoad # 30Apr2021 This is kind of like a "test operator", or for adaptation to special situations # NOTE : d_symbol here is the z_Archive subdirectory symbolYahoo_updates IS OP dateDwnLoad dateStriker { LOCAL d_symbol f_templt symbol ; symbol := 'TSLA' ; d_symbol := link '/media/bill/Dell2/Website - raw/economics, markets/options/' symbol '/z_Archive/' ; FOR dateStriker WITH dateStrikerL DO f_download := link dateDwnLoad ' ' symbol ' options date ' dateStriker '.txt' ; symbolYahoo_extract_callPutFiles d_symbol symbol dateDwnLoad dateStriker f_download ; ENDFOR ; } # loaddefs link d_Qndfs 'economics, markets/options data [download, process].ndf' IF flag_debug THEN write 'loading gnuplot_options_updates' ; ENDIF ; #] gnuplot_options_updates IS - plot options curves as per specified dates # 30Apr2021 This is kind of like a "test operator", or for adaptation to special situations gnuplot_options_updates IS { LOCAL symbol d_symbol f_templt ; symbol := 'TSLA' ; d_symbol := link '/media/bill/Dell2/Website - raw/economics, markets/options/' symbol '/' ; f_templt := '0_Tesla calls&puts for a strikeDate over time gnuplot template.plt' ; gnuplot_options d_symbol symbol ('210407' '210418' '210422' '210422' '210424') ['210430'] f_templt ; % ; f_templt := '0_Tesla calls&puts at a downloadDate gnuplot template.plt' ; gnuplot_options d_symbol symbol ['210424'] ('210430' '210514' '210528' '210618') f_templt ; } 08********08 29Apr2021 +-----+ olde code # old updates : symbol := 'TSLA' ; d_symbol := link '/media/bill/Dell2/Website - raw/economics, markets/options/' symbol '/' ; f_templt := '0_Tesla calls&puts for a strikeDate over time gnuplot template.plt' ; gnuplot_options d_symbol symbol ('210407' '210418' '210422') ['210430'] f_templt ; % ; f_templt := '0_Tesla calls&puts at a downloadDate gnuplot template.plt' ; gnuplot_options d_symbol symbol ['210422'] ('210430' '210514' '210528') f_templt ; # loaddefs link d_Qndfs 'economics, markets/options data [download, process].ndf' IF flag_debug THEN write 'loading list_datPaths' ; ENDIF ; #] list_datPaths IS OP d_symbol symbol dateDwnLoadL dateStrikerL - lists date[DwnLoad,Striker] paths # 24Apr2021 initial list_datPaths IS OP d_symbol symbol dateDwnLoadL dateStrikerL { LOCAL d_symbol f_templt f_dwnld1 f_dwnld2 f_dwnld3 ; % ; % search-replace dates and plotCurves for gnuTemplate file ; YY MM DD := (0 1) (2 3) (4 5) EACHLEFT choose dateStriker ; month := month_name MM ; dateStrikerHuman := link DD month '20' YY ; datePlottedHuman := timestamp_DDMMMYYYY ; % ; % generate a list of data files and plotCurves for gnuTemplate file ; cmd := link 'find "' d_arc '" -maxdepth 1 -type f -name "*' dateStriker '.dat" ' ' >"' p_temp '"' ; % ; % create gnuplot plt & image for comparing same strikeDate at differnt dateDwnLoads ; FOR dateDwnLoad WITH dateDwnLoadL DO gnuplot_dateStriker d_symbol symbol dateDwnLoad dateStriker f_templt ; ENDFOR ; } # loaddefs link d_Qndfs 'economics, markets/options data [download, process].ndf' IF flag_debug THEN write 'loading plot_options' ; ENDIF ; #] plot_options IS OP dateDwnLoadL dateStrikerL - makes the gnuplot file, plots [call, putts] #] for each [dateDwnLoadL, dateStriker] # 23Apr2021 initial # 23Apr2021 [dateDwnLoadL, dateStrikerL] - must handle dates already processed plot_options IS OP d_symbol symbol dateDwnLoad dateStrikerL { LOCAL d_symbol f_templt f_dwnld1 f_dwnld2 f_dwnld3 ; % ; % create gnuplot plt & image for comparing different strikeDates ; FOR dateDwnLoad WITH dateDwnLoadL DO f_dwnld := link dateDwnLoad ' ' symbol ' options strikeDate ' dateStriker1 '.txt' ; symbolYahoo_extract_callPutFiles d_symbol symbol dateDwnLoad dateStriker1 f_dwnld1 ; gnuplot_script d_symbol symbol dateDwnLoad dateStriker1 dateStriker2 dateStriker3 f_templt ; ENDFOR ; % ; % create gnuplot plt & image for comparing same strikeDate at differnt dateDwnLoads ; FOR dateDwnLoad WITH dateDwnLoadL DO gnuplot_dateStriker d_symbol symbol dateDwnLoad dateStriker f_templt ; ENDFOR ; } #] Operators for specific symbols # loaddefs link d_Qndfs 'economics, markets/options data [download, process].ndf' IF flag_debug THEN write '+-----+' ; ENDIF ; IF flag_debug THEN write 'Operators for specific symbols' ; ENDIF ; # loaddefs link d_Qndfs 'economics, markets/options data [download, process].ndf' IF flag_debug THEN write 'loading TESLA_options_process' ; ENDIF ; #] TESLA_options_process IS OP dateDwnLoad dateStriker1 dateStriker2 dateStriker3 - #] creates files of [call, putts] for each dateStriker, makes the gnuplot file, plots data TESLA_options_process IS OP dateDwnLoad dateStrikerL { LOCAL f_templt symbol d_symbol f_templt f_dwnld1 f_dwnld2 f_dwnld3 ; symbol := 'TSLA' ; d_symbol := link '/media/bill/Dell2/Website - raw/economics, markets/options/' symbol '/' ; f_templt := link '0_' Tesla calls&puts at a downloadDate gnuplot template.plt' ; plot_options d_symbol symbol dateDwnLoad f_templt dateStrikerL ; } # TESLA_options_process '210422' '210430' '210514' '210528' % url_strike date_strike p_strike := strike ; 08********08 24Apr2021 link d_Qndfs 'economics, markets/options data [download, process].ndf' % human-readable date strings ; dateDwnLoadL := EACH YYMMDD_to_DDMMMYYYY dateDwnLoadL ; dateStrikerL := EACH YYMMDD_to_DDMMMYYYY dateStrikerL ; +-----+ Copy for direct comparison of date[Striker, DwnLoad] #] gnuplot_dateDwnLoad IS OP d_symbol symbol dateDwnLoad dateStrikerL f_templt - create script #] for [call, putt] gnuplot showing a range of strike dates at a given date (download of data) # 22Apr2021 initial IF flag_break THEN BREAK ; ENDIF ; gnuplot_dateDwnLoad IS OP d_symbol symbol dateDwnLoad dateStrikerL f_templt { LOCAL dateHuman line pCall pPutt pPlot pTmpl ; NONLOCAL d_webRawe ; % ; % verify that paths are allowable ; d_arc := link d_symbol 'z_Archive/' ; pTmpl := link d_symbol f_templt ; pPlot := link d_symbol dateDwnLoad ' ' symbol ' calls&puts for strikeDate over time gnuplot.plt' ; IF (NOT AND (EACH path_exists ("w d_arc) ("r pTmpl) ("w pPlot))) THEN EACH write '?path_backupTo_dir error, file unknown, one of : ' d_arc pTmpl pPlot '' ; ELSE % human-readable dateDwnLoad string ; YY MM DD := (0 1) (2 3) (4 5) EACHLEFT choose dateDwnLoad ; month := month_name MM ; dateDwnLoadHuman := link DD month '20' YY ; % ; % create [human-readable dateStrikerL, curve command-lines] for gnuplot ; i := 0 ; ender := '\' ; n_curves := (gage shape dateStrikerL) - 1 ; curveL := null ; FOR curve WITH dateStrikerL DO % human-readable dateStrikerL strings ; YY MM DD := (0 1) (2 3) (4 5) EACHLEFT choose dateStrikerL@i ; month := month_name MM ; dateStrikerHuman := link DD month '20' YY ; datePlotted := timestamp_YYMMDD ; % ; % curve command-lines ; IF (= i n_curves) THEN ender := '' ; ENDIF ; curveL := link curveL [chr_tab chr_apo curve ' using 3:6 w lp ls 10' (string i) ' title "' callOrPutt ' ' dateStriker '", ' ender ] ; i := i + 1 ; ENDFOR ; % ; % set up gnuplot files ; finn := open pTmpl "r ; fout := open pPlot "w ; WHILE ( ~= ??eof (line := readfile finn)) DO IF (= '' line) THEN % insert [date, plotCurve]s into gnuTemplate file ; fout EACHRIGHT writefile curveL ; ELSE line := str_replace_subStr '' datePlotted line ; line := str_replace_subStr '' dateStriker line ; line := str_replace_subStr '' dateStrikerHuman line ; writefile fout line ; ENDIF ; ENDWHILE ; EACH close finn fout ; % ; % create plot image ; cmd := link 'gnuplot "' pPlot '"' ; write cmd ; host cmd ; ENDIF ; } # loaddefs link d_Qndfs 'economics, markets/options data [download, process].ndf' IF flag_debug THEN write 'loading gnuplot_dateStriker' ; ENDIF ; #] gnuplot_dateStriker IS OP d_symbol symbol dateDwnLoadL dateStriker f_templt - #] create script for [call, putt] gnuplot showing a given strike price across dates # 23Apr2021 initial, limited to 6 gnuplot linestyles (curves) IF flag_break THEN BREAK ; ENDIF ; gnuplot_dateStriker IS OP d_symbol symbol dateDwnLoadL dateStriker f_templt { LOCAL dateHuman line pCall pPutt pPlot pTmpl ; NONLOCAL d_webRawe ; % ; % verify that paths are allowable ; d_arc := link d_symbol 'z_Archive/' ; pTmpl := link d_symbol f_templt ; pPlot := link d_symbol dateDwnLoad ' ' symbol ' calls&puts for strikeDate over time gnuplot.plt' ; IF (NOT AND (EACH path_exists ("w d_arc) ("r pTmpl) ("w pPlot))) THEN EACH write '?path_backupTo_dir error, file unknown, one of : ' d_arc pTmpl pPlot '' ; ELSE % human-readable dateStriker string ; YY MM DD := (0 1) (2 3) (4 5) EACHLEFT choose dateStriker ; month := month_name MM ; dateStrikerHuman := link DD month '20' YY ; % ; % create [human-readable dateDwnLoadL, curve command-lines] for gnuplot ; % create list of curve command-lines for gnuplot ; i := 0 ; ender := '\' ; n_curves := (gage shape dateDwnLoadL) - 1 ; curveL := null ; FOR curve WITH dateDwnLoadL DO IF (= i n_curves) THEN ender := '' ; ENDIF ; curveL := link curveL [chr_tab chr_apo curve ' using 3:6 w lp ls 10' (string i) ' title "' callOrPutt '@dateDwnLoad ' dateDwnLoadL '", ' ender ] ; i := i + 1 ; ENDFOR ; % ; % create gnuplot plt file ; % insert [date, plotCurve]s into gnuTemplate file ; finn := open pTmpl "r ; fout := open pPlot "w ; WHILE ( ~= ??eof (line := readfile finn)) DO IF (= '' line) THEN fout EACHRIGHT writefile curveL ; ELSE line := str_replace_subStr '' datePlotted line ; line := str_replace_subStr '' dateStriker line ; line := str_replace_subStr '' dateStrikerHuman line ; writefile fout line ; ENDIF ; ENDWHILE ; EACH close finn fout ; % ; % create image ; cmd := link 'gnuplot "' pPlot '"' ; write cmd ; host cmd ; ENDIF ; } +-----+ olde code # loaddefs link d_Qndfs 'economics, markets/options data [download, process].ndf' IF flag_debug THEN write 'loading createCurves_at_dateStriker' ; ENDIF ; #] createCurves_at_dateStriker IS OP d_arc symbol dateDwnLoadL dateStrikerL - res ipsa loquitor # 24Apr2021 initial createCurves_at_dateStriker d_arc symbol dateDwnLoadL dateStrikerL { LOCAL curveL ender i dateDwnLoad dateStriker ; i := 0 ; ender := '\' ; curveL := null ; % do calls first - keep legend collected together by [call,putt]s ; FOR dateDwnLoad WITH dateDwnLoadL DO FOR dateStriker WITH dateStrikerL DO curveL := append curveL ( link chr_tab chr_apo d_arc dateDwnLoad ' ' symbol ' calls for ' dateStriker '.dat' chr_apo ' using 3:6 w lp ls 10' (string i) ' title "calls ' dateDwnLoad '", ' ender ) ; i := i + 1 ; ENDFOR ; ENDFOR ; % now do putts, do NOT zero curve counter i! ; FOR dateDwnLoad WITH dateDwnLoadL DO FOR dateStriker WITH dateStrikerL DO curveL := append curveL ( link chr_tab chr_apo d_arc dateDwnLoad ' ' symbol ' putts for ' dateStriker '.dat' chr_apo ' using 3:6 w lp ls 10' (string i) ' title "putts ' dateDwnLoad '", ' ender ) ; i := i + 1 ; ENDFOR ; ENDFOR ; curveL } # loaddefs link d_Qndfs 'economics, markets/options data [download, process].ndf' IF flag_debug THEN write 'loading createCurves_at_dateDwnLoad' ; ENDIF ; #] createCurves_at_dateDwnLoad IS OP d_arc symbol dateDwnLoadL dateStrikerL - res ipsa loquitor # 24Apr2021 initial createCurves_at_dateDwnLoad IS OP d_arc symbol dateDwnLoadL dateStrikerL { LOCAL curveL ender i dateDwnLoad dateStriker ; i := 0 ; ender := '\' ; curveL := null ; % do calls first - keep legend collected together by [call,putt]s ; FOR dateDwnLoad WITH dateDwnLoadL DO FOR dateStriker WITH dateStrikerL DO curveL := append curveL ( link chr_tab chr_apo d_arc dateDwnLoad ' ' symbol ' calls for ' dateStriker '.dat' chr_apo ' using 3:6 w lp ls 10' (string i) ' title "calls ' dateStriker '", ' ender ) ; i := i + 1 ; ENDFOR ; ENDFOR ; % now do putts, do NOT zero curve counter i! ; FOR dateDwnLoad WITH dateDwnLoadL DO FOR dateStriker WITH dateStrikerL DO curveL := append curveL ( link chr_tab chr_apo d_arc dateDwnLoad ' ' symbol ' putts for ' dateStriker '.dat' chr_apo ' using 3:6 w lp ls 10' (string i) ' title "putts ' dateStriker '", ' ender ) ; i := i + 1 ; ENDFOR ; ENDFOR ; curveL } # $ find '/media/bill/Dell2/Website - raw/economics, markets/options/TSLA/z_Archive/' -maxdepth 1 -type f -name "*210430.dat" | sed 's#/media/bill/Dell2/Website - raw/economics, markets/options/TSLA/z_Archive/##' # don't need : ' | sed ' chr_apo 's#' d_arc '##' cmd := link 'cat "' pTmpl '" | sed ' chr_apo 's//' dateStrikerHuman '/g;' 's//' datePlottedHuman '/g;' 's//' dateStriker3 '/g' chr_apo ' >"' pPlot '"' ; write cmd ; host cmd ; # enddoc