2013年11月1日 星期五

分析師的領先指標交易策略 Part 4 (程式碼)

EasyTrader ArtNo 039
亞股七大主要市場連續第三周呈現「北勝於南」的現象,不過,今年吸金突破千億美元大關的日股在上周小幅遭資金撤出,但台、韓股吸金態勢仍強勁,共流入約15億美元,東南亞國家中除印度吸金外,泰國股市上周止贖,微幅流入0.54億美元。

國際貨幣基金會IMF在十月全球經濟展望下調2013年及2014年全球成長預估,新興國家中包括中國、印度與東協區域的成長預估值均遭調降,雖然IMF調降亞洲經濟成長率,但是亞股未受衝擊,周線全數收紅,顯示前一波亞股修正已反映經濟放緩的可能性,因此利空不跌。

外資熱情擁抱台灣及韓國股市,主因第三季後美、日、歐接力復甦,尤其是歐洲自第三季正式擺脫衰退,由於外資近期回補過去遭大幅殺出的亞洲區域股票,而在亞洲區域來看,跟成熟市場景氣關聯度較高的為台灣與韓國,特別是出口產業受惠最明顯,根據券商統計,台灣的出口成長與美國關聯度高達73%,韓國則為五成左右,除了台韓與美國景氣關聯度高,也與全球景氣連動性大,因此資金流入台韓反應的是這兩大東北亞經濟體受惠於成熟國家觸底回升與走出衰退的契機。
引用內容 MoneyDJ 財經知識庫


先看來看台灣與韓國的股市連動相關性






從以上三個圖表顯示很強的正相關性,南韓綜合指數的開收盤時間 08:00~14:00 剛好跨越整個台指期的開收盤,是否利用韓國股指也能作為我們交易策略的元素呢?

基本設定:台指期 60 min K
參考商品:韓國綜合指數 日K線
交易策略:留倉交易
回測時間:2013/10/29 往前 3000日
來回成本: 1200

舊策略程式碼修正 + 小濾網
小濾網:Check 台指與參考商品的TScore接近程度 AbsValue(TTXN-Tscore) < ScoreGap


inputs: Type(2) ,TscoreHigh(20),TscoreMid(80),TscoreLow(40) ,TBar(10),TradeStopLoss(0.025),ScoreGap(10);

Vars: Zscore(0),Tscore(0),MP(0),ISBalanceDay(false),TTXN_Score(0),TTXN(0),Zscore1(0),Tscore1(0);

MP = MarketPosition ;

if DAYofMonth(Date) > 14 and DAYofMonth(Date) < 22 and DAYofWeek(Date)= 3 then isBalanceDay = True else isBalanceDay =False ;

if date <> date[1] then Begin
   Value1 = Close of Data2 ;
   if StdDev(Value1,TBar) <> 0 then Zscore = (Value1
- Average(Value1,TBar))/StdDev(Value1,TBar);

TScore = 10*Zscore + 50 ;

{ TTXN 60 min K}
  if StdDev(Close,TBar) <> 0 then TTXN_Score = (Close
      - Average(Close,TBar)) / StdDev(Close,TBar);

TTXN = 10*TTXN_score + 50 ;
Condition1 = Tscore > TscoreHigh and AbsValue(TTXN-Tscore) < ScoreGap;
Condition2 = Tscore < TscoreLow and AbsValue(TTXN-Tscore) < ScoreGap;

Condition3 = Tscore > TscoreMid and AbsValue(TTXN-Tscore) < ScoreGap;
Condition4 = Tscore < TscoreMid and AbsValue(TTXN-Tscore) < ScoreGap;

Condition5 = Tscore < TscoreHigh and AbsValue(TTXN-Tscore) > ScoreGap;
Condition6 = Tscore > TscoreLow and AbsValue(TTXN-Tscore) > ScoreGap;
end;

if Type = 1 then Begin
    if Condition1 then Buy next bar at Market ;
    if Condition2 then Sell next bar at Market ;
end;

if Type = 2 then Begin
    if Condition1 then Buy next bar Highest(High,3) stop ;
    if Condition2 then Sell next bar at Lowest(Low,3) stop ;
end;

if Type = 3 then Begin
   if Condition3 then Buy next bar at Market ;
   if Condition4 then Sell next bar at Market ;
end;

if Type = 4 then Begin
   if Condition3 then Buy next bar Highest(High,3) stop;
   if Condition4 then Sell next bar at Lowest(Low,3) stop ;
end;

if Type = 5 then Begin
   if Condition6 then Buy next bar at Market ;
   if Condition5 then Sell next bar at Market ;
end;

if Type = 6 then Begin
   if Condition6 then Buy next bar Highest(High,3) stop;
   if Condition5 then Sell next bar at Lowest(Low,3) stop ;
end;

if MP > 0 and Low < EntryPrice*(1-TradeStopLoss) then ExitLong at EntryPrice*(1-TradeStopLoss) stop ;

if MP < 0 and High > EntryPrice*(1+TradeStopLoss) then ExitShort at EntryPrice*(1+TradeStopLoss) stop ;

if IsBalanceDay then SetExitonClose ;

舊策略的回測圖示




果然是有不錯的連動性
亞洲股市與台指的連動告一段落,下次會介紹美國老大哥的影響力,Coming Soon.....

2 則留言:

  1. EasyTrader版主你好

    不好意思我想請問一下

    為什麼 TscoreHigh設定為20 TscoreMid為80 TscoreLow為40呢?

    我有點搞不太懂

    謝謝

    回覆刪除
    回覆
    1. 您好,那只是初值設定 ,你也可以設成 80/50/20 最主要是在跑最佳化過程中 ,系統的跟自己的決定才是最後的定案

      刪除