updated market performance calculation and get_marketdata.sh; added US Market data

This commit is contained in:
olli 2023-10-06 10:52:20 +02:00
parent 24bff9a13a
commit 7da8f09630
5 changed files with 70 additions and 43 deletions

View File

@ -95,13 +95,15 @@ function get_assets {
export csv_headline export csv_headline
. /tmp/parallel . /tmp/parallel
get_boerse_de https://www.boerse.de/realtime-kurse/MSCI-World/XC0009692739 MSCI-WORLD-INDEX get_marketdata 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_marketdata 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-INVERTED-INDEX get_marketdata 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_marketdata 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_marketdata https://www.boerse.de/indizes/Dax/DE0008469008 DAX-INDEX
get_boerse_de https://www.boerse.de/indizes/Nasdaq-100/US6311011026 NASDAQ-INDEX get_marketdata https://www.boerse.de/indizes/Nasdaq-100/US6311011026 NASDAQ-INDEX
get_boerse_de https://www.boerse.de/devisen/Dollar-Euro/XC0009666410 DXY-INVERTED-INDEX get_marketdata https://www.investing.com/indices/usdollar DXY-INVERTED-INDEX
get_marketdata https://www.investing.com/economic-calendar/unemployment-rate-300/ US-UNEMPLOYMENT-INDEX
get_marketdata https://www.investing.com/economic-calendar/cpi-733 US-CONSUMER-PRICE-INDEX
} }

View File

@ -1,33 +0,0 @@
function get_boerse_de {
local f_url="$1"
local f_name="$2"
# get data for analysis
echo "wget -q -O - ${f_url} | egrep 'itemprop=\"price\" content=\"[0-9]+\.[0-9]+\"' | cut -d\\\" -f6" >BOERSE_DE_CMD
g_runcmd g_retrycmd sh BOERSE_DE_CMD >BOERSE_DE_CMD_OUT-${f_name}.tmp
# check output
if [ -s BOERSE_DE_CMD_OUT-${f_name}.tmp ] && egrep -q "^[0-9]*\.[0-9]+$" BOERSE_DE_CMD_OUT-${f_name}.tmp
then
if egrep -q "^0\.00$" BOERSE_DE_CMD_OUT-${f_name}.tmp
then
g_echo_note "Ignoring ${f_name} $(tail -n 10 BOERSE_DE_CMD_OUT-${f_name}.tmp) - maybe out of business day"
else
g_echo_note "${f_name}: $(tail -n 10 BOERSE_DE_CMD_OUT-${f_name}.tmp)"
mv BOERSE_DE_CMD_OUT-${f_name}.tmp BOERSE_DE_CMD_OUT-${f_name}
fi
else
g_echo_warn "BOERSE_DE_CMD_OUT-${f_name}.tmp has wrong Syntax. - Not updating ${f_name} Index $(tail -n 10 BOERSE_DE_CMD_OUT-${f_name}.tmp)"
fi
if ! [ -e "BOERSE_DE_CMD_OUT-${f_name}" ]
then
local f_old_value=$(tail -n 1 asset-histories/${f_name}.history.csv | cut -d, -f2)
if echo ${f_old_value} | egrep -q "^[0-9]*\.[0-9]+$"
then
echo ${f_old_value} >BOERSE_DE_CMD_OUT-${f_name}
else
echo 0 >BOERSE_DE_CMD_OUT-${f_name}
fi
fi
echo "${f_timestamp},$(cat BOERSE_DE_CMD_OUT-${f_name})" >>asset-histories/${f_name}.history.csv
}

View File

@ -0,0 +1,41 @@
function get_marketdata {
local f_url="$1"
local f_name="$2"
## get data for analysis
# check source platform for parsing parameters, prepare and run wget command
>MARKET_DATA_CMD
echo ${f_url} | grep -q "boerse.de" && echo "wget -q -O - ${f_url} | egrep 'itemprop=\"price\" content=\"[0-9]+\.[0-9]+\"' | cut -d\\\" -f6" >MARKET_DATA_CMD
echo ${f_url} | egrep -q "investing.com.+economic-calendar" && echo "wget -q -O - ${f_url} | egrep 'Actual.+Forecast.+Previous' | cut -d'>' -f7,11 | cut -d'<' -f1,2 | sed 's#,##g' | sed 's#\%##g' | sed 's#</div>#,#'" >MARKET_DATA_CMD
echo ${f_url} | egrep -q "investing.com.+indices" && echo "wget -q -O - ${f_url} | sed 's#</div>#\n#g' | grep 'text-5xl font-bold leading-9 md:text-' | cut -d'>' -f5 | sed 's#,##g'" >MARKET_DATA_CMD
[ -s MARKET_DATA_CMD ] || echo "wget -q -O - ${f_url}" >MARKET_DATA_CMD
g_runcmd g_retrycmd sh MARKET_DATA_CMD >MARKET_DATA_CMD_OUT-${f_name}.tmp
# check output
if [ -s MARKET_DATA_CMD_OUT-${f_name}.tmp ] && egrep -q "^[0-9]*\.[0-9]+" MARKET_DATA_CMD_OUT-${f_name}.tmp
then
if egrep -q "^0\.00" MARKET_DATA_CMD_OUT-${f_name}.tmp
then
g_echo_note "Ignoring ${f_name} $(tail -n 10 MARKET_DATA_CMD_OUT-${f_name}.tmp) - maybe out of business day"
else
g_echo_note "${f_name}: $(tail -n 10 MARKET_DATA_CMD_OUT-${f_name}.tmp)"
mv MARKET_DATA_CMD_OUT-${f_name}.tmp MARKET_DATA_CMD_OUT-${f_name}
fi
else
g_echo_warn "MARKET_DATA_CMD_OUT-${f_name}.tmp has wrong Syntax. - Not updating ${f_name} Index $(tail -n 10 MARKET_DATA_CMD_OUT-${f_name}.tmp)"
fi
if ! [ -e "MARKET_DATA_CMD_OUT-${f_name}" ]
then
local f_old_value=$(tail -n 1 asset-histories/${f_name}.history.csv | cut -d, -f2)
if echo ${f_old_value} | egrep -q "^[0-9]*\.[0-9]+"
then
echo ${f_old_value} >MARKET_DATA_CMD_OUT-${f_name}
else
echo 0 >MARKET_DATA_CMD_OUT-${f_name}
fi
fi
echo "${f_timestamp},$(cat MARKET_DATA_CMD_OUT-${f_name})" >>asset-histories/${f_name}.history.csv
}

