- UID
- 2
- 积分
- 2892817
- 威望
- 1396440 布
- 龙e币
- 1496377 刀
- 在线时间
- 13326 小时
- 注册时间
- 2009-12-3
- 最后登录
- 2024-12-26
|
【optimalfgeo】
- //OptimalFGeo by George Pruitt
- //My interpretation Sept. 2018
- //www.georgepruitt.com
- //georgeppruitt@gmail.com
- input: minNumTrades(numericSimple);
- vars: totalTradesCount(0),tradeCnt(0);
- array: tradesArray[500](0);
- vars: iCnt(00),jCnt(00),grandTot(0),highI(0);
- vars: optF(0.0),gMean(0.0),fVal(0.0),HPR(0.0),TWR(0.0),hiTWR(0.0);
- vars: biggestLoser(0.0),gat(0.0);
- totalTradesCount = totalTrades;
- If totalTradesCount > totalTradesCount[1] then
- begin
- tradeCnt = tradeCnt + 1;
- tradesArray[tradeCnt] = positionProfit(1);
- end;
- // Taken from my Fortran library - GPP and Vince Book PMF
- optF = 0.0;
- gMean = 1.00;
- gat = 0.00;
- //Only calculate if new trade
- IF(tradeCnt>minNumTrades and totalTradesCount > totalTradesCount[1]) then
- Begin
- biggestLoser = 0;
- grandTot = 0;
- For iCnt = 1 to tradeCnt //get the biggest loser
- begin
- grandTot = grandTot + tradesArray[iCnt];
- IF(tradesArray[iCnt]<biggestLoser) then biggestLoser = tradesArray[iCnt];
- end;
- // print(grandTot," ",biggestLoser);
- IF({grandTot > 0 and} biggestLoser <0) then
- begin
- // print("Inside TWR Calculations");
- highI = 0;
- hiTWR = 0.0;
- for iCnt = 1 to 100
- begin
- fVal = .01 * iCnt;
- TWR = 1.0;
- for jCnt = 1 to tradeCnt // calculate the Terminal Wealth Relative
- begin
- HPR = 1. + (fVal * (-1*tradesArray[jCnt]) / biggestLoser);
- TWR = TWR * HPR;
- // print(fVal," ",iCnt," " ,jCnt," Trades ",tradesArray[jCnt]," HPR ",HPR:6:4," TWR : ",TWR:6:4," hiTWR",hiTWR:6:4," bl ",biggestLoser);
- end;
- // print(iCnt," ",TWR," ",hiTWR);
- IF(TWR>hiTWR) THEN
- begin
- hiTWR = TWR;
- optF = fVal; // assign optF to fVal in case its the correct one
- end
- else
- break; //highest f found - stop looping
- end;
- If (TWR <= hiTWR or optF >= 0.999999) then
- begin
- TWR = hiTWR;
- OptimalFGeo = optF; //assign optF to the name of the function
- end;
- gmean = power(TWR,(1.0 / tradeCnt));
-
- if(optF<>0) then gat = (gMean - 1.0) * (biggestLoser / -(optF));
- print(d," gmean ",gmean:6:4," ",gat:6:4); // I calculate the GMEAN and GeoAvgTrade
- end;
- end;
复制代码 |
论坛官方微信、群(期货热点、量化探讨、开户与绑定实盘)
|