Tradestation users who have browsed the Tradestation Forum will be acquainted with the work of John Joseph, CTA, of Dimension Creative Technologies. John is the infamous "Mathemagician" and he has agreed to make a presentation on Trade Position Sizing. Specifically...
The presentation begins with a general introduction of constantaccountequity position sizing and a survey of publicdomain position sizing methods (e.g. constant contract, constant risk, constant volatility). Next will be a discussion of variableaccountsize methods (i.e. compounding, a.k.a. money management) with a survey of publicdomain methods (e.g. Fixed Fractional, Fixed Ratio, Optimal F). Throughout the presentation, the emphasis will be on application of the concepts using Tradestation and sample EasyLanguage code will be provided wherever possible. A complete sample trading system is provided.
We might transform some of the TS code that Math provides to NeoTicker during his Webinar during some future Sunday NeoTicker Webinar.
The webinar with Mathemagician is free.
July 16, 5am Pacific Daylight Time (currently GMT 7)
Registration is required before the webinar begins. You may register for it here:
https://www.gotomeeting.com/register/856006095
Cheers!
Mathemagician Live! on Position Sizing
Moderator: moderators
Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.
Thank you for your support.
 michal.kreslik
 rank: 1000+ posts
 Posts: 1034
 Joined: Sat May 13, 2006 2:40 am
 Reputation: 3
 Location: Monte Carlo, Monaco
 Real name: Michal Kreslik
 Gender:
 Contact:
Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.
Thank you for your support.
 michal.kreslik
 rank: 1000+ posts
 Posts: 1034
 Joined: Sat May 13, 2006 2:40 am
 Reputation: 3
 Location: Monte Carlo, Monaco
 Real name: Michal Kreslik
 Gender:
 Contact:
 TomKeough
 rank: <50 posts
 Posts: 29
 Joined: Sat Jun 17, 2006 1:13 am
 Reputation: 0
 Location: Jacksonville, Florida
 Real name: Tom Keough
 Gender:
 Contact:
MoneyManagement Book by Ralph Vince cited by Mathemagician
michal.kreslik wrote:Forsooth, having Mathemagician live on a webinar really is kind of hardcore..
FYI,
I bought the book cited by Mathemagician here:
http://www.powells.com/biblio/HARDCOVER ... =23955#top
for $25 used (no dustcover).
Tom
"We either make ourselves miserable,
or we make ourselves strong.
The amount of work is the same."
 Carlos Castaneda
or we make ourselves strong.
The amount of work is the same."
 Carlos Castaneda

 rank: 50+ posts
 Posts: 113
 Joined: Tue Jun 13, 2006 3:42 am
 Reputation: 0
 Location: Atlanta, GA
 Gender:
After listening to John's presentation today, It still seems to me that the most important aspect of successful trading is figuring out which type of position sizing fits best with the methodology you trade. And in turn without a solid method, sizing doesn't matter at all.
I can't necessarily agree with him that there are some types of postioning which are unacceptable for any trading system, which is what I assumed he was implying from the shoot down of the Martingale methods. I have seen this method applied to many systems which use near even odds and some of them have been quite successful.
One idea he presented did spark my interest though, and that is when he stated "if you trade long enough using a nonoptimal sizing method you will eventually experience its weakness, in turn causing you to lose everything." I know it's not a perfect quote, but I can see how after a period of time, you have to quit trading period, or at least reduce your risk capital in order to actually realize profits.
It was a good presentation and I appreciate him and the organizers taking the time for putting it on.
I can't necessarily agree with him that there are some types of postioning which are unacceptable for any trading system, which is what I assumed he was implying from the shoot down of the Martingale methods. I have seen this method applied to many systems which use near even odds and some of them have been quite successful.
One idea he presented did spark my interest though, and that is when he stated "if you trade long enough using a nonoptimal sizing method you will eventually experience its weakness, in turn causing you to lose everything." I know it's not a perfect quote, but I can see how after a period of time, you have to quit trading period, or at least reduce your risk capital in order to actually realize profits.
It was a good presentation and I appreciate him and the organizers taking the time for putting it on.
 TomKeough
 rank: <50 posts
 Posts: 29
 Joined: Sat Jun 17, 2006 1:13 am
 Reputation: 0
 Location: Jacksonville, Florida
 Real name: Tom Keough
 Gender:
 Contact:
Optimal f MoneyManagement code from a trading system
I found this Optimal f MoneyManagement code for a trading system.
Here is the code:
I found it here:
http://www.seertrading.com/SID/512.html
Tom
Here is the code:
Code: Select all
Notes for this Money Management Position Sizing Strategy:
Description
An Optimal F money management/position sizing strategy. Optimal F Money Management was developed by Ralph Vince as an aggressive way to grow your account balance. Optimal F is simply the optimal amount of capital that should be invested in each trade.
Optimal F has it's critics  with one of the major criticisms being that it is too risky. The money management strategy presented here focuses on the practical issues on how to implement Optimal F for a real trading system, and as such commentary about the wisdom of using OptimalF is beyond the scope of this money management strategy. There are plenty of resources on the internet that discus Optimal F in great detail.
As the OptimalF formula uses the trading history of the system in it's calculation the first issue that we first have to consider is what to do before there are enough trades for the results of OptimalF to be statistically meaningful. The simplest solution  the one adopted here  is to wait for X trades to occur, and then use the real OptimalF value. We then recalculate the value of OptimalF after each trade.
This OptimalF strategy is controlled by two variables: $mintrades and $defaultf. The value of $mintrades contains the number of trades that have to occur before the real value of OptimalF is used. If the number of trades is less than $mintrades, the value of $defaultf is used to calculate the size of the position. These values can be changed in the PositionSize function.
All orders are supported with this money management, but for the case of stop and limit orders this money management expects to be passed the stop and limit prices. The actual position size that is calculated is suitable for stocks but with a little tweaking it can be used for futures or forex.
The calculation of OptimalF that is used within this money management is extremely inefficient.
Notes for this Money Management Position Sizing Strategy:
PositionSize:
###########################
# Optimal F Money management  read notes for a description
# Play around with the vars below to change the settings of this MM
#
my $mintrades = 20; #Minimum number of trades before optimalf is used
my $defaultf = 0.30; #The value of optimalf if we havn't got enough trades
#
#
############################
sub OptimalF {
#This function uses a brute force approach to calculate the optimal f
#and can be made *much* more efficient.
#define our variables
my ($BestTWR,$OptimalF,$f,$TWR,$HPR,$WSC);
$WSC=LargestLosingTrade;
#Loop round for all the values of f  in this case
#all values between 1 and 100
foreach my $per (1..100) {
$f=$per/100; #Set F to be a percent
$TWR=1; #reset the TWR
#Loop round all trades for this system
foreach my $trade (TradeHistory) {
#Work out the HPR and TWR
$HPR=1+($f*($trade>NetProfit / $WSC));
$TWR*=$HPR;
}
#Output "f $f is TWR $TWR";
#Is this the best f so far?
if ($BestTWR<$TWR) {
$BestTWR=$TWR;
$OptimalF=$f;
}
}
#Output "best $BestTWR Optimal F $OptimalF";
#Return the optimal f
return $OptimalF;
}
#Set the optimalf to the default value
my $optimalf=$defaultf;
if (TotalTrades> $mintrades) {
#we have enough trades  calculate the optimalf
$optimalf=OptimalF;
}
#Calculate the number of units we should hold for this position
my $units=int(($optimalf * LiquidatingValue)/ClosePrice);
return $units;
BuyMarket event logic:
if (ShortPosition) {
#If we have a short position, close it.
PlaceBuyOpen('OptimalF');
}
else {
#we have no position, or we are long.
my $num=PositionSize();
PlaceBuyOpen('OptimalF',$num) if $num;
}
BuyStop event logic:
my $stop=shift;
#Stop trading if we do not have a stop price
die 'No stop price for BuyStop' unless $stop;
if (ShortPosition) {
#If we have a short position, close it.
PlaceBuyStop('OptimalFClosingShort',0,$stop);
}
else {
#we have no position, or we are long.
my $num=PositionSize();
PlaceBuyStop('OptimalFGoingLong',$num,$stop) if $num;
}
BuyLimit event logic:
my $limit=shift;
#Stop trading if we do not have a limit price
die 'No limit price for BuyLimit' unless $limit;
if (ShortPosition) {
#If we have a short position, close it.
PlaceBuyLimit('OptimalFClosingShort',0,$limit);
}
else {
#we have no position, or we are long.
my $num=PositionSize();
PlaceBuyLimit('OptimalFGoingLong',$num,$limit) if $num;
}
BuyStopLimit event logic:
my ($stop,$limit)=@_;
#Stop trading if we do not have a stop and limit price
die 'No limit price for BuyStopLimit' unless $limit;
die 'No stop price for BuyStopLimit' unless $stop;
if (ShortPosition) {
#If we have a short position, close it.
PlaceBuyStopLimit('OptimalFClosingShort',0,$stop,$limit);
}
else {
#we have no position, or we are long.
my $num=PositionSize();
PlaceBuyStopLimit('OptimalFGoingLong',$num,$stop,$limit) if $num;
}
SellMarket event logic:
if (LongPosition) {
#If we have a long position, close it.
PlaceSellOpen('OptimalFClosingLong');
}
else {
#If we have no position or we are short, place the order
my $num=PositionSize();
PlaceSellOpen('OptimalFGoingShort',$num) if $num;
}
SellStop event logic:
my $stop=shift;
#Stop trading if we do not have a stop price
die 'No stop price for BuyStop' unless $stop;
if (LongPosition) {
#If we have a long position, close it.
PlaceSellStop('OptimalFClosingLong',0,$stop);
}
else {
#If we have no position or we are short, place the order
my $num=PositionSize();
PlaceSellStop('OptimalFGoingShort',$num,$stop) if $num;
}
SellLimit event logic:
my $limit=shift;
#Stop trading if we do not have a limit price
die 'No limit price for BuyStop' unless $limit;
if (LongPosition) {
#If we have a long position, close it.
PlaceSellLimit('OptimalFClosingLong',0,$limit);
}
else {
#If we have no position or we are short, place the order
my $num=PositionSize();
PlaceSellLimit('OptimalFGoingShort',$num,$limit) if $num;
}
SellStopLimit event logic:
my ($stop,$limit)=@_;
#Stop trading if we do not have a stop and limit price
die 'No limit price for BuyStopLimit' unless $limit;
die 'No stop price for BuyStopLimit' unless $stop;
if (LongPosition) {
#If we have a long position, close it.
PlaceSellStopLimit('OptimalFClosingLong',0,$stop,$limit);
}
else {
#If we have no position or we are short, place the order
my $num=PositionSize();
PlaceSellStopLimit('OptimalFGoingShort',$num,$stop,$limit) if $num;
}
I found it here:
http://www.seertrading.com/SID/512.html
Tom
"We either make ourselves miserable,
or we make ourselves strong.
The amount of work is the same."
 Carlos Castaneda
or we make ourselves strong.
The amount of work is the same."
 Carlos Castaneda
Please add www.kreslik.com to your ad blocker white list.
Thank you for your support.
Thank you for your support.