: | : | :期货程序化 | :期货程序化研究 | :期货量化学习 | :期货量化 |
返回列表 发帖

【optimalfgeo】

【optimalfgeo】

  1. //OptimalFGeo by George Pruitt
  2. //My interpretation Sept. 2018
  3. //www.georgepruitt.com
  4. //georgeppruitt@gmail.com

  5. input: minNumTrades(numericSimple);
  6. vars: totalTradesCount(0),tradeCnt(0);
  7. array: tradesArray[500](0);

  8. vars: iCnt(00),jCnt(00),grandTot(0),highI(0);
  9. vars: optF(0.0),gMean(0.0),fVal(0.0),HPR(0.0),TWR(0.0),hiTWR(0.0);
  10. vars: biggestLoser(0.0),gat(0.0);

  11. totalTradesCount = totalTrades;
  12. If totalTradesCount > totalTradesCount[1] then
  13. begin
  14.         tradeCnt = tradeCnt + 1;
  15.         tradesArray[tradeCnt] = positionProfit(1);
  16. end;

  17. // Taken from my Fortran library - GPP and Vince Book PMF

  18. optF = 0.0;
  19. gMean = 1.00;
  20. gat   = 0.00;
  21. //Only calculate if new trade
  22. IF(tradeCnt>minNumTrades and totalTradesCount > totalTradesCount[1]) then
  23. Begin
  24.         biggestLoser = 0;
  25.         grandTot = 0;
  26.         For iCnt = 1 to tradeCnt //get the biggest loser
  27.         begin
  28.                    grandTot = grandTot + tradesArray[iCnt];
  29.                    IF(tradesArray[iCnt]<biggestLoser) then biggestLoser = tradesArray[iCnt];
  30.         end;
  31. //        print(grandTot," ",biggestLoser);
  32.         IF({grandTot > 0 and} biggestLoser <0) then
  33.         begin
  34. //                print("Inside TWR Calculations");
  35.                 highI = 0;
  36.                 hiTWR = 0.0;
  37.                 for iCnt = 1 to 100
  38.                 begin
  39.                         fVal = .01 * iCnt;
  40.                         TWR = 1.0;
  41.                         for jCnt = 1 to tradeCnt // calculate the Terminal Wealth Relative
  42.                         begin
  43.                             HPR = 1. + (fVal * (-1*tradesArray[jCnt]) / biggestLoser);
  44.                             TWR = TWR * HPR;
  45. //                           print(fVal," ",iCnt," " ,jCnt," Trades ",tradesArray[jCnt]," HPR ",HPR:6:4," TWR : ",TWR:6:4," hiTWR",hiTWR:6:4," bl ",biggestLoser);
  46.                         end;
  47. //                        print(iCnt," ",TWR," ",hiTWR);
  48.                         IF(TWR>hiTWR) THEN
  49.                         begin
  50.                             hiTWR = TWR;
  51.                             optF = fVal;            // assign optF to fVal in case its the correct one               
  52.                         end
  53.                         else
  54.                             break;                     //highest f found - stop looping
  55.                 end;               
  56.                 If (TWR <= hiTWR or optF >= 0.999999) then
  57.                 begin
  58.                         TWR  = hiTWR;
  59.                         OptimalFGeo = optF;  //assign optF to the name of the function
  60.                 end;      
  61.                 gmean = power(TWR,(1.0 / tradeCnt));
  62.                
  63.                 if(optF<>0) then gat   = (gMean - 1.0) * (biggestLoser / -(optF));               
  64.                 print(d," gmean ",gmean:6:4," ",gat:6:4);  // I calculate the GMEAN and GeoAvgTrade
  65.         end;
  66. end;
复制代码

论坛官方微信、群(期货热点、量化探讨、开户与绑定实盘)
 
期货论坛 - 版权/免责声明   1.本站发布源码(包括函数、指标、策略等)均属开放源码,用意在于让使用者学习程序化语法撰写,使用者可以任意修改语法內容并调整参数。仅限用于个人学习使用,请勿转载、滥用,严禁私自连接实盘账户交易
  2.本站发布资讯(包括文章、视频、历史记录、教材、评论、资讯、交易方案等)均系转载自网络主流媒体,内容仅为作者当日个人观点,本网转载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。本网不对该类信息或数据做任何保证。不对您构成任何投资建议,不能依靠信息而取代自身独立判断,不对因使用本篇文章所诉信息或观点等导致的损失承担任何责任。
  3.本站发布资源(包括书籍、杂志、文档、软件等)均从互联网搜索而来,仅供个人免费交流学习,不可用作商业用途,本站不对显示的内容承担任何责任。请在下载后24小时内删除。如果喜欢,请购买正版,谢谢合作!
  4.龙听期货论坛原创文章属本网版权作品,转载须注明来源“龙听期货论坛”,违者本网将保留追究其相关法律责任的权力。本论坛除发布原创文章外,亦致力于优秀财经文章的交流分享,部分文章推送时若未能及时与原作者取得联系并涉及版权问题时,请及时联系删除。联系方式:http://www.qhlt.cn/thread-262-1-1.html
如何访问权限为100/255贴子:/thread-37840-1-1.html;注册后仍无法回复:/thread-23-1-1.html;微信/QQ群:/thread-262-1-1.html;网盘链接失效解决办法:/thread-93307-1-1.html

返回列表