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

Re: [amibroker] How do I backtest placing a restricted number of limit orders each night?



PureBytes Links

Trading Reference Links

Morning Ed,
 
My problem when using the Backtester and in general a Backtester based upon portfolio result is the fact that in the real world an investor will have a portfolio with
let's day 20 stocks. Therefore when the portfolio has been filled, all other BUY signals
will be lost until you've a SELL signal. For this reason when doing a Backtest
I always do an Explore analysis of all signals. In general what I get is something like
200 Transactions from the Backtester and 1.000 Transactions from the Explore analysis.
What makes things worse, I often get a RAR from the backtest of let's say 25% with
75% of the signals being winners. When looking to the Explore analysis of all the
signals I only get something like 35% of winners. Therefore the result coming from
the Backtester must be pure luck. The backtester 'randomly' chooses the signals to
fill the portfolio. I have no idea how to solve this problem ...
 
Regards, Ton.
 
 
 
----- Original Message -----
Sent: Sunday, August 26, 2007 8:45 PM
Subject: Re: [amibroker] How do I backtest placing a restricted number of limit orders each night?

hi,
 
the way you set it up it shoudl not be possible. However, what can happen is that the backtester finds exits for the next day and immediatelly fills them with new positions. So you need to make sure that you first exit your positions and tell the backtester to enter only on the next bar. This is usually the problem.  There are several ways to achieve this. Maybe you will get a more satisfactory result when you set settradedelays(1,1,1,1).
 
I use setttradedelays(0,0,0,0) but I make sure that the trade is entered 1 bar after the signal (same with the exits),
 
Ed
 
 
 
 
----- Original Message -----
Sent: Friday, August 24, 2007 11:37 AM
Subject: [amibroker] How do I backtest placing a restricted number of limit orders each night?

Can anyone help me model the following scenario?

- Assume a portfolio is allowed to consist of some fixed number
of "slots" with equity equally divided among them (e.g. 10 slots at
10% of equity).
- Check for setup criteria at close of each day.
- Place next day limit buy orders for as many unfilled slots as are
currently available (e.g. if already have 2 fills after day 1, then
there are only 10 - 2 = 8 slots remaining for day 2, etc.).
- Buy orders are prioritized by a calculated value.

My problem is that if I receive a setup for more symbols than I have
available slots (e.g. receive 20 setups but only have 8 available
slots), my script will try to fill all 8 slots from the 20
candidates, and the portfolio manager will correctly prevent me from
having more positions than allowed (e.g. no more than 10).

However, in reality, I will only have placed as many limit orders as
I have available slots (e.g. 8 limit orders when 8 available slots,
not limit orders for all 20 candidates, since I only have funds to
cover placing 8 orders).

What is happening is that my script is filling orders that I would
not have placed! I need a way to indicate that despite 20 setups,
only 8 limit orders were placed.

Following is some script snippets.

/*
* Assume an initial purse and brokerage fees ($0.01/share)
*/
SetOption("InitialEquity", 50000);
SetOption("CommissionMode", 3);
SetOption("CommissionAmount", 0.01);

/*
* Carry fixed number of positions, dividing 100% of Equity between
* them (based on previous bar's closing).
*/
PositionSize = -100/10; // Each position is 10% of equity

SetOption("MaxOpenPositions", 10); // No more than 10 positions
SetOption("UsePrevBarEquityForPosSizing", True);

/*
* We recognize the sale signal at the close of a bar and execute the
* sale at the open of the next one, delay sale by 1 day.
*/
SetTradeDelays(0, 1, 0, 0);

/*
* Trigger a Buy signal when previous bar meets the setup
* requirements AND this bar's Low has dropped to less than a fixed
* percentage below the previous bar's close. This emulates having
* placed a limit order the night before after having seen the signal
* on that day's close.
*/
setup = ... // Some position entry logic.
PositionScore = ... // Some prioritization logic.

BuyPrice = Ref(Close, -1) * 0.95;
Buy = Ref(setup, -1) AND Low <= BuyPrice; // Problem here!!!

Sell = ... // Some sell logic.

As indicated in my earlier comments. The problem is that in reality I
will not actually have placed orders for all candidates, but rather
only for as many as there are available slots (e.g. 8). However, the
script will attempt to fill the available slots based on all
candidates (e.g. 20).

How can I restrict the Buy assignment to only apply to the top X of Y
candidates based on priority (e.g. top 8 of 20 in example above).

Thanks in advance.

__._,_.___

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___