龙听期货论坛's Archiver

C
+
+


 微信: QQ:

龙听 发表于 2022-11-2 14:30

【OptimalF】

[code]input: theData(Numeric), watchDays(Numeric), isOnStrategy(TrueFalse);
array: DATAs[](0), DATAsCopy[](0), HPRs[](1), Geo_Mean[101](1);
var: maxLoss(0), maxMeans(0), j(0), k(0), temp(1);
var: MP(0), passDays(0), isHasTraded(false);


once begin
  array_setmaxindex( DATAs, watchDays+1 );
  array_setmaxindex( DATAsCopy, watchDays+1 );
  array_setmaxindex( HPRs, watchDays+1 );
end;



MP= i_MarketPosition;
if MP<>MP[1] then isHasTraded= true;

if isOnStrategy= true then
  begin
    if isHasTraded and sessionlastbar then
      begin
        _arrayShift( DATAs );
        DATAs[1]= theData;
        passDays= passDays + 1;
      end;
  end
else
  begin
    _arrayShift( DATAs );
    DATAs[1]= theData;
    passDays= passDays + 1;
  end;


if watchDays > 0 and passDays > watchDays then begin
  
  array_copy( DATAs, 1, DATAsCopy, 1, watchDays );
  maxLoss= minlist( Lowest_a( DATAsCopy, watchDays ), -1 );

  for k= 0 to 99 begin

    temp= 1;
    for j=1 to watchDays begin
      HPRs[j]= 1 + k/100 * ( -DATAsCopy[j] / maxLoss );
      temp= temp * HPRs[j];
    end;
  
    Geo_Mean[k]= power( temp, 1/watchDays );

  end;


  maxMeans= 0;
  _OptimalF=0;

  for k=0 to 99 begin
    if Geo_Mean[k] > maxMeans then begin
      maxMeans= Geo_Mean[k];
      _OptimalF= k;
    end;
  end;
  
end;

[/code]

页: [1]