-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'Purity Test' unexpected results / flawed expectations #83
Comments
Apologies for the delayed response. I much appreciate your close inspection!
Seems to be due to these lines in backtesting.py/backtesting/backtesting.py Lines 699 to 702 in 1715c91
I think the "+1 to have at least two entries available" is there as a simple workaround to have "previous close" certainly accessible: backtesting.py/backtesting/backtesting.py Line 484 in 1715c91
The dotted lines indeed mark the duration of trades.
In my slightly updated branch (force-pushed), 17 trades are closed. At the end, the remaining two trades and three orders are:
You can dive into trades details by accessing
|
Hi Again! This time, its my turn to apologise for my response time - as you can probably now tell, the amount of time I get to spend doing the things I WANT to do is highly variable 😉 Thanks muchly for the explanation on why that trade wasn't getting picked up on the first candle - that 'warm up' period seems fair enough. Mostly clear for now except one thing - in that dataframe at the end of your reply, why is the EntryPrice for rows indexed 1-7 all set at 2.2545? My expectation on all those trades would be that the EntryPrice was one dollar less than the ExitPrice at dollar increments, much like the sell orders but in reverse or course. This means that I'm making more profit than I'd expect and may explain why some of the final figures coming out in the summary don't look as 'round' as I was expecting. One final ponderance on the resultant chart: would it be at all possible to have mouseover information showing the trades executed on those dotted lines? I only ask because I instinctively mouse over them to see more detail but don't get any 😜 I had a quick look at Bokeh documentation and couldn't see obviously how to do this, but that's literally my first look at Bokeh. If you point me in the right direction, I'm happy to look into doing that. |
Yeah, busy year for everyone. 😃
All the orders are placed in advance in
Does the tooltip over triangles in the PL chart, aligned with dotted lines' ends, maybe do for you? backtesting.py/backtesting/_plotting.py Lines 373 to 399 in ff97188
Could add a few more fields like EntryTime and Duration. 🤔 |
Ah, okay - I just looked up the textbook definition of a limit order and that seems right: instructs your broker to fill your buy or sell order at a specific price or better. I gather that's the or better part. It raises a question with my broker as to why they fill a limit order only ever at the exact price I request - rather than what I'm seeing as the textbook definition. So I just tried changing the code to place a stop limit order in stead and that produced the set of trades I was originally expecting:
Ahh yes they work fine, thankyou! That should be okay and will be interesting to see how the chart looks when we start testing it with 1 minute candles with multiple trades per minute.
Potentially some additional info in there would be handy, duration yes, perhaps EntryPrice, ExitPrice, PnL? Or maybe there could be an option to simply include a linked DataTable which seems to automatically synchronise click events between plot and table? In a little while, I hope to test backtesting.py using some real world tick data (rolled up to OHLC of course) and real world trades and see how closely backtesting.py reproduces how we've actually seen our trades pan out! 👍 💪 😄 |
@kernc unless you disagree, I figure this issue can be closed? If there are any feature suggestions you'd like me to write up as a result of the discussion here, I'm happy to write them up. I may even attempt a few myself with time! |
As I mentioned in #47 , I've been beginning by conducting some 'purity tests' on that pull request.
Note that I have disabled FIFO by commenting out the lines I referred to earlier on in the comments on that PR.
Expected Behavior
It may be my expectations are flawed, but that is part of this test 😜
Generally speaking my expectations are that with a set of 20 orders already placed (in the
init()
function) and one oscillation of the market, all orders should result in positions being taken and take profit ... ending with a neat little bow on top.I'm also expecting that the numbers that result from
print(output)
somewhat reveal the overly simple and pure scenario that preceded it - with a lot of figures that may have even numbers and numbers with relatively clear relationships to one another.The code:
That should place the following trade orders before the first OHLC is processed:
The data being used for market movements is:
Actual Behavior
Zip file of the chart produced:
PureSimple.zip
This is the output that is printed:
Steps to Reproduce
Additional info
The text was updated successfully, but these errors were encountered: