使用 bash 將 tick 轉 K 線
程式碼 ( Bash Code )
#!/bin/sh # V 1.2.0 2016-02-27 change url # V 1.1.1 2015-04-24 change prg dir ( tick -> trade ) # V 1.1 2009-10-10 change Last-Trading-Days # tick 轉 K 線 # Get Tick # Use Argv # if [ $1 = ]; then if [ $# -lt 1 ]; then echo "Argv number is less than 1." echo "EX: $0 20090610" exit 1 fi year=`echo $1 | cut -c 1-4` month=`echo $1 | cut -c 5-6` day=`echo $1 | cut -c 7-8` workFile=`printf "%s_%s_%s" $year $month $day` workday=`printf "%s%s%s" $year $month $day` workMonth=`printf "%s%s" $year $month` url_zipDailyFile=http://www.taifex.com.tw/DailyDownload/DailyDownload/Daily_$workFile.zip dailyStoreDir=/home/redjoe/trade/prg_bash/daily/ tickStoreDir=/home/redjoe/trade/prg_bash/tick/ log_File=/home/redjoe/trade/prg_bash/rj_crontab.log ltd=`tac /home/redjoe/trade/last-trading-days/last-trading-days` wget -c -a $log_File -P $dailyStoreDir $url_zipDailyFile # Process Tick cd $dailyStoreDir zip_DailyFile=Daily_$workFile.zip rpt_DailyFile=Daily_$workFile.rpt workmonth=./tmp1 wkproduct=`ls -l $zip_DailyFile | cut -d ' ' -f 5 ` # echo $wkproduct if [ "$wkproduct" -ne '93' ]; then unzip $zip_DailyFile # echo $rpt_DailyFile # echo $workFile.TX for td in $ltd do #echo "$td="$td , "$workday="$workday if [ "$td" -ge "$workday" ]; then #echo " $td > $workday " wkmonth=`echo $td` fi done echo $wkmonth > $workmonth wkproduct=`cut -c 1-6 $workmonth` # echo $wkproduct # TX 台指 head -n 1 $rpt_DailyFile > $workFile.TX sed '/MTX/d' $rpt_DailyFile | sed -n '/TX/p' | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $1,$2,$3,$4,$5,$6/2 }' >> $workFile.TX echo "TickTime,Price,Vol" > txf$workday.csv sed '/MTX/d' $rpt_DailyFile | sed -n '/TX/p' | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $4,$5,$6/2 }' >> txf$workday.csv # MTX 小台 head -n 1 $rpt_DailyFile > $workFile.MTX sed -n '/MTX/p' $rpt_DailyFile | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $1,$2,$3,$4,$5,$6/2 }' >> $workFile.MTX echo "TickTime,Price,Vol" > mxf$workday.csv sed -n '/MTX/p' $rpt_DailyFile | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $4,$5,$6/2 }' >> mxf$workday.csv # TE 電指期 head -n 1 $rpt_DailyFile > $workFile.TE sed -n '/TE/p' $rpt_DailyFile | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $1,$2,$3,$4,$5,$6/2 }' >> $workFile.TE echo "TickTime,Price,Vol" > exf$workday.csv sed -n '/TE/p' $rpt_DailyFile | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $4,$5,$6/2 }' >> exf$workday.csv ## TF 金指期 head -n 1 $rpt_DailyFile > $workFile.TF sed '/GTF/d' $rpt_DailyFile | sed -n '/TF/p' | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $1,$2,$3,$4,$5,$6/2 }' >> $workFile.TF echo "TickTime,Price,Vol" > fxf$workday.csv sed '/GTF/d' $rpt_DailyFile | sed -n '/TF/p' | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $4,$5,$6/2 }' >> fxf$workday.csv rm $workmonth if [ ! -d $workMonth ]; then mkdir $workMonth fi mv $rpt_DailyFile $zip_DailyFile $workMonth/ if [ ! -d "/home/redjoe/trade/prg_bash/tick/$workMonth" ]; then mkdir /home/redjoe/trade/prg_bash/tick/$workMonth fi mv $workFile.TX txf$workday.csv $workFile.MTX mxf$workday.csv $workFile.TE exf$workday.csv $workFile.TF fxf$workday.csv $tickStoreDir$workMonth/ fi