顯示具有 K線 標籤的文章。 顯示所有文章
顯示具有 K線 標籤的文章。 顯示所有文章

2021年3月11日 星期四

結算日-2021年台期所期貨最後交易日檔

110年台期所期貨最後交易日(結算日)檔


20210120
20210217
20210317
20210421
20210519
20210616
20210721
20210818
20210922
20211020
20211117
20211222
20220119

2018年1月5日 星期五

使用 bash tick

程式碼 ( 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

2016年12月23日 星期五

結算日-2017年台期所期貨最後交易日檔

2017(中華民國106年)台期所期貨最後交易日(結算日)檔

2016-12-24
106年台期所期貨最後交易日檔

資訊來源 -> 臺灣期貨交易所首頁 > 交易制度 > 行事曆

20170118
20170215
20170315
20170419
20170517
20170622
20170719
20170816
20170920
20171018
20171115
20171220
20180117
20180221
20180321
20180418
20180516
20180620
20180718
20180815
20180919
20181017
20181121
20181219
20190116

--

2015年12月2日 星期三

2016年台期所期貨最後交易日(結算日)檔

2016(中華民國105年)台期所期貨最後交易日(結算日)檔

2015-12-03

2016年台期所期貨最後交易日檔

資訊來源 -> 首頁 > 交易制度 > 行事曆

20160120
20160217
20160316
20160420
20160518
20160615
20160720
20160817
20160921
20161019
20161116
20161221

--

2014年12月16日 星期二

2015年台期所期貨最後交易日檔

2015(中華民國104年)台期所期貨最後交易日檔

2014-12-17

2015台期所期貨最後交易日檔(結算日)

資訊來源 - 期貨交易所 - 最新消息 - 公告 - 1205期交所-年曆卡(底黑).pdf

20150121
20150218
20150318
20150415
20150520
20150617
20150715
20150819
20150916
20151021
20151118
20151216

--

2014年6月3日 星期二

台指期轉檔程式 - part5 (只用AutoHotkey)

AutoHotkey到期交所抓交易檔, 並分拆成Tick及K線 (多天)

寫過幾個 到期交所抓交易檔, 並分拆成Tick及K線 "台指期轉檔程式" - 轉檔程 Linux Bash ~ 轉檔程 part4.

這次是只用 AutoHotkey 及外部程式 unzip.exe 來處理





ahk 程式
  \twfTrade2K.exe  (主程式)
  \Tick2mk.exe
  \Tick2dk.exe
  \chk_Ver.exe   檢查 AutoHotkey 版本

設定檔
  \twfTrade2K.ini (設定檔)

  \last-trading-days (期貨最後交易日檔)

Source code 在 ahk_code 目錄下

程式



相關


2012年1月12日 星期四

2012年台期所期貨最後交易日檔

有用的人補一下吧, 2012(中華民國101年)台期所期貨最後交易日檔

2012-01-13

2012台期所期貨最後交易日檔(結算日)

資訊來源 - 期貨交易所 - 交易制度 - 台灣行事曆


20120118
20120215
20120321


20120418
20120516
20120620
20120718
20120815
20120919
20121017
20121121
20121219
20130119



--

2010年12月20日 星期一

2011年台期所期貨最後交易日檔(結算日)

2010-12-21

每年都要補的內容,最後交易日也就是結算日, 期交所每年定訂,在程式交易中會用到, 是得到當月期貨及換倉重要參考。

2011(中華民國100年)台期所期貨最後交易日檔(結算日)

資訊來源 - 期貨交易所 - 交易制度 - 台灣行事曆



20101117
20101215
20110119
20110216
20110316
20110420
20110518
20110615
20110720
20110817
20110921
20111019
20111116
20111221





-
--
-

2010年6月25日 星期五

AutoHotKey補一個月的轉檔主程式

這支程式是用AutoHotKey寫的,用來補前幾天(前30天)沒有做轉檔, 要配合
台指期轉檔程式 - part4(懶人包), 自動取得交易檔, 轉Tick及1分K線。

程式中用到他人的 SimpleArray.ahk 要放在同個資料夾(目錄)下。下載SimpleArray.zip, 下載後要解zip檔。

getTick.ahk程式碼


;
; 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


-

2010年6月17日 星期四

2010年台期所期貨最後交易日檔

2010-06-18

2010台期所期貨最後交易日檔


20100120
20100217
20100317
20100421
20100519
20100616
20100721
20100818
20100915
20101020
20101117
20101215


參考 - 台灣期貨交易所 - 行事曆

-
--
-

2010年4月28日 星期三

康和全都賺轉出1分鐘K線

康和全都賺轉(匯)出300筆(近3個月)的1分鐘K線

  1. 開技術分析。
  2. 選一分K線。
  3. 滑鼠右鍵->重新回補資料。
  4. 滑鼠右鍵->瀏覽歷史資料。
  5. 儲存到CSV檔。


註:
  • 資料開頭會多兩行, 第一行瀏覽歷史資料名稱, 第二行是抬頭, 在TS匯入時要先刪除。
  • 若是在盤中轉(匯)出, 要刪除最後一筆, (很可能時間還沒到, 最後一筆還不完整)。

2010年4月27日 星期二

台指期轉檔程式 - part4(懶人包)

因應 JameX 網友所提的"懶人包",

1. tick.zip
2. tool.zip
3. CRONw_crontab.zip

為配合TS的匯入, 這次改了一分K線的檔案名稱, 及輸出目錄, 並刪除抬頭

安裝說明, 參照 台指期轉檔程式 - part4

---

2010年4月20日 星期二

台指期轉檔程式 - part4

因為我比較懶, 用K線轉檔機還要按按鈕, 所以用 CRONw 排程, 自行到期交所抓當日的成交檔, 分類 tick, 再轉K線...

最近在 win XP sp3 下安裝
  • perl - ActivePerl-5.8.2.808-MSWin32-x86.msi
  • CRONw - CRONw_2.0.zip
  • tool - wget.exe unzip.exe
  • perl 轉檔程式
之前的操作忘了, 這次記錄一下。



1. perl
ActivePerl-5.8.2.808-MSWin32-x86.msi
2. CRONw
CRONw_2.0.zip
a.unzip CRONw_2.0.zip
b. CRONw -> C:\CRONw
3. tool.zip
a.unzip put at c:\tool\
b.file
1. c:\tool\wget.exe
2. c:\tool\unzip.exe
3. c:\tool\unzip32.dll
4. tick.zip (perl script)
a. unzip put at c:\tick
b.file
1. c:\tick\prg_perl3w\gettick3w.bat
2. c:\tick\prg_perl3w\proc3w_tick.bat
3. c:\tick\prg_perl3w\gettick3w.pl
4. c:\tick\prg_perl3w\proc3w_tick.pl
5. c:\tick\prg_perl3w\last-trading-days
6. c:\tick\prg_perl3w\movefile2dir.pl
(其他-手動補之前的K線)
7. c:\tick\ext\make_kline
8. c:\tick\ext\win_crontab.txt
9. c:\tick\ext\user_proc3w_tick.ba
10. c:\tick\ext\tick2kline.pl
c. 排程時間 copy c:\tick\ext\win_crontab.txt to c:\CRONw\crontab.txt
(add crontab rule)
27 15 * * 1-5 c:\perl\bin\perl.exe C:\tick\prg_perl3w\gettick3w.pl
29 15 * * 1-5 c:\perl\bin\perl.exe C:\tick\prg_perl3w\proc3w_tick.pl

5. install CRONW modules -> read \INSTALL.txt
a.
installer.pl

6. install CRONw to WinXP Service
a. 安裝服務 - perl cronHelper.pl --install

b. 起動服務 - net start CRON
c. 檢查 -> Cron Service (CRONw) -
net start

時間定在 15:27 以後, 是確保當時可以抓得到今日的成交檔


相關 -  台指期轉檔程式 - part4(懶人包)
 

2009年7月30日 星期四

cronw - perl 程式的自動排程

配合前兩篇 - 自期交所自行下載交易檔 perl 程式(win-XP)台指期轉檔程式,perl 程式 2 (配合前支gettick3w.pl-自行下載交易檔)

另外有兩部份 crontab 的設定最後交易日檔, crontab 是自動排程, 最後交易日檔是判斷交易檔中的當月成交資料基的依據。

說明:
  • 程式放在 C:\tick\prg_perl3w\ 下。
  • 資料處理在 C:\tick\prg_perl3w\daily\ 下。
  • 最後交易檔會移到 C:\tick\prg_perl3w\daily\yyyymm\ , 成交檔分好的 tick 及 k線檔(附名csv)會移到 C:\tick\prg_perl3w\tick\yyyymm\ 。以今天為例會移到 C:\tick\prg_perl3w\daily\200907\ 及 C:\tick\prg_perl3w\tick\200907\ , 若是日期為 2009-08-04 會移到 C:\tick\prg_perl3w\daily\200908\ 及 C:\tick\prg_perl3w\tick\200908\ 。




crontab 的設定
  1. 每週 1-5 15:38分,執行這支perl程式 C:\tick\prg_perl3w\gettick3w.pl (到期交所抓檔)
  2. 每週 1-5 15:43分,執行分拆 C:\tick\prg_perl3w\proc_tick3w.pl
  3. crontab 內容(C:\CRONw\crontab.txt)
#      
# 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


2009年台期所期貨最後交易日檔
2009依日期排順序的最後交易, 2010年(含)以後要自行建立。要用我的成程轉以前的資料, 要自行建立這個 "最後交易日檔"。

內容

20090121
20090218
20090318
20090415
20090520
20090617
20090715
20090819
20090916
20091021
20091118
20091216
參考我的 wiki : 2009 Last Trading Days - 2009年台期所期貨最後交易日


台指期轉檔程式 - perl 程式 2 (配合前支gettick3w.pl-自行下載交易檔)

配合前支程式 : 自期交所自行下載交易檔 perl 程式(win-XP) - gettick3w.pl

  1. 配合環境: windows xp sp2
  2. 程式名稱 : proc3w_tick.pl
  3. 程式目的 : 將當天交易檔分拆成台指期,小台,電指期,金指期當月分tick檔
  4. 程式碼



#!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);
}

