Why am I peeking?
Author: sf631
Creation Date: 5/26/2011 3:38 PM
profile picture

sf631

#1
I am pretty certain a change I made to my code is guilty of peeking ahead (my simulation performance just changed dramatically with one change). What I'd like to do is simulate a VWAP style order which is more realistic for the way I trade than an order to execute exactly at the close, open etc...

My exits (and entries for that matter) have always been coded as:
CODE:
Please log in to see this code.


And I've replaced that with a limit order that exits at a pseudo-VWAP price on the next bar (I assume that I make my decision to exit at bar and then execute upon that decision on bar+1 at the VWAP price of bar+1

CODE:
Please log in to see this code.



Here's the way I've defined the calculation of my pseudo-VWAP
CODE:
Please log in to see this code.


Note that I get the same # of trades executing in either case, and I've verified dozens of the VWAP limit trades, all of which seem to be truly within the range of realistic. I'm aware that there are ExitAtPrice and EnterAtPrice methods defined in the community components library, so I suppose I need to resort to those, but if anyone can explain simply why the above isn't valid I'd really appreciate the insight.

Of perhaps this is valid?

profile picture

Eugene

#2
In real life, how can you make the decision to exit today (i.e. bar) while at the same time evaluating the tomorrow's OHLC (i.e. vwap(p.Symbol,bar+1))? This is impossible w/o a crystal ball.

Sorry to rain on your parade but the correct way is to pass "bar" and not "bar+1" to the vwap function.
profile picture

sf631

#3
OK, I'll try that and see if it changes things. Not sure what impact it'll have to pass bar to vwap() which will then peek ahead to the next bar, vs pass bar+1 to a vwap() function that pulls for that (bar+1) bar, but I'll try.

I don't disagree that I'm somehow violating the no-peeking rule, I just can't figure out why. Since I don't trade with MarketOnClose orders in real life, trading ExitAtClose(bar+1) seems wrong too

Thanks
profile picture

Eugene

#4
Just give it a thought: the code implies being able to exit the market tomorrow with a limit order that can take place e.g. at 11 am, knowing tomorrow's closing price of 4 pm beforehand (let alone the high and low prices). Even if you made that decision to exit yesterday or a week ago, it's unreal to know these prices beforehand while tomorrow's bar is not closed.
profile picture

sf631

#5
Ah, I see what's happening. In case anyone else reads with a similar question... When the limit is placed at a price, it will fill at that price *or better*. So, if the open price is less favorable than the VWAP price, the fill will happen at the VWAP (will eventually get there). But if the open price is more favorable than VWAP it'll fill at that better price.

It'd be handy to have a BuyAtVWAP or BuyAtAverage order type in the future to simulate cases where the trade will execute throughout the bar not at the open or the close only. Probably a better simulation of reality for traders concerned about moving the market... Some brokers (not Fidelity) do support this order type on liquid instruments, where they'll guarantee execution at the day's VWAP.

Thanks
profile picture

Cone

#6
If you know what price you want the order to execute, use EnterAtPrice from Community.Components.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).