Money management & control risk

Viewing 9 posts - 16 through 24 (of 24 total)
  • Author
    Posts
  • #105117 quote
    Vonasi
    Moderator
    Master

    I found this EasyLanguage calculator of F in the September 26 2018 post of this blog:

    http://georgepruitt.com/category/easylanguage/must-know/

    I know nothing of EasyLanguage coding but I see that it uses arrays which may make conversion to PRT either impossible or very difficult.

    Perhaps Nicolas could comment on whether it could be converted?

    Note: DO NOT try to use the code posted here in PRT as it is – it is EasyLanguage code!

    //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;
    #105384 quote
    Nicolas
    Keymaster
    Master

    This is a rough version, it makes the computation but i used a positionprofit in percentage instead of real money.. so I assume the result is not really the one that we need. The problem is to know the position profit in money by using positionperf at a time when we don’t know what was the Close value used to calculate it.

    defparam cumulateorders=false
    
    // --- settings
    minNumTrades = 10
    // --- end of settings
    
    //dummy strategy
    irsi = rsi[14]
    if irsi crosses over 50 then
    buy at market
    tradeCnt = tradeCnt+1
    endif
    set target pprofit 20
    set stop ploss 10
    
    //
    optF = 0.0
    gMean = 1.00
    gat = 0.00
    IF(tradeCnt>minNumTrades and tradeCnt<>tradeCnt[1]) then
    biggestLoser = 0
    grandTot = 0
    For iCnt = 1 to tradeCnt do //get the biggest loser
    grandTot = grandTot + positionperf(iCnt)
    IF(positionperf(iCnt)<biggestLoser) then
    biggestLoser = positionperf(iCnt)
    endif
    next
    IF(grandTot > 0 and biggestLoser <0) then
    //highI = 0
    hiTWR = 0.0
    for iCnt = 1 to 100 do
    fVal = .01 * iCnt
    TWR = 1.0
    for jCnt = 1 to tradeCnt do // calculate the Terminal Wealth Relative
    HPR = 1.0 + (fVal * (-1*positionperf(jCnt) / biggestLoser))
    TWR = TWR * HPR
    
    IF(TWR>hiTWR) THEN
    hiTWR = TWR
    optF = fVal // assign optF to fVal in case its the correct one
    else
    break
    endif
    next
    next //highest f found - stop looping
    If (TWR <= hiTWR or optF >= 0.999999) then
    TWR = hiTWR
    OptimalFGeo = optF //assign optF to the name of the function
    endif
    //gmean = power(TWR,(1.0 / tradeCnt))
    //y = x^p = e^(p*LN(x))
    //This could then be coded as: y = EXP(p*LOG(x)) This works fine.
    gmean = exp((1.0/tradeCnt)*log(TWR))
    
    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
    endif
    endif
    endif
    
    graph gat
    graph OptimalFGeo
    //graph tradeCnt
    //graph positionperf
    Vonasi thanked this post
    #105400 quote
    Vonasi
    Moderator
    Master

    I think it will take a few moments to get my head round what that code is trying to do. Perhaps it would be better to try to code it as an indicator with a simulated strategy built in rather than a strategy?

    #105454 quote
    deleted271219
    Member
    New

    No, I can’t … the code is yet to be completed.

    A few days ago I asked how to enter Kelly’s F or Kelly’s Secure F as money management in the code and I still haven’t got an answer.

    In addition, I want to get a couple of things for the code:

    1. For each successful operation add 10% more risk than in the previous operation for the next operation, and for each failed operation remove 10% less risk than in the previous operation.
    2. If the total benefit of the system is for example between € 10,000 or € 12,000, operate with € 5 / pip. If the total benefit of the system falls, and is between € 8,000 or € 10,000 operate with € 4 / pip. But if then the total benefit of the system is once again between € 8,000 or € 10,000, then re-operate with € 5 / pip. With these ideas the code would be complete and could upload it.
    #105456 quote
    robertogozzi
    Moderator
    Master

    @sdesergio

    do NOT use Insert PRT code for TEXT, it doesn’t work!

    In you last request did you refer to the current discussion or to Kelly’s Secure F?

    #105465 quote
    deleted271219
    Member
    New
    Let's see, all I say is that the code is unfinished and I need help.
    Also in September I will have 200k of backtest and I will have to update it very probably.
    
    Until then it is nonsense to upload a half-programmed code.
    
    I don't force anyone to "work for me" ... I've only asked for help just like others like me do.
    
    Im referred F of Kelly and actually discusión.
    #105468 quote
    robertogozzi
    Moderator
    Master

    @sdesergio

    do NOT use Insert PRT code for TEXT, it doesn’t work!

    #105471 quote
    robertogozzi
    Moderator
    Master

    @sdesergio

    1. don’t mix post from different topics
    2. try not to urge help, IF someone is able AND willing to answer… he will, provided you have posted all details and answered any question may have been asked

    urging people to work for you when you want them to… does not work as intended!

    #105479 quote
    Vonasi
    Moderator
    Master

    sdesergio – no one is working here. No one is employed or paid by anyone else to provide free coding solutions to anyone else. This is a forum set up by someone who is not employed by PRT just to provide a community for those who use PRT. It is moderated by volunteers.

    The Optimal F calculation that you request has been discussed in the past and no one was able to provide the code then. We are now a tiny step closer thanks to the Easylanguage code that I found and thanks to Nicolas’s conversion of it- all this despite a lack of actual information on how exactly Optimal F is calculated from yourself or from any sources found by anyone else and yet you are complaining that no one has provided you with an answer. Then you throw in a whole bunch of new demands on top!

    As moderators we have had to constantly remind you of basic forum etiquette and to tidy up your posts after you and as volunteers giving our time for free we would appreciate it if you took up slightly less of our time doing this.

    At the moment your posts are likely to get you less help rather than more help. 🙂

Viewing 9 posts - 16 through 24 (of 24 total)
  • You must be logged in to reply to this topic.

Money management & control risk


ProOrder: Automated Strategies & Backtesting

New Reply
Summary

This topic contains 23 replies,
has 4 voices, and was last updated by Vonasi
6 years, 5 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/15/2019
Status: Active
Attachments: No files
Logo Logo
Loading...