參考我的 wiki : Process split tick - proc3w_tick.pl

2009年7月2日 星期四

台指期轉檔程式 - Linux Bash

自行到期交所下載交易檔及轉台指期的1分 K 的 bash 程式

這部份是在linux上的shell script程式,配合crontab自動排程
  • Crontab for User
    • 自動排程crontab
    • 編輯 user 的 crontab (執行 crontab -l )
    • 每週 1-5 16:44分,執行這支bash程式(~/prg_bash/cron_proc_tick.bash)
    • crontab 內容
    • # m  h  dom mon dow command
      # 分 時 日 月 周 指令
      44 16 * * 1-5 ~/prg_bash/cron_proc_tick.bash



  • 抓交易檔轉成tick程式
    • 環境: debian linux lenny
    • 程式名稱 : cron_proc_tick.bash
    • 程式目的 : 抓台灣期貨交易所當天交易檔,並分別轉成tick(.csv)
    • BASH 程式碼
    • #!/bin/sh

      # Get Tick

      today_tickfile=http://www.taifex.com.tw/DailyDownload/Daily_`date +%Y_%m_%d`.zip

      wget -c -a ~/tick/prg_bash/rj_crontab.log -P ~/tick/prg_bash/daily/ $today_tickfile


      # Process Tick

      cd ~/tick/prg_bash/daily/

      todayfile=`date +%Y_%m_%d`
      today=`date +%Y%m%d`
      todayMonth=`date +%Y%m`
      zipfile=Daily_$todayfile.zip

      workmonth=./tmp1

      wkproduct=`ls -l Daily_$todayfile.zip | cut -d ' ' -f 5 `

      if [ "$wkproduct" -ne '93' ]; then

      unzip $zipfile

      # echo Daily_$todayfile.rpt
      # echo $todayfile.TX

      # ltd=`tac last-trading-days`
      ltd=`tac ~/tick/last-trading-days`
      for td in $ltd
      do
      #echo "$td="$td , "$today="$today
      if [ "$td" -ge "$today" ]; then
      #echo " $td > $today "
      wkmonth=`echo $td`
      fi
      done

      echo $wkmonth > $workmonth

      wkproduct=`cut -c 1-6 $workmonth`
      # echo $wkproduct


      # TX 台指
      head -n 1 Daily_$todayfile.rpt > $todayfile.TX
      sed '/MTX/d' Daily_$todayfile.rpt | sed -n '/TX/p' | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $1,$2,$3,$4,$5,$6/2 }' >> $todayfile.TX
      echo "TickTime,Price,Vol" > txf$today.csv
      sed '/MTX/d' Daily_$todayfile.rpt | sed -n '/TX/p' | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $4,$5,$6/2 }' >> txf$today.csv

      # MTX 小台
      head -n 1 Daily_$todayfile.rpt > $todayfile.MTX
      sed -n '/MTX/p' Daily_$todayfile.rpt | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $1,$2,$3,$4,$5,$6/2 }' >> $todayfile.MTX
      echo "TickTime,Price,Vol" > mxf$today.csv
      sed -n '/MTX/p' Daily_$todayfile.rpt | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $4,$5,$6/2 }' >> mxf$today.csv


      # TE 電指期
      head -n 1 Daily_$todayfile.rpt > $todayfile.TE
      sed -n '/TE/p' Daily_$todayfile.rpt | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $1,$2,$3,$4,$5,$6/2 }' >> $todayfile.TE
      echo "TickTime,Price,Vol" > exf$today.csv
      sed -n '/TE/p' Daily_$todayfile.rpt | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $4,$5,$6/2 }' >> exf$today.csv

      ## TF 金指期
      head -n 1 Daily_$todayfile.rpt > $todayfile.TF
      sed '/GTF/d' Daily_$todayfile.rpt | sed -n '/TF/p' | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $1,$2,$3,$4,$5,$6/2 }' >> $todayfile.TF
      echo "TickTime,Price,Vol" > fxf$today.csv
      sed '/GTF/d' Daily_$todayfile.rpt | sed -n '/TF/p' | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $4,$5,$6/2 }' >> fxf$today.csv

      rm $workmonth


      if [ ! -d $todayMonth ]; then
      mkdir $todayMonth
      fi
      mv Daily_$todayfile.rpt $zipfile $todayMonth/

      if [ ! -d "~/tick/prg_bash/tick/$todayMonth" ]; then
      mkdir ~/tick/prg_bash/tick/$todayMonth
      fi
      mv $todayfile.TX txf$today.csv $todayfile.MTX mxf$today.csv $todayfile.TE exf$today.csv $todayfile.TF fxf$today.csv ~/tick/prg_bash/tick/$todayMonth/

      fi


參考我的 wiki : Get Taiwan future tick - cron_proc_tick.bash


原提供 "轉自期交所的台指期1分K" 將停止

最近幾次會將 提供轉自期交所的台指期1分K線 的程式放上來。

而原提供 "轉自期交所的台指期1分K", 將在下個月1日(2009/08/01)停止, 不再提供轉好的1分K線csv檔(好像也沒人用)。

若需要的人, 可自行按程式說明建置或修改自己的格式(5分,15分,30分,60分,1日K)。


2009年6月9日 星期二

定時自動抓期交所的成交資料(3)

每天提供轉自期交所的台指期1分K線。

這幾天在轉前幾年的成交資料, 順便把 定時自動抓期交所的成交資料 程式改寫, 全改成perl, 方便在windows下定時抓資料及轉成1分k線, 考慮到頻寬的問題, 目前只先放上台指一分K線給別人下載。

位置 http://rj.twbbs.org/~redjoe/future/daily/

2009年5月1日 星期五

定時自動抓期交所的成交資料

這幾天在趕程式, 空時看 程式交易聚寶盆 的文章, 其中有下載當天(最近30天)的成交資料, 要每天去抓, 覺得不方便。

昨天五月一日(星期五)沒交易, 在自家的主機(Debian)上, 用shell script 配合crontab寫了每天(星期一至星期五)16:30左右, 自動到期交所抓當天成交資料, 並分拆成台指, 小台指, 金指期, 電指期的tick檔, 下星期開始跑, 先暫時這樣。

