[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Here is software code for Johnson's betsizing algorithm



PureBytes Links

Trading Reference Links

Thank you, Mark.

----- Original Message -----
From: Mark Johnson <janitor@xxxxxxxxxxxx>
To: <omega-list@xxxxxxxxxx>
Sent: Thursday, July 13, 2000 6:12 AM
Subject: Here is software code for Johnson's betsizing algorithm


> The message "Vendor system, real profits for 3 years" included this
>
>     >
>     >   I also decided to use a betsize selection algorithm that
>     > risked a percentage of my total account equity on every
>     > trade. But this percentage is ITALICS{not fixed} -- it
>     > varies as the account equity fluctuates. The risk-versus
>     > -equity curve for my betsize approach is shown in Figure 1,
>     > and the math formula behind the curve was presented in
>     > Club3000 News #99.04.
>     >
>     >   note: The curve of Figure 1 was generated in Microsoft
>     >   Excel, and may be viewed or downloaded from the web, at
>     >      http://www.mjohnson.com/plots/fig1_2k01.xls
>     >
>
> Club3000 sells backissues for the relatively modest
> price of US $5.00; you may decide that you want to
> buy backissue #99.04. It includes a complete exposition
> of my betsizing approach including both my equations
> and numerous test cases for debugging.  I will contact
> the Editor of Club3000 News to ask permission to reprint
> that article here on the omega-list.  It might take
> a couple of weeks before I get an answer; I believe the
> Editor is on Summer vacation.
>
> Meanwhile, I'd like to give away (for free :-) the
> little PERL program that implements my betsizing
> algorithm.  It uses the very same variable names as
> the betsizing equation in #99.04 and it implements the
> betsizing equation exactly.  You can try it out on
> the testcases in the Newsletter to see for yourself
> whether it gives the same answers are were printed
> back in April of 1999.  [Answer: yes]
>
> (Why PERL?  Why not Omega's EasyLanguage?  Because I
> happen to trade a portfolio of many different commodities
> out of the same account.  What I need is the daily
> combined total equity (including cash, closed trade
> equity, and open trade equity), added up for all
> commodities in the portfolio, and this isn't available
> from Tradestation / EasyLanguage.  TS/EL just gives
> you the equity from a single "market+system", not the
> total of all equity in all commodities in the Workspace
> or Custom Data List.)
>
> The filename is "calc_bet.pl" ; the extension ".pl"
> indicates that it is PERL source code.  Don't be
> frightened, it's just ASCII text -- you can load it
> into Windows Notepad or WordPad or vi or emacs and
> play around with it.  But of course you do need
> to have the PERL language system on your machine
> to actually *run* the code :-).  I got PERL on
> a free CD-ROM at the back of the $29 book "Teach
> Yourself PERL5 in 21 Days", one of MANY books that
> discuss the PERL language and that include PERL
> s/w along with the text.  Naturally, Unix and
> Linux systems are SHIPPED with PERL already
> installed, so if you're running one of those,
> you're set to go right now.  If you have any
> problems running the code or preparing its inputs
> or interpreting its output, feel free to email me.
>
> I hope you enjoy it,
>


----------------------------------------------------------------------------
----


> #
> # Perl5 program that implements the betsize
> #   algorithm in Club 3000 News issue # 99.04
> #
>
> $J = 4.64e4;
> $K = 1.37e6;
> $L = 3.69e5;
> $M = 4.7e-1;
>
> while(<STDIN>) {
>   chop;
>
>   ($commsymb,
>    $bigpoint,
>    $longshort,
>    $entry_price,
>    $stoploss_price,
>    $equity)             = split(/,/);
>
> # compute R1
>   if( ($longshort eq "L") || ($longshort eq "l") )
>        { $R1 = ($entry_price - $stoploss_price) * $bigpoint; }
>   else { $R1 = ($stoploss_price - $entry_price) * $bigpoint; }
>   if($R1 < 0.0) { die("\nFATAL ERROR: Somehow R1 became negative\n"); }
>
> # compute A
>   $temp = ($L / $equity);
>   $temp = ($K / $equity) - ($temp * $temp);
>   if($temp <= 0.0) { $B = 0.0; }
>   else { $B = ($J / $equity) + exp($M * log($temp)) ; }
>   $A = 1.0;
>   if($B > $A) { $A = $B; }
>
> # compute N
>   $N = 0.025 * ($equity / $R1) * $A ;
>
> # output the computed figures
>   printf "%-4s %6.0f %-2s %9.4f %9.4f  %9.2f  R1=%7.2f  A=%7.4f
N=%7.4f\n",
> $commsymb, $bigpoint, $longshort, $entry_price,
> $stoploss_price, $equity, $R1, $A, $N ;
> }
>


----------------------------------------------------------------------------
----


>
> --
>    Mark Johnson     Silicon Valley, California     mark@xxxxxxxxxxxx
>
>    "... The world will little note, nor long remember, what we
>     say here..."   -Abraham Lincoln, "The Gettysburg Address"
>