Board logo

标题: 【OptimalF】 [打印本页]

作者: 龙听    时间: 2022-11-2 14:30     标题: 【OptimalF】

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


  5. once begin
  6.   array_setmaxindex( DATAs, watchDays+1 );
  7.   array_setmaxindex( DATAsCopy, watchDays+1 );
  8.   array_setmaxindex( HPRs, watchDays+1 );
  9. end;



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

  12. if isOnStrategy= true then
  13.   begin
  14.     if isHasTraded and sessionlastbar then
  15.       begin
  16.         _arrayShift( DATAs );
  17.         DATAs[1]= theData;
  18.         passDays= passDays + 1;
  19.       end;
  20.   end
  21. else
  22.   begin
  23.     _arrayShift( DATAs );
  24.     DATAs[1]= theData;
  25.     passDays= passDays + 1;
  26.   end;


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

  31.   for k= 0 to 99 begin

  32.     temp= 1;
  33.     for j=1 to watchDays begin
  34.       HPRs[j]= 1 + k/100 * ( -DATAsCopy[j] / maxLoss );
  35.       temp= temp * HPRs[j];
  36.     end;
  37.   
  38.     Geo_Mean[k]= power( temp, 1/watchDays );

  39.   end;


  40.   maxMeans= 0;
  41.   _OptimalF=0;

  42.   for k=0 to 99 begin
  43.     if Geo_Mean[k] > maxMeans then begin
  44.       maxMeans= Geo_Mean[k];
  45.       _OptimalF= k;
  46.     end;
  47.   end;
  48.   
  49. end;
复制代码





欢迎光临 龙听期货论坛 (http://qhlt.club/) Powered by Discuz! 7.2