updated market performance calculation

This commit is contained in:
olli 2023-10-05 17:03:54 +02:00
parent c2dd60e021
commit 24bff9a13a
3 changed files with 81 additions and 18 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -92,8 +92,33 @@ function webpage {
echo "</table>" >>../index.html.tmp
echo "<h2>Market Performance ( $(cat MARKET_PERFORMANCE_LATEST)%)</h2>" >>../index.html.tmp
echo -e "<pre>$(egrep ":00:" MARKET_PERFORMANCE | tail -n10)\n$(tail -n1 MARKET_PERFORMANCE)</pre>" >>../index.html.tmp
echo "<a href=\"botdata/MARKET_PERFORMANCE\">Complete list</a>" >>../index.html.tmp
echo "<table><tr>" >>../index.html.tmp
head -n1 MARKET_PERFORMANCE.csv | perl -pe 's/,/\n/g' | while read f_mperfcol
do
echo "<td><b>${f_mperfcol}</b></td>" >>../index.html.tmp
done
echo "</tr>" >>../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 "<tr>" >>../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 "<td><b>${f_mperfcol}</b></td>" >>../index.html.tmp
else
echo "<td> ${f_mperfcol}%</td>" >>../index.html.tmp
fi
done
echo "</tr>" >>../index.html.tmp
done
echo "</table>" >>../index.html.tmp
echo "<a href=\"botdata/MARKET_PERFORMANCE.csv\">Complete list</a>" >>../index.html.tmp
echo "<h2>Top/Flop</h2>" >>../index.html.tmp
ls -1 trade-histories/*.result | cut -d . -f3-6 | sort -u | while read f_asset_results