這個程式只取當期(近月)的tick, 若是4月29日當天,會做以下動作
  • 到期交所抓當天成交資料(Daily_2009_04_29.zip)
  • 解Daily_2009_04_29.zip成Daily_2009_04_29.rpt
  • 參考最後結算日檔(last-trading-days)取出近月tick, 並分成台指, 小台指, 金指期, 電指期,及產生2009_04_29.TX , 2009_04_29.MTX , 2009_04_29.TF , 2009_04_29.TE 四個檔



待處理
  • 還沒有統計成1分鐘K,
  • 及改成perl寫的程式
  • 合併到原有的K線中


用 wget 下載的 script - wget-future-tick

#!/bin/sh

today_tickfile=http://www.taifex.com.tw/DailyDownload/Daily_`date +%Y_%m_%d`.zip

wget -c -a /daily/future_tick.log -P /daily/ $today_tickfile




分拆成台指,小台指,金指期,電指期的 script - proc-tick

#!/bin/sh

todayfile=`date +%Y_%m_%d` # -> 2009_04_29
today=`date +%Y%m%d` # -> 20090429
zipfile=Daily_$todayfile.zip # -> Daily_2009_04_29.zip

workmonth=./tmp1 # 暫存用

# 取得下載檔 size
filesize=`ls -l Daily_$todayfile.zip | cut -d ' ' -f 5 `

