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

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



PureBytes Links

Trading Reference Links

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
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/