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

Profit/Loss Calculation



  • Hello,

    I am using backtrader on OHLC data that I resampled using every 100 trades. When I run my strategy with a bracket order, I get a strange profit result. The price and lot size look correct, but the actual cash value in my account doesn't match. I think this might have to do with the timeframe since I am not using a standard timeframe, but I can't find in the documentation where I can correct for the timeframe.

    If I buy 6 shares at $144.88 ($869.28) and sell 6 shares at $147.78 ($886.68) shouldn't the profit be $17.40? But the cash account says there is a profit of $0.06.

    I really appreciate any help you can offer! I am showing two examples of my logs bellow. The second one is even more strange since it shows the profit being negative.

    Starting Portfolio Value: 100000.00
    --------------------------------  NOTIFY ORDER  --------------------------------
    AutoOrderedDict() Order Accepted
    2019-01-04, Status 2: Ref: 1, Size: 6, Price: 144.88
    --------------------------------  NOTIFY ORDER  --------------------------------
    AutoOrderedDict() Order Accepted
    2019-01-04, Status 2: Ref: 2, Size: -6, Price: 147.78
    --------------------------------  NOTIFY ORDER  --------------------------------
    AutoOrderedDict() Order Accepted
    2019-01-04, Status 2: Ref: 3, Size: -6, Price: 144.45
    --------------------------------  NOTIFY ORDER  --------------------------------
    AutoOrderedDict() Order Completed
    2019-01-04, Status 4: Ref: 1, Size: 6, Price: 144.88
    Created: 2019-01-04 14:40:10.550929 Price: 144.88 Size: 6
    --------------------------------------------------------------------------------
    --------------------------------  NOTIFY ORDER  --------------------------------
    AutoOrderedDict() Order Completed
    2019-01-04, Status 4: Ref: 2, Size: -6, Price: 147.78
    Created: 2019-01-04 14:40:10.550929 Price: 147.78 Size: -6
    --------------------------------------------------------------------------------
    --------------------------------  NOTIFY ORDER  --------------------------------
    AutoOrderedDict() Order Canceled
    2019-01-04, Status 5: Ref: 3, Size: -6, Price: 144.45
    --------------------------------  NOTIFY TRADE  --------------------------------
    2019-01-04 14:40:12.187734, Close Price: 144.88, Profit, Gross 0.06, Net 0.06
    --------------------------------------------------------------------------------
    --------------------------------  NOTIFY ORDER  --------------------------------
    AutoOrderedDict() Order Accepted
    2019-01-04, Status 2: Ref: 4, Size: 6, Price: 144.9499
    --------------------------------  NOTIFY ORDER  --------------------------------
    AutoOrderedDict() Order Accepted
    2019-01-04, Status 2: Ref: 5, Size: -6, Price: 147.85
    --------------------------------  NOTIFY ORDER  --------------------------------
    AutoOrderedDict() Order Accepted
    2019-01-04, Status 2: Ref: 6, Size: -6, Price: 144.52
    --------------------------------  NOTIFY ORDER  --------------------------------
    AutoOrderedDict() Order Completed
    2019-01-04, Status 4: Ref: 4, Size: 6, Price: 144.9499
    Created: 2019-01-04 14:50:04.968234 Price: 144.9499 Size: 6
    --------------------------------------------------------------------------------
    --------------------------------  NOTIFY ORDER  --------------------------------
    AutoOrderedDict() Order Completed
    2019-01-04, Status 4: Ref: 5, Size: -6, Price: 147.85
    Created: 2019-01-04 14:50:04.968234 Price: 147.85 Size: -6
    --------------------------------------------------------------------------------
    --------------------------------  NOTIFY ORDER  --------------------------------
    AutoOrderedDict() Order Canceled
    2019-01-04, Status 5: Ref: 6, Size: -6, Price: 144.52
    --------------------------------  NOTIFY TRADE  --------------------------------
    2019-01-04 14:50:05.824677, Close Price: 144.9499, Profit, Gross -0.09, Net -0.09
    --------------------------------------------------------------------------------
    --------------------------------  NOTIFY ORDER  --------------------------------
    AutoOrderedDict() Order Accepted
    2019-01-04, Status 2: Ref: 7, Size: 6, Price: 145.15
    --------------------------------  NOTIFY ORDER  --------------------------------
    AutoOrderedDict() Order Accepted
    2019-01-04, Status 2: Ref: 8, Size: -6, Price: 148.05
    --------------------------------  NOTIFY ORDER  --------------------------------
    AutoOrderedDict() Order Accepted
    2019-01-04, Status 2: Ref: 9, Size: -6, Price: 144.71
    --------------------------------  NOTIFY ORDER  --------------------------------
    AutoOrderedDict() Order Completed
    2019-01-04, Status 4: Ref: 7, Size: 6, Price: 145.15
    Created: 2019-01-04 14:59:01.293961 Price: 145.15 Size: 6
    --------------------------------------------------------------------------------
    --------------------------------  NOTIFY ORDER  --------------------------------
    AutoOrderedDict() Order Completed
    2019-01-04, Status 4: Ref: 8, Size: -6, Price: 148.05
    Created: 2019-01-04 14:59:01.293961 Price: 148.05 Size: -6
    --------------------------------------------------------------------------------
    --------------------------------  NOTIFY ORDER  --------------------------------
    AutoOrderedDict() Order Canceled
    2019-01-04, Status 5: Ref: 9, Size: -6, Price: 144.71
    --------------------------------  NOTIFY TRADE  --------------------------------
    2019-01-04 14:59:03.591464, Close Price: 145.15, Profit, Gross 0.0, Net 0.0
    --------------------------------------------------------------------------------
    Cash: 99999.97	Portfolio: 99999.97                    
    



Log in to reply
 

});