From 24bff9a13a669bfc9285a43d4597c12bb05c4dc4 Mon Sep 17 00:00:00 2001 From: olli Date: Thu, 5 Oct 2023 17:03:54 +0200 Subject: [PATCH] updated market performance calculation --- dabo/functions/get_assets.sh | 4 +- dabo/functions/market_performance.sh | 66 ++++++++++++++++++++++------ dabo/functions/webpage.sh | 29 +++++++++++- 3 files changed, 81 insertions(+), 18 deletions(-) diff --git a/dabo/functions/get_assets.sh b/dabo/functions/get_assets.sh index 348ccb0..a93fa44 100644 --- a/dabo/functions/get_assets.sh +++ b/dabo/functions/get_assets.sh @@ -97,11 +97,11 @@ function get_assets { get_boerse_de https://www.boerse.de/realtime-kurse/MSCI-World/XC0009692739 MSCI-WORLD-INDEX get_boerse_de https://www.boerse.de/indizes/SundP-500/US78378X1072 SP500-INDEX - get_boerse_de https://www.boerse.de/indizes/DJ-AMER-OIL-und-GAS/XC0006886516 OIL-GAS-INDEX + get_boerse_de https://www.boerse.de/indizes/DJ-AMER-OIL-und-GAS/XC0006886516 OIL-GAS-INVERTED-INDEX get_boerse_de https://www.boerse.de/fonds/SPDR-SundP-Regional-Banking-ETF/US78464A6982 KRE-BANKING-INDEX get_boerse_de https://www.boerse.de/indizes/Dax/DE0008469008 DAX-INDEX get_boerse_de https://www.boerse.de/indizes/Nasdaq-100/US6311011026 NASDAQ-INDEX - get_boerse_de https://www.boerse.de/devisen/Dollar-Euro/XC0009666410 DXY-INDEX + get_boerse_de https://www.boerse.de/devisen/Dollar-Euro/XC0009666410 DXY-INVERTED-INDEX } diff --git a/dabo/functions/market_performance.sh b/dabo/functions/market_performance.sh index a1956e2..22c1910 100644 --- a/dabo/functions/market_performance.sh +++ b/dabo/functions/market_performance.sh @@ -54,18 +54,54 @@ function market_performance { f_eth_forecast=$(echo "scale=2; ${f_eth_forecast}/3" | bc -l | sed -r 's/^(-?)\./\10./') - # price performance msci world (last week and halved because of the long time) - local f_msci_last_date=$(tail -n1 asset-histories/MSCI-WORLD-INDEX.history.csv | cut -d, -f1) - local f_from=$(egrep "^$(date -d "${f_msci_last_date} last week" "+%Y-%m-%d %H:" | cut -d, -f1 | tail -n1)" asset-histories/MSCI-WORLD-INDEX.history.csv | head -n1 | cut -d, -f2) - [ -z "${f_from}" ] && f_from=$(egrep "^$(date -d "${f_msci_last_date} last week" "+%Y-%m-%d " | cut -d, -f1 | tail -n1)" asset-histories/MSCI-WORLD-INDEX.history.csv | head -n1 | cut -d, -f2) - local f_to=$(tail -n 1 asset-histories/MSCI-WORLD-INDEX.history.csv | cut -d, -f2) - local f_exchange_rate_diff_percentage=$(g_percentage-diff ${f_from} ${f_to}) - if [ ${f_to} == "0" ] || [ ${f_from} == "0" ] - then - local f_msci_world_performance="-0.1" - else - local f_msci_world_performance=$(echo "scale=2; ${f_exchange_rate_diff_percentage}/2" | bc -l | sed -r 's/^(-?)\./\10./') - fi + # Calculate available Index week changes + local f_index_performance_txt="" + local f_index_performance_added=0 + local f_index_performance_csv="" + for f_INDEX in DXY-INVERTED SP500 NASDAQ MSCI-WORLD OIL-GAS-INVERTED DAX KRE-BANKING + do + # day average 1 week ago + local f_from=$(grep "^$(date "+%Y-%m-%d" -d "last week") " asset-histories/${f_INDEX}-INDEX.history.csv | cut -d, -f2 | awk '{ sum += $1; n++ } END { if (n > 0) print sum / n; }') + [ -z "${f_from}" ] && f_from=0 + # latest value + local f_to=$(tail -n 1 asset-histories/${f_INDEX}-INDEX.history.csv | cut -d, -f2) + [ -z "${f_to}" ] && f_to=0 + if [ ${f_to} == "0" ] || [ ${f_from} == "0" ] + then + # default to -0.1 if no week data available + local f_index_performance="-0.1" + else + # calculate performance + local f_index_performance=$(g_percentage-diff ${f_from} ${f_to}) + fi + # if growing is bad for krypto - invert + if echo ${f_INDEX} | grep -q INVERTED + then + if echo "${f_index_performance}" | grep -q ^- + then + f_index_performance=$(echo ${f_index_performance} | sed 's/^-//') + else + f_index_performance="-${f_index_performance}" + fi + fi + # finishing vars + f_index_performance_txt="${f_index_performance_txt}${f_INDEX}: ${f_index_performance}%; " + f_index_performance_added="$(echo "scale=2; ${f_index_performance_added}+${f_index_performance}" | bc -l | sed -r 's/^(-?)\./\10./')" + f_index_performance_csv="${f_index_performance_csv},${f_index_performance}" + done + + ## price performance msci world (last week and halved because of the long time) + #local f_msci_last_date=$(tail -n1 asset-histories/MSCI-WORLD-INDEX.history.csv | cut -d, -f1) + #local f_from=$(egrep "^$(date -d "${f_msci_last_date} last week" "+%Y-%m-%d %H:" | cut -d, -f1 | tail -n1)" asset-histories/MSCI-WORLD-INDEX.history.csv | head -n1 | cut -d, -f2) + #[ -z "${f_from}" ] && f_from=$(egrep "^$(date -d "${f_msci_last_date} last week" "+%Y-%m-%d " | cut -d, -f1 | tail -n1)" asset-histories/MSCI-WORLD-INDEX.history.csv | head -n1 | cut -d, -f2) + #local f_to=$(tail -n 1 asset-histories/MSCI-WORLD-INDEX.history.csv | cut -d, -f2) + #local f_exchange_rate_diff_percentage=$(g_percentage-diff ${f_from} ${f_to}) + #if [ ${f_to} == "0" ] || [ ${f_from} == "0" ] + #then + # local f_msci_world_performance="-0.1" + #else + # local f_msci_world_performance=$(echo "scale=2; ${f_exchange_rate_diff_percentage}/2" | bc -l | sed -r 's/^(-?)\./\10./') + #fi @@ -87,9 +123,11 @@ function market_performance { local f_top250_marketcap_performance=$(jq -r ".[].price_change_percentage_1h_in_currency" COINGECKO_GET_ASSETS_CMD_OUT | awk '{ SUM += $1} END { printf("%.2f", SUM/250) }') ## calculate market performance - f_market_performance=$(echo "scale=2; (${f_btc_forecast} + ${f_eth_forecast} + ${f_msci_world_performance} + ${f_btc_performance} + ${f_eth_performance} + ${f_top250_marketcap_performance})/6" | bc -l | sed -r 's/^(-?)\./\10./') + f_market_performance=$(echo "scale=2; (${f_btc_forecast} + ${f_eth_forecast} + ${f_index_performance_added} + ${f_btc_performance} + ${f_eth_performance} + ${f_top250_marketcap_performance})/6" | bc -l | sed -r 's/^(-?)\./\10./') local f_date=$(g_date_print) - echo "${f_date} Market Performance: ${f_market_performance}%; BTC forecast: ${f_btc_forecast}%; ETH forecast: ${f_eth_forecast}%; MSCI WORLD: ${f_msci_world_performance}%; BTC: ${f_btc_performance}%; ETH: ${f_eth_performance}%; TOP250 Marketcap: ${f_top250_marketcap_performance}%" >>MARKET_PERFORMANCE + echo "${f_date} Market Performance: ${f_market_performance}%; BTC forecast: ${f_btc_forecast}%; ETH forecast: ${f_eth_forecast}%; ${f_index_performance_txt}BTC: ${f_btc_performance}%; ETH: ${f_eth_performance}%; TOP250 Marketcap: ${f_top250_marketcap_performance}%" >>MARKET_PERFORMANCE + [ -s MARKET_PERFORMANCE.csv ] || echo "date,market performance,btc,eth,btc forecast,eth forecast,top250,DXY-INVERTED,SP500,NASDAQ,MSCI-WORLD,OIL-GAS-INVERTED,DAX,KRE-BANKING" >MARKET_PERFORMANCE.csv + echo "${f_date},${f_market_performance},${f_btc_performance},${f_eth_performance},${f_btc_forecast},${f_eth_forecast},${f_top250_marketcap_performance}${f_index_performance_csv}" >>MARKET_PERFORMANCE.csv echo -n "${f_market_performance}" >MARKET_PERFORMANCE_LATEST } diff --git a/dabo/functions/webpage.sh b/dabo/functions/webpage.sh index 2998c12..4809f51 100644 --- a/dabo/functions/webpage.sh +++ b/dabo/functions/webpage.sh @@ -92,8 +92,33 @@ function webpage { echo "" >>../index.html.tmp echo "

Market Performance ( $(cat MARKET_PERFORMANCE_LATEST)%)

" >>../index.html.tmp - echo -e "
$(egrep ":00:" MARKET_PERFORMANCE | tail -n10)\n$(tail -n1 MARKET_PERFORMANCE)
" >>../index.html.tmp - echo "Complete list" >>../index.html.tmp + echo "" >>../index.html.tmp + head -n1 MARKET_PERFORMANCE.csv | perl -pe 's/,/\n/g' | while read f_mperfcol + do + echo "" >>../index.html.tmp + done + echo "" >>../index.html.tmp + egrep "^[0-9][0-9]" MARKET_PERFORMANCE.csv | tail -n10 | while read f_mperfline + do + f_mperfline="$(echo ${f_mperfline} | perl -pe 's/ /_/g; s/,/ /g')" + echo "" >>../index.html.tmp + #echo "${mperfline}" | perl -pe 's/,/\n/g' | while read f_mperfcol + for f_mperfcol in ${f_mperfline} + do + if echo "${f_mperfcol}" | grep -q ":" + then + f_mperfcol="$(echo ${f_mperfcol} | perl -pe 's/_/ /')" + echo "" >>../index.html.tmp + else + echo "" >>../index.html.tmp + fi + done + echo "" >>../index.html.tmp + done + + echo "
${f_mperfcol}
${f_mperfcol} ${f_mperfcol}%
" >>../index.html.tmp + echo "Complete list" >>../index.html.tmp + echo "

Top/Flop

" >>../index.html.tmp ls -1 trade-histories/*.result | cut -d . -f3-6 | sort -u | while read f_asset_results