if [ "$filesize" -ne '93' ]; then # 超過 93 才有資料

unzip $zipfile # 解zip

# echo Daily_$todayfile.rpt
# echo $todayfile.TX

ltd=`tac last-trading-days` # 最後結算日檔
for td in $ltd
do
#echo "$td="$td , "$today="$today
if [ "$td" -ge "$today" ]; then
#echo " $td > $today "
wkmonth=`echo $td` # 取得最近的結算日 -> wkmonth
fi
done

echo $wkmonth > $workmonth

wkproduct=`cut -c 1-6 $workmonth` # 當期交易商品月份
# echo $wkproduct

# 用 sed 及 awk 分拆檔案
# TX 台指
head -n 1 Daily_$todayfile.rpt > $todayfile.TX # 留表頭第一行
sed '/MTX/d' Daily_$todayfile.rpt | sed -n '/TX/p' | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $1,$2,$3,$4,$5,$6 }' >> $todayfile.TX

# MTX 小台
head -n 1 Daily_$todayfile.rpt > $todayfile.MTX
sed -n '/MTX/p' Daily_$todayfile.rpt | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $1,$2,$3,$4,$5,$6 }' >> $todayfile.MTX

# TE 電指期
head -n 1 Daily_$todayfile.rpt > $todayfile.TE
sed -n '/TE/p' Daily_$todayfile.rpt | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $1,$2,$3,$4,$5,$6 }' >> $todayfile.TE

## TF 金指期
head -n 1 Daily_$todayfile.rpt > $todayfile.TF
sed '/GTF/d' Daily_$todayfile.rpt | sed -n '/TF/p' | sed -n 's/ //gp' | awk -F, 'BEGIN{OFS=","}($3=='$wkproduct'){ print $1,$2,$3,$4,$5,$6 }' >> $todayfile.TF

rm $workmonth # 刪除暫存檔
fi


crontab中的內容

# 分 時 日 月 星期 要執行的指令
34 16 * * 1-5 redjoetseng cd /daily/ && run-parts /etc/cron.tick/01get/wget-future-tick #每天抓future成交記錄
44 16 * * 1-5 redjoetseng cd /daily/ && run-parts /etc/cron.tick/02proc/proc-tick #依商品分拆future成交記錄


註:
  1. windows下也有crontab 排程(自動執行)程式 - CRONw
  2. 修改金指期(TF)部份,有GTF要除掉。(2009-05-06)



台灣期交所下載網頁

2008年12月30日 星期二

全都賺1k資料最近300筆-(搬2008/03/15)

自己的yahoo部落格 - 2008/03/15 05:01


康和全都賺在 "技術分析" 圖上點右鍵,選瀏覽歷史資料,會有最近大約3個月的1k資料,再按儲存到CSV檔。

--------------------------------------------------------------------------------------------
以上是搬家的文章



聯絡表單

名稱

以電子郵件傳送 *

訊息 *