如何將選股中心的選股條件改用 XScript 表達?

  •   255 
  • 最後發表   奔雷  2024 二月 06
奔雷 發文於   2024/02/03

我之前看到 外資不碰的股票有人在收 這篇文章,該文章的策略有用到選股中心「近1日綜合前十大券商合計買超合計佔成交量 5% 以上」與「成交量大於 500 張」兩個條件,由於這兩項條件要到選股中心用滑鼠點選,我想把這兩個條件改用 XScript 來表達。

於是我把文章提供的程式碼改寫成這樣:

input: period(5,"計算期間");
input: investorLimit(2000,"外資持股上限");
input: ratio(50,"主力買張比重(%)");
input: volLimit(500 , "成交均量下限");
input: top10Buy(5, "近 1 日綜合前十大券商合計買超佔成交量比");
input: volRecent(500, "近 1 日成交量最低張數");

SetTotalBar(3);

// 主力買張比重
value1 = summation(GetField("主力買張","D")[1], period);
value2 = summation(volume[1], period);
value3 = value1 / value2 * 100;

value4 = GetField("綜合前十大券商買賣超張數", "D")[1];
value5 = volume[1];
value6 = value4 / value5 * 100;

print("Date=", Date, "top10=", value4);

if GetField("外資持股","D") [1]< investorLimit and value3 > ratio and value2 > volLimit * period and value6 > top10Buy and value5 > volRecent
then ret=1;

但改出來的程式碼回測報酬率卻和原本的策略差很多:

請問是不是我理解錯了「近1日綜合前十大券商合計買超合計佔成交量 5% 以上」的意思?

我的程式碼「value6 > top10Buy」就是想要用來取代「近1日綜合前十大券商合計買超合計佔成交量 5% 以上」條件的,但無法順利取代,請問我該怎麼改才能讓 XScript 可以直接跑出那篇文章的報酬率呢?

排序方式: 標準 | 最新
XQ小幫手 發文於   2024/02/06

Hello, 奔雷.

 

請問是不是我理解錯了「近1日綜合前十大券商合計買超合計佔成交量 5% 以上」的意思? 是的,近一日是指今日,你用[1]是表示昨日「近1日綜合前十大券商合計買超合計佔成交量 5% 以上」,

input: period(5,"計算期間");
input: investorLimit(2000,"外資持股上限");
input: ratio(50,"主力買張比重(%)");
input: volLimit(500 , "成交均量下限");
input: top10Buy(5, "近 1 日綜合前十大券商合計買超佔成交量比");
input: volRecent(500, "近 1 日成交量最低張數");

SetTotalBar(3);

// 主力買張比重
value1 = summation(GetField("主力買張","D")[1], period);
value2 = summation(volume[1], period);
value3 = value1 / value2 * 100;

value4 = GetField("綜合前十大券商買賣超張數", "D");
value5 = volume;
value6 = value4 / value5 * 100;

print("Date=", Date, "top10=", value4);

if 
    GetField("外資持股","D")[1] < investorLimit 
    and value3 > ratio 
    and value2 > volLimit * period 
    and value6 > top10Buy 
    and value5 > volRecent
then 
    ret=1;

修改後回測結果如下,

1707201831860

 

謝謝。

XQ小幫手 發文於   2024/02/06

補充一下正確的"近N期綜合前十大券商合計買超總計佔成交量X%以上"寫法如下

input:N(1),X(5); 

if 
    Summation(GetField("綜合前十大券商買賣超張數"), N) / Summation(GetField("成交量"), N) > 0.01 * X 
then 
    ret=1; 

奔雷 發文於   2024/02/06

感謝小幫手的協助,我改完 code 後,報酬率有變成像範圍文章一樣。

發表回覆
Close