PacktPublishing / Learn-Algorithmic-Trading

Learn Algorithmic Trading, Published by Packt
MIT License
802 stars 302 forks source link

cp5_basic_mean_reversion.py #10

Open liqinglin54951 opened 2 years ago

liqinglin54951 commented 2 years ago

mark the remaining position to market i.e. pnl would be what it would be if we closed at current price

author line 106 : open_pnl += abs(sell_sum_qty - position) * (close_price - buy_sum_price_qty / buy_sum_qty)

should be corrected since:

position -= NUM_SHARES_PER_TRADE # reduce position by the size of this trade sell_sum_qty += NUM_SHARES_PER_TRADE so the remaining position : abs(position) Line 106 : open_pnl += abs(position) (close_price - buy_sum_price_qty / buy_sum_qty) and the author line 111 : open_pnl += abs(buy_sum_qty - position) (sell_sum_price_qty/sell_sum_qty - close_price) also need to be corrected: Line 111 : open_pnl += abs(buy_sum_qty - position) * (sell_sum_price_qty/sell_sum_qty - close_price)

Note: abs(position) = abs(buy_sum_qty-sell_sum_qty)