update market index calculation

This commit is contained in:
olli 2023-10-12 18:07:38 +02:00
parent e509d412ce
commit f66a6903c1
3 changed files with 36 additions and 4 deletions

View File

@ -108,10 +108,13 @@ function get_assets {
get_marketdata https://www.boerse.de/realtime-kurse/MSCI-World/XC0009692739 MSCI-WORLD-INDEX
get_marketdata https://www.boerse.de/indizes/DJ-AMER-OIL-und-GAS/XC0006886516 OIL-GAS-INVERTED-INDEX
get_marketdata https://www.boerse.de/fonds/SPDR-SundP-Regional-Banking-ETF/US78464A6982 KRE-BANKING-INDEX
get_marketdata https://www.boerse.de/indizes/Dax/DE0008469008 DAX-INDEX
#get_marketdata https://www.boerse.de/indizes/Dax/DE0008469008 DAX-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
get_marketdata https://www.investing.com/indices/fed-funds-composite-interest-rate-opinion US-FED-FEDERAL-FUNDS-RATE-INVERTED-INDEX
# clear old stuff
find asset-histories/*INDEX* -type f -mtime +6 -delete
}

View File

@ -58,7 +58,8 @@ function market_performance {
local f_index_performance_added=0
local f_index_performance_csv=""
local f_INDEX
for f_INDEX in DXY-INVERTED SP500 NASDAQ MSCI-WORLD OIL-GAS-INVERTED DAX KRE-BANKING
local f_indexlist=$(ls -1t asset-histories/*INDEX* | egrep -v 'US-UNEMPLOYMENT-INDEX|US-CONSUMER-PRICE-INDEX|US-FED-FEDERAL-FUNDS-RATE-INVERTED' | perl -pe 's#asset-histories/(.+)-INDEX.history.csv#$1#')
for f_INDEX in $f_indexlist
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; }')
@ -94,6 +95,26 @@ function market_performance {
f_index_performance_csv="${f_index_performance_csv},${f_index_performance}"
done
# calculate US-FED-FEDERAL-FUNDS-RATE-INVERTED
local f_economic
for f_eco_data in US-FED-FEDERAL-FUNDS-RATE-INVERTED-INDEX
do
local f_index_performance=$(tail -n 1 asset-histories/${f_eco_data}.history.csv | cut -d, -f2)
if echo ${f_eco_data} | 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
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
# 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
@ -127,7 +148,14 @@ 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})" | 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}%; ${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,US-UNEMPLOYMENT forecast,US-CONSUMER-PRICE forecast" >MARKET_PERFORMANCE.csv
local f_indexlistcsv=$(echo "$f_indexlist" | perl -pe 's/\n/,/g; s/ +/,/g; s/,+/,/g')
local f_market_csv_headline="date,market performance,btc,eth,btc forecast,eth forecast,top250,${f_indexlistcsv}US-FED-FEDERAL-FUNDS-RATE,US-UNEMPLOYMENT forecast,US-CONSUMER-PRICE forecast"
if [ -s MARKET_PERFORMANCE.csv ]
then
sed -i -e 1c"$f_market_csv_headline" MARKET_PERFORMANCE.csv
else
echo "$f_market_csv_headline" >MARKET_PERFORMANCE.csv
fi
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

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