腳本資料讀取的問題

  •   57 
  • 最後發表   funleica  2022 二月 24
funleica 發文於   2022/02/22

請問小幫手

回測以下程式5年資料, 發現有些問題: 回測報告中出現優群的分析,而其在2021/11進場價是100多, 沒有被限制在程式設定的40以下. 檢查歷史資料發現優群在2017年果真股價低於40, 似乎讓trueall(high<=l1,period) 這個條件成真. 不知道是不是因為回測的設定不正確所造成? 

 input:period(400,"股價過去天期");
input:l1(40,"股價上限");
//條件1. 過去N年裡有一年EPS超過M元。這代表這家公司過往曾經有不錯的表現,對應的腳本如下:
input:_period(7,"ESP過去年期");
input:_eps(3,"EPS");
variable: the_eps(0);
the_eps=GetField("每股稅後淨利(元)","Y");
if trueany(the_eps>=_eps,_period) then condition1=true;
//條件2.  過去X日股價都小於Y元,代表有一陣子股價並沒有突出的表現,對應的腳本如下:
//**** 以下條件似乎有問題,
if trueall(high<=l1,period) then condition2=true;
if condition1 and condition2 then ret=1;

XQ小幫手 發文於   2022/02/24

Hello funleica,

 

if trueany(the_eps>=_eps,_period) then condition1=true;

if trueall(high<=l1,period) then condition2=true;

您這種寫法會讓條件符合一次後 condition1 就會一直是True。

建議您修改為:

condition1 = trueany(the_eps>=_eps,_period);

condition2 = trueall(high<=l1,period);

或是

if trueany(the_eps>=_eps,_period) then condition1=true else condition1 = False;

if trueall(high<=l1,period) then condition2=true else condition2 = False;

應該就不會有問題。

  • 按讚來自於
  • funleica
發表回覆
Close