Greetings --

Tomasz has added the Mersene Twister algorithm for generation of random
numbers since my book Quantitative Trading Systems was printed.

See the AmiBroker help files for mtrandom for details.

mtrandom is a better algorithm than the one distributed with most language
packages, including C++ and Excel.

Also, download the pdf file from the link "Addendum and Errata" from this
page:
http://www.quantitativetradingsystems.com/book.html
which has an example of using mtrandom.

Thanks,
Howard


On Wed, Jul 7, 2010 at 4:34 AM, Howard B <[email protected]> wrote:

> Greetings --
>
> This is the code being referred to from my book, Quantitative Trading
> Systems.
>
> Thanks,
> Howard
>
>
> //    EnterAtRandom.afl
> //
> //    Entry a position at the close of a random bar.
> //
> //    A random entry for use as a benchmark.
> //
> //    Expect this entry to mirror the buy and hold.
> //    It cannot be profitable taking long positions in
> //    a declining market, or taking short positions
> //    in a rising market.
> //
> //    This code just waits a fixed number of bars to exit.
> //    It can be used to test any of the exit systems.
> //
> //    For market orders, enter and exit Market On Close
> //        with no delay
>
> SetTradeDelays(0,0,0,0);
> BuyPrice = C;
> SellPrice = C;
>
> //    Frequency is the number of entries per year.
> Frequency = Param("Entries per Year",12,1,100,1);
>
> //    Repeatable is a switch.
> //    True (1): the sequence of random numbers will be repeated.
> //    False (0): each sequence is random.
> Repeatable = Param("Repeatable",0,0,1,1);
>
> //    Seed is the number used to start the random sequence
> //    when repeatable sequences are desired.
> Seed = Param("Seed",13331,1,99999,1);
>
> //    Generate a fraction, uniformly distributed
> //    between 0.00000 AND 0.99999.
> NextRandom = IIf(Repeatable,Random(Seed),Random());
>
> Buy = IIf(NextRandom<Frequency/252,1,0);
>
> //    The code for the exit being tested starts here.
> //
> //    HoldBars is the number of bars to wait for exit.
> HoldBars = Param("HoldBars",3,1,100,1);
>
> Sell = BarsSince(Buy)>=HoldBars;
> //    The code for the exit being tested ends here.
>
> //    Remove extra Buy and Sell signals.
>
> Buy = ExRem(Buy,Sell);
> Sell = ExRem(Sell,Buy);
> //Figure 7.5 Enter at Random
>
> /////////////////////////// end of afl ////////////////////////
>
>
> On Wed, Jul 7, 2010 at 1:39 AM, reinsley <[email protected]> wrote:
>
>>
>>
>>
>> Hi,
>>
>> I don't know the last author.
>>
>> Best regards
>>
>> _SECTION_BEGIN("ct1");
>> /*
>>    Coin Toss model , it has nothing to do with Technical OR Fundamental
>> Analysis
>>
>>    It has nothing to do with entry or exit rules.
>>    Here One books profits and losses at a predefined percent.
>>
>>
>>    This Model was Inspired by many authors
>>    ---------------------------------------
>>    a)Victor Sperandeo   :- Methods of Wall Street Master
>>    b)Nasim Taleb         :-   Fooled by Randomness
>>    c)Ed Thorp            :-   #Beat the Market       #Beat the Dealer
>>    d)William Poundstone   :-   Fortune's Formula
>>
>>    thanks for AB codes and concepts by
>>    a)Dimitris Tsokakis
>>    b)Herman van den Bergen
>>    c)Anthony Faragasso
>>    d)Graham Kavanagh
>>    and countless good souls.
>>
>>    Hearty thanks to
>>
>>    "Tomasz Janeczko" for AB Platform.
>>
>>
>>    Disclaimer : any error in code or concept here belongs to me.
>>    This Amibroker Script is for educational purposes only. I cannot
>> guarantee
>> it's accuracy nor take any responsibility for your use of it.  Use at your
>> own
>> risk.
>>
>>
>> */
>> SetOption("InitialEquity", 5000);
>> SetOption("CommissionMode", 2); //2 - $ per trade
>> SetOption("CommissionAmount", 1.35); // commission in BPS per leg
>> SetOption("MarginRequirement", 100);// no margin
>> SetOption("UsePrevBarEquityForPosSizing", 1);
>> SetOption("AllowSameBarExit",1);                           // Sq off
>> Daily
>> SetOption("PriceBoundChecking",0);
>> SetTradeDelays( 0, 0, 0, 0 );
>> *RoundLotSize*=1;                                         //Change this
>> according to your needs [i did it for Nifty].
>>
>> posSizeX = Optimize("posSizeX", 1, 1, 10, 1);
>>
>> winloss = Optimize("winloss", 50, 10, 50, 2);                // Assumed
>> probability of winning, higher the better
>>
>> winPercent = Optimize("winPercent", 1, 0.25, 10, 0.25);        // higher
>> the better
>> lossPercent = winPercent/2;                               
>> //Optimize("lossPercent",
>> 0.5, 0.25, 10, 0.25);    // lower the better
>>
>> //iterations = Optimize("iterations",1,1,20,1);                // to test
>> randomness at different levels, not used in any equation.
>>
>> HitRatio = mtRandomA() < (winloss/100);                      //hit ratio
>>
>>
>> *PositionSize* = -(posSizeX);                               //exposure of
>> capital
>>
>> *Buy* = Day() != Ref(Day(), -1 );                           // trade
>> daily
>> *Sell* = *Buy*;                                             // Sq off
>> Daily
>>
>> *Short*=*Cover*=0;
>>
>> *BuyPrice*=100;  // to make it generic from EURUSD to Hangseng to Bovespa
>>
>> //if you win you get winPercent, if you loose you loose lossPercent
>> *SellPrice*=IIf(HitRatio,*BuyPrice**(1+(winPercent/100)),*BuyPrice**(1
>> -(lossPercent/100))  );
>>
>> Plot(Equity(),"Equity : " , 1,1);
>> RequestTimedRefresh(1);
>>
>> SetChartBkGradientFill( ParamColor("BgTop", *colorWhite*),ParamColor(
>> "BgBottom",*colorViolet*));
>> _SECTION_END();
>>
>>
>>
>>
>> Le 07/07/2010 01:17, spacebass5000 a écrit :
>>
>>
>>
>> wow, how did I miss this... i have read and reread this book many times.
>> thanks for the reminder!!!!!!!
>>
>> --- In [email protected] <amibroker%40yahoogroups.com>,
>> "notanaiqgenius" <notanaiqgen...@...> <notanaiqgen...@...> wrote:
>> >
>> > If you happen to have Howard Bandy's book, Quantitative Trading Systems,
>> you can see page 91-92 for an example of random entries (but not exits).
>> (Sorry, I'm not going to post the code here out of respect for Howard's
>> work.)
>>
>>
>>  
>>
>
>

Reply via email to