更新於 2023/09/09閱讀時間約 24 分鐘

成長價值指標(Growth Value Index)

淡江大學葉怡成教授發明的指標
GVI=(B/P)×(1+ROE)^n
  • B/P:淨值股價比 →PB Ratio的倒數→反應股價目前是否夠便宜
  • ROE:股東權益報酬率→反應公司成長性
  • N:變數參數,控制GVI指標偏向成長面還是價值面,數值愈高表示愈偏向成長面,若以年度ROE計算(N=5);若以季度ROE計算(N=20)為佳
公式前半部(B/P)是衡量股票的價格是否便宜,後半部則是衡量企業的成長性。兩者綜合的用意是要找出價格便宜又具有成長性的企業。GVI指數愈高,代表越值得投資。
GVI指標應用的投資記律:
1. 只選股不擇時
2. 以20支股票形成投資組合
3. 每個月交易一次為最佳(迅速反應,耐心持有,定期換股,留強汰弱)
根據GVI用shell script寫一隻不盡完善的選股工具,如有需要請自行取用
#!/bin/bash

getColumnByName(){
  csv_file="$1"
  column_name="$2"
  column_number=$(awk -F ',' 'NR==1 { for(i=1; i<=NF; i++) { if($i == column_name) { print i; break } } }' column_name="$column_name" "$csv_file")
  echo $column_number
}
YMD=$(date +%Y%m%d)
day_of_week=$(date +%u)
if [ "$day_of_week" -eq 6 ] || [ "$day_of_week" -eq 7 ]; then
  current_timestamp=$(date +%s)
  days_to_friday=$(( day_of_week % 5 ))
  friday_timestamp=$((current_timestamp - (days_to_friday * 24 * 3600)))
  YSTDAY=$(date -d "@$friday_timestamp" "+%Y%m%d")
else
  YSTDAY=$(date +%Y%m%d)
fi
echo $YSTDAY

FILE_INCOME="income_${YMD}.csv"
FILE_BS="bs_${YMD}.csv"
FILE_PRICE="price_${YMD}.csv"
FILE_MERGE="merge_${YMD}.csv"
FILE_RAW="raw_${YMD}.csv"
FILE_TMP="temp_${YMD}.tmp"

YYY=$(( $(date +%Y) - 1911 ))
SS="0$(( ($(date +%_m) - 1 ) / 3 ))"

if [ $SS -eq 0 ] ; then
  YYY=$(( YYY - 1 ))
  SS=04
fi

curl 'https://mops.twse.com.tw/mops/web/ajax_t163sb04' \
  -H 'Accept: */*' \
  -H 'Accept-Language: zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'Cookie: jcsession=jHttpSession@199002cc; _ga=GA1.3.1478531031.1681117556; _gid=GA1.3.1147883650.1684137366; _gat=1' \
  -H 'Origin: https://mops.twse.com.tw' \
  -H 'Sec-Fetch-Dest: empty' \
  -H 'Sec-Fetch-Mode: cors' \
  -H 'Sec-Fetch-Site: same-origin' \
  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36' \
  -H 'sec-ch-ua: "Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Windows"' \
  --data-raw "encodeURIComponent=1&step=1&firstin=1&off=1&isQuery=Y&TYPEK=sii&year=${YYY}&season=${SS}" \
  --compressed -o $FILE_TMP

grep -o "t163sb04_${YMD}_..........csv" $FILE_TMP | sort -u | while read -r CSV ; do
  curl 'https://mops.twse.com.tw/server-java/t105sb02' \
    -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \
    -H 'Accept-Language: zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7' \
    -H 'Cache-Control: max-age=0' \
    -H 'Connection: keep-alive' \
    -H 'Content-Type: application/x-www-form-urlencoded' \
    -H 'Cookie: _ga=GA1.3.1478531031.1681117556; _gid=GA1.3.1147883650.1684137366' \
    -H 'Origin: null' \
    -H 'Sec-Fetch-Dest: document' \
    -H 'Sec-Fetch-Mode: navigate' \
    -H 'Sec-Fetch-Site: same-origin' \
    -H 'Sec-Fetch-User: ?1' \
    -H 'Upgrade-Insecure-Requests: 1' \
    -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36' \
    -H 'sec-ch-ua: "Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"' \
    -H 'sec-ch-ua-mobile: ?0' \
    -H 'sec-ch-ua-platform: "Windows"' \
    --data-raw "firstin=true&step=10&filename=${CSV}&saveCSV=Y" \
    --compressed -o income.${CSV}
done
FILE_X=$(ls -l income.t163sb04_${YMD}_*.csv | awk '{print $5, $9}' | sort -nr | head -n 1 | awk '{print $2}')
cp $FILE_X $FILE_INCOME

curl 'https://mops.twse.com.tw/mops/web/ajax_t163sb05' \
  -H 'Accept: */*' \
  -H 'Accept-Language: zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7' \
  -H 'Connection: keep-alive' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -H 'Cookie: jcsession=jHttpSession@279737b5; _ga=GA1.3.1478531031.1681117556; _gid=GA1.3.1147883650.1684137366; _gat=1' \
  -H 'Origin: https://mops.twse.com.tw' \
  -H 'Sec-Fetch-Dest: empty' \
  -H 'Sec-Fetch-Mode: cors' \
  -H 'Sec-Fetch-Site: same-origin' \
  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36' \
  -H 'sec-ch-ua: "Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Windows"' \
  --data-raw "encodeURIComponent=1&step=1&firstin=1&off=1&isQuery=Y&TYPEK=sii&year=${YYY}&season=${SS}" \
  --compressed -o $FILE_TMP

