For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

early order execution prices



  • I ran the tutorial codes with the supplied test data. What could it be that the execution prices for the early orders don't come anywhere near the market prices?

    Starting Portfolio Value: 100000.00
    2000-01-24, Close, 27.09
    2000-01-25, Close, 28.22
    2000-01-25, BUY CREATE, 28.22
    2000-01-26, BUY EXECUTED, Price: 14.19, Cost: 14.19, Comm 0.01
    2000-01-26, Close, 27.53
    2000-01-27, Close, 25.91
    2000-01-27, SELL CREATE, 25.91
    2000-01-28, SELL EXECUTED, Price: 12.88, Cost: 14.19, Comm 0.01
    2000-01-28, OPERATION PROFIT, GROSS -1.31, NET -1.34
    2000-01-28, Close, 23.69
    2000-01-31, Close, 24.98
    2000-02-01, Close, 27.00
    2000-02-02, Close, 27.16
    2000-02-02, BUY CREATE, 27.16
    2000-02-03, BUY EXECUTED, Price: 13.84, Cost: 13.84, Comm 0.01
    2000-02-03, Close, 28.34
    2000-02-04, Close, 28.91
    2000-02-07, Close, 29.97
    2000-02-08, Close, 29.78
    2000-02-09, Close, 29.97
    2000-02-10, Close, 31.16
    2000-02-11, Close, 29.84
    2000-02-14, Close, 31.09
    2000-02-15, Close, 30.69
    2000-02-16, Close, 30.62
    2000-02-17, Close, 30.81
    2000-02-18, Close, 29.28
    2000-02-18, SELL CREATE, 29.28
    2000-02-22, SELL EXECUTED, Price: 14.78, Cost: 13.84, Comm 0.01
    2000-02-22, OPERATION PROFIT, GROSS 0.94, NET 0.91
    2000-02-22, Close, 29.66
    2000-02-22, BUY CREATE, 29.66
    2000-02-23, BUY EXECUTED, Price: 15.05, Cost: 15.05, Comm 0.02
    2000-02-23, Close, 31.53
    2000-02-24, Close, 30.97

    ...

    2000-11-30, BUY CREATE, 26.50
    2000-12-01, BUY EXECUTED, Price: 26.38, Cost: 26.38, Comm 0.03
    2000-12-01, Close, 26.44
    2000-12-04, Close, 28.19
    2000-12-05, Close, 31.50
    2000-12-06, Close, 30.19
    2000-12-07, Close, 28.31
    2000-12-08, Close, 30.06
    2000-12-11, Close, 31.94
    2000-12-12, Close, 30.75
    2000-12-13, Close, 28.38
    2000-12-14, Close, 27.50
    2000-12-14, SELL CREATE, 27.50
    2000-12-15, SELL EXECUTED, Price: 29.44, Cost: 26.38, Comm 0.03
    2000-12-15, OPERATION PROFIT, GROSS 3.06, NET 3.00
    2000-12-15, Close, 28.56
    2000-12-15, BUY CREATE, 28.56
    2000-12-18, BUY EXECUTED, Price: 30.00, Cost: 30.00, Comm 0.03
    2000-12-18, Close, 32.00
    2000-12-19, Close, 30.62
    2000-12-20, Close, 28.50
    2000-12-20, SELL CREATE, 28.50
    2000-12-21, SELL EXECUTED, Price: 27.81, Cost: 30.00, Comm 0.03
    2000-12-21, OPERATION PROFIT, GROSS -2.19, NET -2.25
    2000-12-21, Close, 29.50
    2000-12-21, BUY CREATE, 29.50
    2000-12-22, BUY EXECUTED, Price: 30.38, Cost: 30.38, Comm 0.03
    2000-12-22, Close, 31.88
    2000-12-26, Close, 30.94
    2000-12-27, Close, 30.69
    2000-12-28, Close, 31.06
    2000-12-29, Close, 29.06
    2000-12-29, SELL CREATE, 29.06
    2000-12-29, (MA Period 15) Ending Value 99995.99
    Final Portfolio Value: 99995.99

    Thanks.



  • Check out this thread - https://community.backtrader.com/topic/920/wrong-execution-price-during-the-backtesting

    Possibly you use Yahoo online data, which can be partially adjusted for splits/dividends. Also BUY CREATE event prints close price, BUY EXECUTED event prints next bar open price.