## Testing Optimal f

Discussions about Money Management and Risk Control.
ratio
Roundtable Knight
Posts: 338
Joined: Sun Jan 15, 2006 11:07 pm
Location: Montreal, Canada

### Testing Optimal f

Well I was curious to program a system that would calculate the unit size using the "optimal f" calculation.

It appear that it look good when you apply it to your system when you know what was your biggest losing trade. However In trying to apply it in an ongoing trading journey, as per the included script does. This script look at the past history of trade as it is advencing in time, and calculate the current Optimal f, given what we know at that time. As you will see and if you experiment, hopefully you wont encounter, a bigger (biggest losing trade) or you will go bankrupt pretty fast.

Any comment, anybody have traded with this "Optimal f"

The result in the table below are for a sample trading system that follow trend line. The contract is Feeder Cattle.

The First Chart is for a single contract per trade.
The second is volatility adjusted
The third is with Optimal f (and unfortunately the 3rd trade was a bigger loser than the first one)

Also you have the modified Multi money manager that implement the Optimal f
==================================
VARIABLES: adjustedEquity, riskEquity, dollarRisk TYPE: Money
VARIABLES: loopf,Optimalf,p TYPE: FLOATING
VARIABLES: looptrade TYPE: integer
VARIABLES: HPR,TWR,PREVTWR TYPE: FLOATING
VARIABLES: LargestLosing TYPE:FLOATING

IF algorithm = FIXED_FRACTIONAL THEN

' Compute the risk equity.
riskEquity = system.tradingEquity * riskPerTrade

' Compute the dollar risk.
dollarRisk = entryRisk * instrument.bigPointValue

' Adjust the unit to this percentage.
IF dollarRisk = 0 THEN
unitSize = 1
ELSE
unitSize = riskEquity / dollarRisk
ENDIF

ELSE IF algorithm = SINGLE_CONTRACT THEN

' Just use a single contract.
unitSize = 1

ELSE IF algorithm = VOLATILITY_ADJUSTED THEN

' Compute the risk equity.
riskEquity = system.tradingEquity * riskPerTrade

' Compute the dollar risk.
dollarRisk = averageTrueRange * instrument.bigPointValue

' Adjust the unit to this percentage.
IF dollarRisk = 0 THEN
unitSize = 1
ELSE
unitSize = riskEquity / dollarRisk
ENDIF
ELSE IF algorithm = OPTIMAL_F THEN

LargestLosing = 0

for looptrade = 1 to test.totaltrades+1
if test.tradeprofit[looptrade] < LargestLosing THEN
largestLosing = test.tradeprofit[looptrade]/test.tradequantity[looptrade]
endif
next

PRINT "============================================================"
PRINT "Date= " + test.currentdate + " total trade = " + test.totaltrades + " LargestLosing = " + largestlosing
if LargestLosing < 0 and test.totaltrades >= 2 THEN
loopf = 0.00
TWR = 1
PREVTWR = 0
while TWR >= PREVTWR
PREVTWR = TWR
loopf=loopf+0.01
for looptrade = test.totaltrades to 1 step -1
HPR = 1 + (loopf * (-test.tradeprofit[looptrade] / largestlosing))
TWR = TWR * HPR
PRINT "loopf=" + loopf + " HPR=" + HPR + " TWR= " + TWR + " Trade Proft=" + test.tradeprofit[looptrade] + " Largest losing=" + largestlosing

next

endwhile

unitsize = asinteger(system.tradingequity / (abs(largestlosing) / loopf))

ELSE
unitsize = 1

ENDIF

PRINT "UNITSIZE ======> " + unitsize + " Optimal f = " + Loopf
ENDIF

' Set to filter the trade if the unitsize is zero
IF unitSize = 0 THEN unitSize = FILTER
Attachments
single contract per trade.
FCOneCOntract.png (16.68 KiB) Viewed 8674 times
Volality adjusted
FCVolatility.png (16.21 KiB) Viewed 8674 times
Optimal f
FCOptimal.png (17.9 KiB) Viewed 8674 times

Tim Arnold
Site Admin
Posts: 8652
Joined: Tue Apr 06, 2004 1:41 pm
Location: Boston, MA
Contact:
You will certainly go bust trading with Optimal F as a unit size. That is way too much heat for futures.

BARLI
Roundtable Knight
Posts: 650
Joined: Sat Jan 17, 2004 6:01 pm
Location: USA
Tim, what from your experience works best for futures, if system has a win per. of 60%?

sluggo
Roundtable Knight
Posts: 2986
Joined: Fri Jun 11, 2004 2:50 pm
Maybe it would be a good idea to find out more about a system than just its "winning percentage", before choosing a betsize.

BARLI
Roundtable Knight
Posts: 650
Joined: Sat Jan 17, 2004 6:01 pm
Location: USA
Short term, 2 days hold on avg, PF 1.4 . Win 62% Los 38%

sluggo
Roundtable Knight
Posts: 2986
Joined: Fri Jun 11, 2004 2:50 pm
I'd run some Monte Carlo equity curve resampling studies at various betsizes, and have a look at the (depth of drawdown) and (length of drawdown) plots. I would ask myself "Can I Keep Going When This Happens?" If not, turn down the heat, run the studies again, and look at the plots again.

But hey, that's just me. Others would approach it differently, I'm sure.
Attachments
mcsetup.png (11.76 KiB) Viewed 6738 times

BARLI
Roundtable Knight
Posts: 650
Joined: Sat Jan 17, 2004 6:01 pm
Location: USA
makes sence to me too, but doesn't Monte Carlo leave much space to a chance? What about exhaustive run?

sluggo
Roundtable Knight
Posts: 2986
Joined: Fri Jun 11, 2004 2:50 pm
Here's a comprehensive discussion about Monte Carlo resampling of equity curves: http://www.tradingblox.net/Files/MC_res ... _Nbars.pdf

The Trading Blox User's Guide (link) also has an excellent explanation, including lots of very helpful figures (the User's Guide is downloadable and free). It begins
Monte Carlo Simulations

A Monte Carlo simulation is one way of determining the robustness of a system and of answering the question: "What if the past had been just slightly different"? Trading Blox's Monte Carlo feature simulates new equity curves that are similar to the actual test equity curve but different in certain random ways. A typical Monte Carlo simulation might generate hundreds or thousands of new equity curves. Trading Blox supports two different algorithms for the simulation of the Monte Carlo equity curves: reordering and sampling with replacement. In each case, the new equity curves are generated by taking portions of the actual test equity curve. In real trading, bad days occur together with a frequency that is much higher than one might attribute to purely random chance. This is because at the end of large trends many markets seem to get carried along and then reverse at the same time. The period of a system's maximum drawdown is usually a statistically improbable series of down periods. Trading Blox allows you to specify the number of days which make up each portion using the preference "Sample Grouping Days". This feature allows you to generate equity curves which maintain some of the autocorrelation found in actual equity curves. Without this feature, Monte Carlo simulations tend to underestimate the potential for large or lengthy drawdowns because the randomization process will result in equity curves that don't often show the lengthy periods of negative returns since they are statistically unlikely.
The competitor backtesting product "Wealth-Lab" also offers Monte Carlo resampling of equity curves (as an add-on to the base product). Here is their introduction to the topic: http://wl4.wealth-lab.com/cgi-bin/Wealt ... =MCLab.htm

"Mechanica", another competitor backtesting product, offers Monte Carlo resampling of equity curves as well.
http://www.mechanicasoftware.com/multi_ ... esults.htm (Click on the tabs at the bottom. Monte Carlo tabs begin with the letters "MC").

I have read claims (link) that the "Traders Studio" competitor backtesting product also has Monte Carlo resampling of equity curves. However I can't find discussion of their Monte Carlo offerings on their sales website. Nor can I find any of their product documentation ... except for this web page http://www.tradersstudio.com/Products/t ... fault.aspx which offers to SELL the manuals (in printed form) for \$39.95.

And, of course, there are numerous discussions of Monte Carlo resampling of equity curves, right here on this Trader's Roundtable forum. Try out the Search facility to find some of them, and enjoy the exploration.