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
Testing Optimal f
Testing Optimal f
 Attachments

 single contract per trade.
 FCOneCOntract.png (16.68 KiB) Viewed 8521 times

 Volality adjusted
 FCVolatility.png (16.21 KiB) Viewed 8521 times

 Optimal f
 FCOptimal.png (17.9 KiB) Viewed 8521 times

 Site Admin
 Posts: 8601
 Joined: Tue Apr 06, 2004 1:41 pm
 Location: Boston, MA
 Contact:
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.
But hey, that's just me. Others would approach it differently, I'm sure.
 Attachments

 mcsetup.png (11.76 KiB) Viewed 6585 times
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
"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.
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
The competitor backtesting product "WealthLab" also offers Monte Carlo resampling of equity curves (as an addon to the base product). Here is their introduction to the topic: http://wl4.wealthlab.com/cgibin/Wealt ... =MCLab.htmMonte 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.
"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.