接下來提供讀者FE888的投稿文章。我認為這程式碼看似簡單,其實頗有深度,程式碼為TS2000i。
--------------
主題類別:程式交易
主題:偏態峰態交易策略
作者:FE888
內文介紹:
進場:
將股價之峰態係數、偏態係數與中期均線做為多空趨勢確立之進場訊號。
當股市開始向下突破時,股價之分布會因為空頭市場特性使得峰態係數與偏態係數持續下降。當股價偏態係數與峰態係數處於某個水準之下,且偏態係數持續下降,同時配合股價處於中期均線以下,則視為空方趨勢確立,以中期均線為多方觸價單之進場價位。當股價開始向上突破時,股價之分布會因為多頭市場特性而使股價之峰態係數與偏態係數持續上升。當股價偏態係數與峰態係數處於某個水準之上,且偏態係數持續上升,同時配合股價處於中期均線以上,則視為多方趨勢確立,以中期均線為空方觸價單之進場價位。
出場:
建立部位之後之出場時機,決定了獲利大小與承受之風險,為了保持部位獲利之水準與嚴謹之風險控管,本策略以下列兩種方式結束部位出場。
1. 固定停損停利
2. 追蹤門檻停利
建立部位之後則開始追蹤最大獲利,當獲利超過各個門檻後獲利回吐最大可獲利處之部分保留比率,則獲利則以觸價單停利出場。
程式碼:
多:
Input: AvgLenL(16),LengthL(18),K0L(-1),S0L(-0.7),
LossPoint(160),ProfitPoint(510),BPRiskFloor(380),BpBaseProfit(60);
Vars: KurtL(0),SkewVL(0),ProfitCalc(0),RiskFloor(0),BaseProfitPoint(0),OrderPrice(0);
KurtL = Kurtosis(Close,LengthL);
SkewVL = Skew(Close,LengthL);
If KurtL > K0L and SkewVL > S0L and SkewVL>SkewVL[1] and MarketPosition=0 Then
Buy Next Bar at Average(Close,AvgLenL) Stop ;
RiskFloor = BPRiskFloor/10000*Close;
If MaxPositionProfit / BigPointValue >= RiskFloor and BarsSinceEntry > 0 Then Begin
OrderPrice = EntryPrice + MaxPositionProfit/BigPointValue*BpBaseProfit/100;
Exitlong ("R%LX1") at OrderPrice Stop;
END;
SetStopLoss(LossPoint*BigPointValue);
If MarketPosition = 1 Then
SetProfitTarget(ProfitPoint*BigPointValue);
空:
Input: AvgLenS(19),LengthS(15),K0S(-0.4),S0S(0.2),
LossPoint(160),ProfitPoint(290),BPRiskFloor(240),BpBaseProfit(90);
Vars: KurtS(0),SkewVS(0),ProfitCalc(0),RiskFloor(0),BaseProfitPoint(0),OrderPrice(0);
KurtS = Kurtosis(Close,LengthS);
SkewVS = Skew(Close,LengthS);
If KurtS < K0S and SkewVS < S0S and SkewVS < SkewVS[1] and MarketPosition=0 Then
Sell Next Bar at Average(Close,AvgLenS) Stop ;
RiskFloor = BPRiskFloor/10000*Close;
If MaxPositionProfit / BigPointValue >= RiskFloor and BarsSinceEntry > 0 Then Begin
OrderPrice = EntryPrice - MaxPositionProfit/BigPointValue*BpBaseProfit/100;
ExitShort ("R%SX1") at OrderPrice Stop;
END;
SetStopLoss(LossPoint*BigPointValue);
If MarketPosition= -1 Then
SetProfitTarget(ProfitPoint*BigPointValue);
回測結果:
|
L |
S |
Total |
|
歷年獲利 |
|
Net profit |
1992800 |
1831600 |
3824400 |
|
YTD |
37600 |
勝率 |
44.93% |
54.11% |
49.52% |
|
12M |
(44400) |
交易次數 |
207 |
207 |
414 |
|
2012 |
11200 |
MDD |
(297600) |
(319800) |
(287400) |
|
2011 |
107000 |
MDD/NP |
0.15 |
0.17 |
0.08 |
|
2010 |
47800 |
連錯 |
7 |
7 |
7 |
|
2009 |
291200 |
Sharp ratio |
|
|
0.91 |
|
2008 |
856800 |
K-ratio |
|
|
5.28 |
|
2007 |
(16000) |
賠率 |
|
|
1.65 |
|
2006 |
238800 |
進場效率 |
|
|
0.54 |
|
2005 |
(11800) |
出場效率 |
|
|
0.41 |
|
2004 |
487200 |
|
|
|
|
|
2003 |
114800 |
資料期間:1998/7/21~2013/3/14
手續費來回:1000元