110年台期所期貨最後交易日(結算日)檔
20210217
20210317
20210421
20210519
20210616
20210721
20210818
20210922
20211020
20211117
20211222
20220119
110年台期所期貨最後交易日(結算日)檔
# prg : perl_proc_tick.pl # 期貨日交易檔分拆成當月 台指, 小台, 電指期, 金指期 # V 1.3.1 2015-04-24 change workDir to ~/trade/prg_perl/trade_data/ # tickDir to ~/trade/prg_perl/tick/ # V 1.3.0 2010-01-05 Auto Create Store Dir # V 1.2.0 2009-10-10 change Last-Trading-Days # V 1.1.0 2009-05-30 get taiwan future tick # V 1.0.0 2009-06-17 change Work Directory and move to Storage use POSIX qw(strftime); use integer; # $workDir = '/home/redjoe/tick/prg_perl/trade_data/'; # $tickDir = '/home/redjoe/tick/prg_perl/tick/'; # my $LastTradingDays_file = "/home/redjoe/tick/last-trading-days/last-trading-days"; $workDir = '/home/redjoe/trade/prg_perl/trade_data/'; $tickDir = '/home/redjoe/trade/prg_perl/tick/'; my $LastTradingDays_file = "/home/redjoe/trade/last-trading-days/last-trading-days"; # $target = 'hm30:~/public_html/future/daily/'; # my $TX_Product = 'TX'; # 台指 my $MTX_Product = 'MTX'; # 小台 my $TE_Product = 'TE'; # 電指期 my $TF_Product = 'TF'; # 金指期 my $startHH = '08'; # 開始時 my $startMM = '45'; # 開始分 # my $MinuteK = 5; # 分K my $MinuteK = 1; # 分K my $IdxK = -1; # idx my $PreIdxK = -1; # idx chdir $workDir; # $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime; ($sec, $min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year = $year + 1900; $mon = $mon + 1; # :34,43s/^# //g :47,55s/^/# /g # testing use # :34,43s/^/# /g :47,55s/^# //g # Auto get date # $today_ziptickfile = "Daily_" . $year . "_" . $mon ."_" . $mday . ".zip"; $today = strftime "%Y%m%d", localtime; $wtoday = strftime "%Y/%m/%d", localtime; $today_ziptickfile = strftime "Daily_%Y_%m_%d.zip", localtime; $today_tickfile = strftime "Daily_%Y_%m_%d.rpt", localtime; $today_wt_tx_tickfile = strftime "%Y_%m_%d.tx", localtime; $today_wt_mtx_tickfile = strftime "%Y_%m_%d.mtx", localtime; $today_wt_te_tickfile = strftime "%Y_%m_%d.te", localtime; $today_wt_tf_tickfile = strftime "%Y_%m_%d.tf", localtime; $today_wt_tx_kfile = $today_wt_tx_tickfile .'_' . $MinuteK . 'k'; $today_wt_mtx_kfile = $today_wt_mtx_tickfile .'_' . $MinuteK . 'k'; $today_wt_te_kfile = $today_wt_te_tickfile .'_' . $MinuteK . 'k'; $today_wt_tf_kfile = $today_wt_tf_tickfile .'_' . $MinuteK . 'k'; $outRec = "交易日期,商品代號,交割年月,成交時間,成交價格,成交數量"; open(open_LastTradingDays, $LastTradingDays_file)|| die("Cannot open $LastTradingDays_file.\n"); @recs = <open_LastTradingDays>; for($row=@recs-1; $row >= 0; $row=$row-1) # for($row=0; $row < @recs; $row++) { my $LastTradingDays = $recs[$row]; if ($LastTradingDays >= $today ) { $TradingDays = $LastTradingDays; } } my $wkMonth = substr $TradingDays, 0, 6; close(open_LastTradingDays); open(open_file, $today_tickfile) || die("Cannot open $workDir$today_tickfile.\n"); open(wf_tx, ">$today_wt_tx_tickfile"); open(wf_mtx,">$today_wt_mtx_tickfile"); open(wf_te, ">$today_wt_te_tickfile"); open(wf_tf, ">$today_wt_tf_tickfile"); open(wf_ktx, ">$today_wt_tx_kfile"); # open(wf_kmtx,">$today_wt_mtx_kfile"); # open(wf_kte, ">$today_wt_te_kfile"); # open(wf_ktf, ">$today_wt_tf_kfile"); # print wf_tx "成交時間,成交價格,數量\n"; print wf_tx "Date Time,Price,Vol\n"; print wf_mtx "Date Time,Price,Vol\n"; print wf_te "Date Time,Price,Vol\n"; print wf_tf "Date Time,Price,Vol\n"; print wf_ktx "Date Time,Open,High,Low,Close,Vol\n"; # print wf_kmtx "成交時間,開,高,低,收,數量\n"; # print wf_kte "成交時間,開,高,低,收,數量\n"; # print wf_ktf "成交時間,開,高,低,收,數量\n"; # print "Processing...\n"; while(my $record = <open_file>) { chomp $record; $record =~ s/ //g; # 交易日期,商品代號,交割年月,成交時間,成交價格,成交數量(B+S),近月價格,遠月價格 ($tDays, $tProduct, $tMonth, $tickTime, $tPrice, $tVol, $nPrice, $fPrice)=split(/,/ , $record); # print "$record\n"; $tVol = $tVol / 2; # print "$tDays, $tProduct, $tMonth, $tickTime, $tPrice, $tVol, $nPrice, $fPrice\n"; $tTimeHh = substr $tickTime, 0, 2; $tTimeMm = substr $tickTime, 2, 2; $tTimeSs = substr $tickTime, 4, 2; # my $tTimeMs = substr $tickTime, 6, 6; $tTime = $tTimeHh . ':' . $tTimeMm . ':' . $tTimeSs; # print "\$wkMonth = $wkMonth \n\$tMonth = $tMonth\n"; # print "\$tProduct = $tProduct \n"; # 當月 if ($tMonth eq $wkMonth) { if ($tProduct eq $TX_Product) { # 台指 # # print "\n # $tProduct# $tTime,$tPrice,$tVol, =$tDays, $tProduct, $tMonth, $nPrice, $fPrice="; # print wf_tx "$tTime,$tPrice,$tVol,=$tDays, $tProduct, $tMonth, $nPrice, $fPrice="; print wf_tx "$tTime,$tPrice,$tVol\n"; } elsif ($tProduct eq $MTX_Product) { # 小台 # # print "\n # $tProduct# $tTime,$tPrice,$tVol, =$tDays, $tProduct, $tMonth, $nPrice, $fPrice="; print wf_mtx "$tTime,$tPrice,$tVol\n"; } elsif ($tProduct eq $TE_Product) { # 電指期 # print "\n # $tProduct# $tTime,$tPrice,$tVol, =$tDays, $tProduct, $tMonth, $nPrice, $fPrice="; print wf_te "$tTime,$tPrice,$tVol\n"; } elsif ($tProduct eq $TF_Product) { # 金指期 # print "\n # $tProduct# $tTime,$tPrice,$tVol, =$tDays, $tProduct, $tMonth, $nPrice, $fPrice="; print wf_tf "$tTime,$tPrice,$tVol\n"; } if ($tProduct eq $TX_Product) { # 台指 $IdxK = int(((($tTimeHh - $startHH) * 60) + ($tTimeMm - $startMM)) / $MinuteK); if ($IdxK == $PreIdxK) { # 同根k if ($tPrice > $HPrice) { $HPrice = $tPrice; } if ($tPrice < $LPrice) { $LPrice = $tPrice; } $CPrice = $tPrice; $KVol = $KVol + $tVol; } else { if ($PreIdxK != -1){ print wf_ktx "$KTime,$OPrice,$HPrice,$LPrice,$CPrice,$KVol\n"; } $OPrice = $tPrice; $HPrice = $tPrice; $LPrice = $tPrice; $CPrice = $tPrice; $KVol = $tVol ; # $PreIdxK = $IdxK - 1; my $KTimeHH = ((($IdxK + 1) * $MinuteK) + ($startHH * 60) + $startMM) / 60 + 100; my $KTimeMM = ((($IdxK + 1) * $MinuteK) + ($startHH * 60) + $startMM) % 60 + 100; $KTimeHH = substr $KTimeHH, 1, 2; $KTimeMM = substr $KTimeMM, 1, 2; $KTime = $wtoday . ' ' . $KTimeHH . ':' . $KTimeMM; # print "\n\$IdxK = $IdxK \$PreIdxK = $PreIdxK \$KTime = $KTime \$MinuteK = $MinuteK \$tTimeHh = $tTimeHh \$tTimeMm = $tTimeMm \$startHH = $startHH \$startMM = $startMM "; $PreIdxK = $IdxK; } } } } if ($IdxK == $PreIdxK) { # 同根k print wf_ktx "$KTime,$OPrice,$HPrice,$LPrice,$CPrice,$KVol\n"; # print "\n\$IdxK = $IdxK \$PreIdxK = $PreIdxK \$KTime = $KTime \$MinuteK = $MinuteK \$tTimeHh = $tTimeHh \$tTimeMm = $tTimeMm \$startHH = $startHH \$startMM = $startMM "; } # close(wf_ktf); # close(wf_kte); # close(wf_kmtx); close(wf_ktx); close(wf_tf); close(wf_te); close(wf_mtx); close(wf_tx); close(open_file); # 2009-08-01 stop # my $scp_content = `/usr/bin/scp $today_wt_tx_kfile $target`; # 2009-06-17 for move File to Storage Directory $workdayfile = strftime "%Y_%m_%d", localtime; $daily_trade_file = 'Daily_' . $workdayfile; $saveDir = substr $today, 0, 6; $tickStoreDir = $tickDir . $saveDir . '/'; $dailyStoreDir = $workDir . $saveDir . '/'; unless (-e $tickStoreDir ) { mkdir($tickStoreDir , 0700) || print $!; } unless (-e $dailyStoreDir ) { mkdir($dailyStoreDir , 0700) || print $!; } for $file (<$daily_trade_file*.*>) { $targetFile = $dailyStoreDir . $file; rename $file, $targetFile; # print "Rename File : source(\$file)=$file destination(\$targetFile)=$targetFile\n"; } for $file (<$workdayfile*.*>) { $targetFile = $tickStoreDir . $file; rename $file, $targetFile; # print "Rename File : source(\$file)=$file destination(\$targetFile)=$targetFile\n"; }
# set PATH so it includes user's geniustrader if it exists
if [ -d "$HOME/geniustrader/Scripts" ] ; then
PATH="$PATH:$HOME/geniustrader/Scripts"
fi
modules (程式) | 備註 |
---|---|
File::Find File::Spec IO::Handle | 是 Perl core 一部份 |
GD (backtest.pl) | perl 圖形套件隨著 c gd 程式庫 libgd |
DBI DBD::Pg DBD::mysql DBD::SQLite DBD::SQLite2 DBD::File DBD::ODBC | 若有用 SQL 後端儲存價格資料 |
Finance::BeanCounter | 推薦的股票價格數據庫應用程序 |
Time::Local | 使用 CSV (GT/DB/CSV.pm) 基礎價格資料 與 GT/DB/Text.pm text based prices data 不同 |
List::Util | 用在 future max/min 方法 |
Test::More Test::Differences | tool kit modules 執行測試 |
LWP | 若有使用 GT/DB/HTTP.pm |
XML::Simple | 只在 backtest_multi.pl 用到, 其他 GT 應用程式使用 XML::LibXML |
perldoc | 不一定需要 |
cd Scripts
./display_indicator.pl I:RSI txf2012 | less
Calculating indicator RSI[14, {I:Prices CLOSE}] ...
RSI[14, {I:Prices CLOSE}][2012/01/31] = 79.7701
RSI[14, {I:Prices CLOSE}][2012/02/01] = 78.6667
RSI[14, {I:Prices CLOSE}][2012/02/02] = 80.8903
RSI[14, {I:Prices CLOSE}][2012/02/03] = 79.8857
RSI[14, {I:Prices CLOSE}][2012/02/04] = 84.7966
RSI[14, {I:Prices CLOSE}][2012/02/06] = 83.0189
RSI[14, {I:Prices CLOSE}][2012/02/07] = 81.4645
RSI[14, {I:Prices CLOSE}][2012/02/08] = 84.3478
RSI[14, {I:Prices CLOSE}][2012/02/09] = 84.7458
RSI[14, {I:Prices CLOSE}][2012/02/10] = 81.8926
RSI[14, {I:Prices CLOSE}][2012/02/13] = 88.1086
RSI[14, {I:Prices CLOSE}][2012/02/14] = 83.4540
RSI[14, {I:Prices CLOSE}][2012/02/15] = 87.0250
RSI[14, {I:Prices CLOSE}][2012/02/16] = 75.9036
RSI[14, {I:Prices CLOSE}][2012/02/17] = 74.6032
RSI[14, {I:Prices CLOSE}][2012/02/20] = 73.7418
RSI[14, {I:Prices CLOSE}][2012/02/21] = 68.9913
RSI[14, {I:Prices CLOSE}][2012/02/22] = 71.0465
RSI[14, {I:Prices CLOSE}][2012/02/23] = 64.1089
RSI[14, {I:Prices CLOSE}][2012/02/24] = 66.4103
RSI[14, {I:Prices CLOSE}][2012/02/29] = 71.3974
RSI[14, {I:Prices CLOSE}][2012/03/01] = 66.0622
RSI[14, {I:Prices CLOSE}][2012/03/02] = 65.2058
RSI[14, {I:Prices CLOSE}][2012/03/03] = 67.4451
RSI[14, {I:Prices CLOSE}][2012/03/05] = 58.6701
RSI[14, {I:Prices CLOSE}][2012/03/06] = 54.3478
RSI[14, {I:Prices CLOSE}][2012/03/07] = 42.5703
RSI[14, {I:Prices CLOSE}][2012/03/08] = 54.8077
RSI[14, {I:Prices CLOSE}][2012/03/09] = 54.9932
RSI[14, {I:Prices CLOSE}][2012/03/12] = 47.7876
RSI[14, {I:Prices CLOSE}][2012/03/13] = 54.8098
RSI[14, {I:Prices CLOSE}][2012/03/14] = 57.2939
RSI[14, {I:Prices CLOSE}][2012/03/15] = 59.3647
RSI[14, {I:Prices CLOSE}][2012/03/16] = 56.3996
RSI[14, {I:Prices CLOSE}][2012/03/19] = 46.1827
RSI[14, {I:Prices CLOSE}][2012/03/20] = 40.8768
RSI[14, {I:Prices CLOSE}][2012/03/21] = 39.6882
RSI[14, {I:Prices CLOSE}][2012/03/22] = 48.0132
RSI[14, {I:Prices CLOSE}][2012/03/23] = 52.4096
RSI[14, {I:Prices CLOSE}][2012/03/26] = 50.6993
RSI[14, {I:Prices CLOSE}][2012/03/27] = 56.6938
RSI[14, {I:Prices CLOSE}][2012/03/28] = 53.3835
RSI[14, {I:Prices CLOSE}][2012/03/29] = 41.6143
RSI[14, {I:Prices CLOSE}][2012/03/30] = 47.9075
RSI[14, {I:Prices CLOSE}][2012/04/02] = 39.7294
RSI[14, {I:Prices CLOSE}][2012/04/03] = 27.0886
RSI[14, {I:Prices CLOSE}][2012/04/05] = 22.6695
RSI[14, {I:Prices CLOSE}][2012/04/06] = 28.9559
RSI[14, {I:Prices CLOSE}][2012/04/09] = 26.5286
RSI[14, {I:Prices CLOSE}][2012/04/10] = 30.8086
RSI[14, {I:Prices CLOSE}][2012/04/11] = 33.1343
RSI[14, {I:Prices CLOSE}][2012/04/12] = 25.2759
RSI[14, {I:Prices CLOSE}][2012/04/13] = 34.1487
RSI[14, {I:Prices CLOSE}][2012/04/16] = 36.9703
RSI[14, {I:Prices CLOSE}][2012/04/17] = 29.3478
RSI[14, {I:Prices CLOSE}][2012/04/18] = 29.9020
RSI[14, {I:Prices CLOSE}][2012/04/19] = 36.2663
RSI[14, {I:Prices CLOSE}][2012/04/20] = 29.6009
RSI[14, {I:Prices CLOSE}][2012/04/23] = 28.9902
RSI[14, {I:Prices CLOSE}][2012/04/24] = 32.7014
RSI[14, {I:Prices CLOSE}][2012/04/25] = 44.6112
RSI[14, {I:Prices CLOSE}][2012/04/26] = 37.5691
RSI[14, {I:Prices CLOSE}][2012/04/27] = 40.2963
RSI[14, {I:Prices CLOSE}][2012/04/30] = 39.0318
RSI[14, {I:Prices CLOSE}][2012/05/02] = 52.1945
RSI[14, {I:Prices CLOSE}][2012/05/03] = 51.2224
RSI[14, {I:Prices CLOSE}][2012/05/04] = 43.6828
RSI[14, {I:Prices CLOSE}][2012/05/07] = 37.7030
RSI[14, {I:Prices CLOSE}][2012/05/08] = 45.4902
RSI[14, {I:Prices CLOSE}][2012/05/09] = 40.0000
RSI[14, {I:Prices CLOSE}][2012/05/10] = 41.9118
RSI[14, {I:Prices CLOSE}][2012/05/11] = 41.1058
RSI[14, {I:Prices CLOSE}][2012/05/14] = 43.1078
RSI[14, {I:Prices CLOSE}][2012/05/15] = 43.6025
RSI[14, {I:Prices CLOSE}][2012/05/16] = 33.9367
RSI[14, {I:Prices CLOSE}][2012/05/17] = 40.1557
RSI[14, {I:Prices CLOSE}][2012/05/18] = 34.8120
RSI[14, {I:Prices CLOSE}][2012/05/21] = 37.1747
RSI[14, {I:Prices CLOSE}][2012/05/22] = 25.7958
RSI[14, {I:Prices CLOSE}][2012/05/23] = 23.7374
RSI[14, {I:Prices CLOSE}][2012/05/24] = 23.2089
RSI[14, {I:Prices CLOSE}][2012/05/25] = 25.4425
RSI[14, {I:Prices CLOSE}][2012/05/28] = 28.3741
RSI[14, {I:Prices CLOSE}][2012/05/29] = 42.0304
RSI[14, {I:Prices CLOSE}][2012/05/30] = 38.6239
RSI[14, {I:Prices CLOSE}][2012/05/31] = 42.3968
RSI[14, {I:Prices CLOSE}][2012/06/01] = 37.8500
RSI[14, {I:Prices CLOSE}][2012/06/04] = 30.4151
RSI[14, {I:Prices CLOSE}][2012/06/05] = 39.1705
RSI[14, {I:Prices CLOSE}][2012/06/06] = 38.1733
RSI[14, {I:Prices CLOSE}][2012/06/07] = 46.1879
RSI[14, {I:Prices CLOSE}][2012/06/08] = 39.8968
RSI[14, {I:Prices CLOSE}][2012/06/11] = 44.2584
RSI[14, {I:Prices CLOSE}][2012/06/12] = 45.1954
RSI[14, {I:Prices CLOSE}][2012/06/13] = 46.7678
RSI[14, {I:Prices CLOSE}][2012/06/14] = 50.4603
RSI[14, {I:Prices CLOSE}][2012/06/15] = 51.7129
RSI[14, {I:Prices CLOSE}][2012/06/18] = 48.7889
RSI[14, {I:Prices CLOSE}][2012/06/19] = 51.4986
RSI[14, {I:Prices CLOSE}][2012/06/20] = 54.2147
RSI[14, {I:Prices CLOSE}][2012/06/21] = 50.6633
RSI[14, {I:Prices CLOSE}][2012/06/22] = 58.1905
RSI[14, {I:Prices CLOSE}][2012/06/25] = 48.7899
RSI[14, {I:Prices CLOSE}][2012/06/26] = 46.3074
RSI[14, {I:Prices CLOSE}][2012/06/27] = 47.0993
RSI[14, {I:Prices CLOSE}][2012/06/28] = 52.4520
RSI[14, {I:Prices CLOSE}][2012/06/29] = 51.1501
RSI[14, {I:Prices CLOSE}][2012/07/02] = 56.7442
RSI[14, {I:Prices CLOSE}][2012/07/03] = 59.6529
:
./backtest.pl TFS 13000 | less
./backtest.pl 'TFS[30,7,7]' 13000 | less
;
; AutoHotkey Version: 1.0.0
; Platform: Win XP
; Author: R.J
; Date : 2010/6/11
; Script Function:
; Get Tick
;
#Include SimpleArray.ahk
; 1 2 3 4 5 6 7 8 9 10 11 12
Month = 31|28|31|30|31|30|31|31|30|31|30|31
PerlExe = c:\perl\bin\perl.exe
plGetTick = c:\tick\prg_perl3w\gettick3w.pl
plProc3wTick = c:\tick\prg_perl3w\proc3w_tick.pl
ToDay = %A_YYYY%-%A_MM%-%A_DD%
if (%A_MM% == 1 ){
sStartMonth := 12 ; 前月
} else {
sStartMonth := A_MM + 99
sStartMonth := SubStr(sStartMonth, 2, 2) ; 前月
}
sStartDay = %A_YYYY%-%sStartMonth%-%A_DD%
sStopDay = %A_YYYY%-%A_MM%-%A_DD%
Gui, Font, S12,
Gui, Add, Text, x10 y25 w70 h20 , Start Date :
Gui, Add, Text, x10 y85 w70 h20 , Stop Date :
Gui, Add, Edit, x90 y23 w90 h20 r1 vStartEdit, %sStartDay%
Gui, Add, Edit, x90 y83 w90 h20 r1 vStopEdit, %sStopDay%
Gui, Add, Button, x220 y18 w46 h29 , Start
Gui, Show, x300 y150 h250 w320, Get Future Daily-Trade from TAIFEX
Return
GuiClose:
ExitApp
ButtonStart:
Gui, Submit
stopDate := StopEdit
stYYYY := SubStr(StartEdit, 1, 4)
stMM := SubStr(StartEdit, 6, 2)
stDD := SubStr(StartEdit, 9, 2)
WorkDate = %stYYYY%-%stMM%-%stDD%
; While (stopDate >= WorkDate) {
While (WorkDate <= stopDate) {
if (stDD > SA_Get(Month, stMM)) {
; 換月
stDD -= SA_Get(Month, stMM)
if (stDD < 10) {
stDD += 100
stDD := SubStr(stDD, 2, 2)
}
stMM += 1
if (stMM > 12) {
stMM := 01
stYYYY += 1
} else if (stMM < 10) {
stMM += 100
stMM := SubStr(stMM, 2, 2)
}
}
WorkDate = %stYYYY%-%stMM%-%stDD%
RunWait, %comspec% /c date %WorkDate%, , min
sleep, 1000
if (A_WDay >= 2 and A_WDay <= 6) {
RunWait, %PerlExe% %plGetTick%
RunWait, %PerlExe% %plProc3wTick%
}
stDD += 1
if (stDD < 10) {
stDD += 100
stDD := SubStr(stDD, 2, 2)
}
WorkDate = %stYYYY%-%stMM%-%stDD%
}
RunWait, %comspec% /c date %ToDay%, , min ;; Reset Today DateTime
Return
20100120
20100217
20100317
20100421
20100519
20100616
20100721
20100818
20100915
20101020
20101117
20101215
#!C:\Perl\bin\perl.exe
# 取出今天的K線, 去除最後一筆
# 輸入一分K線檔 - C:\tmp\1.csv
# 輸出一分K線檔 - C:\tickhist\txf.csv
use POSIX qw(strftime);
use integer;
$src_k1m = 'C:\\tmp\\1.csv'; # 1mk source file
$tmpfile = 'C:\\tickhist\\tmp001.csv'; # tmp file
$tar_k1m = 'C:\\tickhist\\txf.csv'; # 1mk target file
$today = strftime "%Y/%m/%d", localtime;
print "Process $today Today 1 Minute K To : $tar_k1m.\n";
open(infile, $src_k1m) || die("Cannot open $src_k1m.\n");
open(tempfile, ">$tmpfile");
$rec_no=0;
;
while(my $k1m_record = )
{
chomp $k1m_record;
# $k1m_record =~ s/ //g;
# ($kDate, $kTime, $kOpen, $kHigh, $kLow, $kClose, $kVol)=split(/, / , $k1m_record);
($kDateTime, $kOpen, $kHigh, $kLow, $kClose, $kVol)=split(/,/ , $k1m_record);
($kDate, $kTime)=split(/ / , $kDateTime);
if ($kDate eq $today ){
print tempfile "$kDate,$kTime,$kOpen,$kHigh,$kLow,$kClose,$kVol\n";
$rec_no = $rec_no + 1;
}
}
close(tempfile);
close(infile);
open(tmp_file, $tmpfile) || die("Cannot open $tmpfile.\n");
open(outfile, ">$tar_k1m");
print outfile "Date,Time,Open,High,Low,Close,Vol\n";
for ( $i=1; $i<$rec_no; $i++ ) {
my $tmp_record = ;
print outfile $tmp_record;
# print "$i\n";
}
close(tmp_file);
close(outfile);
# 刪除暫存檔
unlink $tmpfile;
installer.pl
perl cronHelper.pl --install
net start CRON
net start
#
# m h dom mon dow command
# 分 時 日 月 周 指令
38 15 * * 1-5 c:\perl\bin\perl.exe C:\tick\prg_perl3w\gettick3w.pl
43 15 * * 1-5 c:\perl\bin\perl.exe C:\tick\prg_perl3w\proc_tick3w.pl
參考我的 wiki : windows版 Crontab for Win - cronw
20090121
20090218
20090318
20090415
20090520
20090617
20090715
20090819
20090916
20091021
20091118
20091216
參考我的 wiki : 2009 Last Trading Days - 2009年台期所期貨最後交易日#!C:\Perl\bin\perl.exe
# 2009-06-25 change output file name
# 2009/6/25 Change directory to C:\\tick\\prg_perl3w\\
# 2009/6/18 For Win32 ActivePerl
# 2009-06-17 for move File to Storage Directory
# 2009-06-06 Process Tick and Make K-Line File
use POSIX qw(strftime);
use integer;
$workDir = 'C:\\tick\\prg_perl3w\\daily\\';
$tickDir = 'C:\\tick\\prg_perl3w\\tick\\';
# 可以改成 5 分K
# my $Minute5K = 5; # 5分K
my $Minute1K = 1; # 1分K
# 讀取最後交易日檔
my $LastTradingDays = "C:\\tick\\prg_perl3w\\last-trading-days";
$today = strftime "%Y%m%d", localtime;
$today_YY = substr $today, 0, 4;
$today_mm = substr $today, 4, 2;
$today_dd = substr $today, 6, 2;
$tick_day = $today_YY . "-" . $today_mm . "-" . $today_dd;
$wkMonth = &get_current_month_product($LastTradingDays);
print "Process $today Tick and Make $Minute1K Minute K-Line File..\n";
chdir $workDir;
&split_Tick ($today_YY, $today_mm, $today_dd, $wkMonth);
$tickdayfile = '???' . $today;
$daily_trade_file = 'Daily_' . $today_YY . '_' . $today_mm . '_' . $today_dd;
$saveDir = substr $today, 0, 6;
$tickStoreDir = $tickDir . $saveDir . '/';
$dailyStoreDir = $workDir . $saveDir . '/';
`C:\\tick\\prg_perl3w\\movefile2dir.pl $workDir $dailyStoreDir $daily_trade_file`;
`C:\\tick\\prg_perl3w\\movefile2dir.pl $workDir $tickStoreDir $tickdayfile`;
exit;
sub process_kline {
# in參數 $tickfile $KMinute
my $startHH = '08'; # 開始時
my $startMM = '45'; # 開始分
my $IdxK = -1; # idx
my $PreIdxK = -1; # idx
my $tickfile = $_[0];
my $KMinute = $_[1];
$workday = substr $tickfile, 3, 8;
my $kline_file = substr($tickfile, 0, 11) . '_' . $KMinute . 'k' . substr($tickfile, 11, 4);
open(infile, $tickfile) || die("Cannot open $tickfile.\n");
open(outfile, ">$kline_file");
print outfile "Date Time,Open,High,Low,Close,Vol\n";
# print "K File Processing...\n";
;
while(my $tk_record = )
{
chomp $tk_record;
$tk_record =~ s/ //g;
($tickTime, $tickPrice, $tickVol)=split(/,/ , $tk_record);
$tkTimeHh = substr $tickTime, 0, 2;
$tkTimeMm = substr $tickTime, 3, 2;
$tkTimeSs = substr $tickTime, 6, 2;
$IdxK = int(((($tkTimeHh - $startHH) * 60) + ($tkTimeMm - $startMM)) / $KMinute);
if ($IdxK == $PreIdxK) { # 同根k
if ($tickPrice > $HPrice) {
$HPrice = $tickPrice;
}
if ($tickPrice < $LPrice) {
$LPrice = $tickPrice;
}
$CPrice = $tickPrice;
$KVol = $KVol + $tickVol;
}
else {
if ($PreIdxK != -1){
print outfile $KTime,$OPrice,$HPrice,$LPrice,$CPrice,$KVol\n";
}
$OPrice = $tickPrice;
$HPrice = $tickPrice;
$LPrice = $tickPrice;
$CPrice = $tickPrice;
$KVol = $tickVol ;
my $KTimeHH = ((($IdxK + 1) * $KMinute) + ($startHH * 60) + $startMM) / 60 + 100;
my $KTimeMM = ((($IdxK + 1) * $KMinute) + ($startHH * 60) + $startMM) % 60 + 100;
$KTimeHH = substr $KTimeHH, 1, 2;
$KTimeMM = substr $KTimeMM, 1, 2;
$KTime = $tick_day . ' ' . $KTimeHH . ':' . $KTimeMM;
$PreIdxK = $IdxK;
}
}
if ($IdxK == $PreIdxK) {
# 同根k
print outfile "$KTime,$OPrice,$HPrice,$LPrice,$CPrice,$KVol\n";
}
close(outfile);
close(infile);
}
# get current month product. ex: 200906 (取得當月月分)
sub get_current_month_product{
my $LastTradingDays_file = $_[0];
open(open_LastTradingDays, $LastTradingDays_file)|| die("Cannot open $LastTradingDays_file.\n");
@recs = ;
for($row=@recs-1; $row >= 0; $row=$row-1)
{
my $LastTradingDays = $recs[$row];
if ($LastTradingDays >= $today ) {
$TradingDays = $LastTradingDays;
}
}
my $wkMonth = substr $TradingDays, 0, 6;
close(open_LastTradingDays);
return $wkMonth;
}
sub split_Tick {
chdir $workDir;
# in參數 $today_YY $today_mm $today_dd $wkMonth
$workday_YY = $_[0];
$workday_mm = $_[1];
$workday_dd = $_[2];
$workMonth = $_[3];
$workdayfile = $workday_YY . $workday_mm . $workday_dd;
$trade_file = 'Daily_' . $workday_YY . '_' . $workday_mm . '_' . $workday_dd . '.rpt';
my $TX_Product = 'TX'; # 台指
my $MTX_Product = 'MTX'; # 小台
my $TE_Product = 'TE'; # 電指期
my $TF_Product = 'TF'; # 金指期
# 2009-06-25 change output file name
$tx_tickfile = 'txf' . $workdayfile . '.csv'; # 台指
$mtx_tickfile = 'mxf' . $workdayfile . '.csv'; # 小台
$te_tickfile = 'exf' . $workdayfile . '.csv'; # 電指期
$tf_tickfile = 'fxf' . $workdayfile . '.csv'; # 金指期
open(read_file, $trade_file) || die("Cannot open $trade_file.\n");
open(out_tx, ">$tx_tickfile");
open(out_mtx,">$mtx_tickfile");
open(out_te, ">$te_tickfile");
open(out_tf, ">$tf_tickfile");
print out_tx "Date Time,Price,Vol\n";
print out_mtx "Date Time,Price,Vol\n";
print out_te "Date Time,Price,Vol\n";
print out_tf "Date Time,Price,Vol\n";
# print "Split Tick File Processing...\n";
while(my $record = )
{
chomp $record;
$record =~ s/ //g;
# 交易日期,商品代號,交割年月,成交時間,成交價格,成交數量(B+S),近月價格,遠月價格
($tDays, $tProduct, $tMonth, $tickTime, $tPrice, $tVol, $nPrice, $fPrice)=split(/,/ , $record);
# print "$tDays, $tProduct, $tMonth, $tickTime, $tPrice, $tVol, $nPrice, $fPrice\n";
$tVol = $tVol / 2;
$tTimeHh = substr $tickTime, 0, 2;
$tTimeMm = substr $tickTime, 2, 2;
$tTimeSs = substr $tickTime, 4, 2;
$tTime = $tTimeHh . ':' . $tTimeMm . ':' . $tTimeSs;
# 當月
if ($tMonth eq $workMonth)
{
if ($tProduct eq $TX_Product) { # 台指
print out_tx "$tTime,$tPrice,$tVol\n";
}
elsif ($tProduct eq $MTX_Product) { # 小台
print out_mtx "$tTime,$tPrice,$tVol\n";
}
elsif ($tProduct eq $TE_Product) { # 電指期
print out_te "$tTime,$tPrice,$tVol\n";
}
elsif ($tProduct eq $TF_Product) { # 金指期
print out_tf "$tTime,$tPrice,$tVol\n";
}
}
}
close(out_tf);
close(out_te);
close(out_mtx);
close(out_tx);
close(read_file);
&process_kline($tx_tickfile, $Minute1K);
}
#!C:\Perl\bin\perl.exe
# 2009/6/25 Change directory to C:\\tick\\prg_perl3w\\
# 2009/6/18 For Win32 ActivePerl
#!/usr/bin/perl # 原程式是在 Debian linux 下
# 2009-05-30 get taiwan future tick
use POSIX qw(strftime);
$workDir = 'C:\\tick\\prg_perl3w\\daily\\';
$today_ziptickfile = strftime "Daily_%Y_%m_%d.zip", localtime;
$today_tickfile = strftime "Daily_%Y_%m_%d.rpt", localtime;
$LogFile = $workDir . "perl_crontab.log";
$tickfile = "http://www.taifex.com.tw/DailyDownload/" .$today_ziptickfile ;
chdir $workDir;
# 用 wget 抓台期交所當天交易檔
my $content = `C:\\tool\\wget.exe -c -a $LogFile -P $workDir $tickfile`;
if (-e $today_ziptickfile) {
# 解 zip 檔
# `unzip $today_ziptickfile`;
`c:\\tool\\unzip $today_ziptickfile`;
}
else {
die("File not exist : $today_ziptickfile.\n");
}