View File

@ -54,14 +54,19 @@ function market_performance {
f_eth_forecast=$(echo "scale=2; ${f_eth_forecast}/3" | bc -l | sed -r 's/^(-?)\./\10./') f_eth_forecast=$(echo "scale=2; ${f_eth_forecast}/3" | bc -l | sed -r 's/^(-?)\./\10./')
# Calculate available Index week changes # Calculate available market data week changes
local f_index_performance_txt="" local f_index_performance_txt=""
local f_index_performance_added=0 local f_index_performance_added=0
local f_index_performance_csv="" local f_index_performance_csv=""
local f_INDEX
for f_INDEX in DXY-INVERTED SP500 NASDAQ MSCI-WORLD OIL-GAS-INVERTED DAX KRE-BANKING for f_INDEX in DXY-INVERTED SP500 NASDAQ MSCI-WORLD OIL-GAS-INVERTED DAX KRE-BANKING
do do
# day average 1 week ago # 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; }') 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; }')
# fallback this or last month
[ -z "${f_from}" ] && f_from=$(grep "^$(date "+%Y-%m-")" 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=$(grep "^$(date "+%Y-%m-" -d "last month")" asset-histories/${f_INDEX}-INDEX.history.csv | cut -d, -f2 | awk '{ sum += $1; n++ } END { if (n > 0) print sum / n; }')
# if no data
[ -z "${f_from}" ] && f_from=0 [ -z "${f_from}" ] && f_from=0
# latest value # latest value
local f_to=$(tail -n 1 asset-histories/${f_INDEX}-INDEX.history.csv | cut -d, -f2) local f_to=$(tail -n 1 asset-histories/${f_INDEX}-INDEX.history.csv | cut -d, -f2)
@ -90,6 +95,18 @@ function market_performance {
f_index_performance_csv="${f_index_performance_csv},${f_index_performance}" f_index_performance_csv="${f_index_performance_csv},${f_index_performance}"
done done
# calculate forecast US Unemployment Rate and US Consumer Price Index (CPI)
local f_economic
for f_eco_data in US-UNEMPLOYMENT-INDEX US-CONSUMER-PRICE-INDEX
do
local f_current=$(tail -n 1 asset-histories/${f_eco_data}.history.csv | cut -d, -f2)
local f_forecast=$(tail -n 1 asset-histories/${f_eco_data}.history.csv | cut -d, -f3)
f_index_performance="$(echo "scale=2; ${f_current}-${f_forecast}" | bc -l | sed -r 's/^(-?)\./\10./')"
f_index_performance_txt="${f_index_performance_txt}${f_eco_data}: ${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) ## 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_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) #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)
@ -126,7 +143,7 @@ function market_performance {
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./') 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) local f_date=$(g_date_print)
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 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 [ -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,US-UNEMPLOYMENT forecast,US-CONSUMER-PRICE forecast" >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 "${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 echo -n "${f_market_performance}" >MARKET_PERFORMANCE_LATEST

View File

@ -93,7 +93,7 @@ function webpage {
echo "<h2>Market Performance ( $(cat MARKET_PERFORMANCE_LATEST)%)</h2>" >>../index.html.tmp echo "<h2>Market Performance ( $(cat MARKET_PERFORMANCE_LATEST)%)</h2>" >>../index.html.tmp
echo "<table><tr>" >>../index.html.tmp echo "<table><tr>" >>../index.html.tmp
head -n1 MARKET_PERFORMANCE.csv | perl -pe 's/,/\n/g' | while read f_mperfcol head -n1 MARKET_PERFORMANCE.csv | perl -pe 's/,/\n/g' | tr [:lower:] [:upper:] | while read f_mperfcol
do do
echo "<td><b>${f_mperfcol}</b></td>" >>../index.html.tmp echo "<td><b>${f_mperfcol}</b></td>" >>../index.html.tmp
done done