grep -o "t163sb04_${YMD}_..........csv" $FILE_TMP | sort -u | while read -r CSV ; do
  curl 'https://mops.twse.com.tw/server-java/t105sb02' \
    -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \
    -H 'Accept-Language: zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7' \
    -H 'Cache-Control: max-age=0' \
    -H 'Connection: keep-alive' \
    -H 'Content-Type: application/x-www-form-urlencoded' \
    -H 'Cookie: _ga=GA1.3.1478531031.1681117556; _gid=GA1.3.1147883650.1684137366; _gat=1' \
    -H 'Origin: null' \
    -H 'Sec-Fetch-Dest: document' \
    -H 'Sec-Fetch-Mode: navigate' \
    -H 'Sec-Fetch-Site: same-origin' \
    -H 'Sec-Fetch-User: ?1' \
    -H 'Upgrade-Insecure-Requests: 1' \
    -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36' \
    -H 'sec-ch-ua: "Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"' \
    -H 'sec-ch-ua-mobile: ?0' \
    -H 'sec-ch-ua-platform: "Windows"' \
    --data-raw "firstin=true&step=10&filename=$CSV" \
    --compressed -o bs.${CSV}
done

FILE_X=$(ls -l bs.t163sb04_${YMD}_*.csv | awk '{print $5, $9}' | sort -nr | head -n 1 | awk '{print $2}')
cp $FILE_X $FILE_BS

curl "https://www.twse.com.tw/rwd/zh/afterTrading/MI_INDEX?date=${YSTDAY}&type=ALLBUT0999&response=csv" \
  -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7' \
  -H 'Accept-Language: zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7' \
  -H 'Connection: keep-alive' \
  -H 'Referer: https://www.twse.com.tw/zh/trading/historical/mi-index.html' \
  -H 'Sec-Fetch-Dest: document' \
  -H 'Sec-Fetch-Mode: navigate' \
  -H 'Sec-Fetch-Site: same-origin' \
  -H 'Sec-Fetch-User: ?1' \
  -H 'Upgrade-Insecure-Requests: 1' \
  -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36' \
  -H 'sec-ch-ua: "Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Windows"' \
  --compressed -o ${FILE_PRICE}

tr -d '\r' < ${FILE_PRICE}  > $FILE_TMP
iconv -f big5 -t utf-8 $FILE_TMP | sed 's/\"證券代號\"/公司代號/g' | sort > $FILE_PRICE
join -t ',' -1 4 -2 4 $FILE_INCOME $FILE_BS  | iconv -f big5 -t utf-8 | sort >  $FILE_MERGE
join -t ',' -1 1 -2 1 $FILE_MERGE $FILE_PRICE  > $FILE_RAW
sed -i '1h;1d;$!H;$!d;G' $FILE_RAW
sed -i '1s/\"//g' $FILE_RAW
tr -d '\r' < ${FILE_RAW}  > $FILE_TMP;  mv $FILE_TMP $FILE_RAW
C1=$(getColumnByName "$FILE_RAW" "每股參考淨值")
C2=$(getColumnByName "$FILE_RAW" "收盤價")
C3=$(getColumnByName "$FILE_RAW" "本期綜合損益總額")
C4=$(getColumnByName "$FILE_RAW" "權益總計")
C5=$(getColumnByName "$FILE_RAW" "基本每股盈餘(元)")
C6=$(getColumnByName "$FILE_RAW" "公司名稱")
FILE_GVI=gvi_${YMD}.csv
echo "每股參考淨值 收盤價 本期綜合損益總額 權益總計 基本每股盈餘(元)"
echo "$C1 $C2 $C3 $C4 $C5"
awk -F'","' -v C1="$C1" -v C2="$C2" -v C3="$C3" -v C4="$C4" -v C5="$C5" -v C6="$C6" '{print $1,$C1,$C2,$C3,$C4,$C5,$C6 }' $FILE_RAW | sed 's/^\"//' > $FILE_TMP
tail -n +2 $FILE_TMP | awk '{gvi=($3/$2) * ((1+4*$6/$2)^5) ; print $1,gvi,$7}' | sort -r -n -k 2 > $FILE_GVI

rm -f $FILE_TMP
rm -f income.*.csv bs.*.csv
5/29使用N=5選出來的資料節錄如下
3308 180.382 聯德
4763 68.9303 材料-KY
4943 62.6762 康控-KY
2739 61.1958 寒舍
8454 60.9364 富邦媒
8478 59.355 東哥遊艇
2707 57.6594 晶華
2727 45.1315 王品
2345 41.4049 智邦
2404 41.0772 漢唐
1808 40.6105 潤隆
1475 38.6233 業旺
8996 33.3226 高力
2395 29.795 研華
1519 27.2633 華城
3653 26.8355 健策
1795 26.6598 美時
2912 26.2441 統一超
3046 25.5417 建碁
6691 22.4088 洋基工程
6515 21.7231 穎崴
6235 20.2265 華孚
3023 19.8833 信邦
2480 18.2976 敦陽科
2364 18.2192 倫飛
9943 18.0576 好樂迪
1609 16.7172 大亞
分享至
成為作者繼續創作的動力吧!
© 2024 vocus All rights reserved.