Tutorials icon indicating copy to clipboard operation
Tutorials copied to clipboard

Copula pairs-trading algorithm needs margin requirement control logic

Open simonsonjack opened this issue 7 years ago • 0 comments

Expected Behavior

The algorithm should place trades only when the account has enough cash to places both orders (i.e., long order for one asset and short order for the second asset).

Actual Behavior

The algorithm will place an order for one of the assets but not the other if it doesn't meet proper margin requirements. This leads to portfolio having one long or one short position and it won't trade again once this is established, resulting in imbalanced holdings and the strategy will fail to execute properly for the remainder of the backtesting period.

Potential Solution

Add logic in OnData() method to check for margin requirements and only allow orders to be placed if the account can afford both trades. I have tried to test this but the result is that the algorithm places only a handful of trades rather than the anticipated several hundred (see the link to the test algorithm below). Proper controls should allow for significant trading volume but only when both trades can be afforded.

Reproducing the Problem

Running the copula pairs trading algorithm in the QC Strategy Library will reproduce this problem. See the algorithm at the link below.

https://www.quantconnect.com/tutorials/strategy-library/pairs-trading-copula-vs-cointegration

Checklist

  • [x] I have completely filled out this template
  • [x] I have confirmed that this issue exists on the current master branch
  • [x] I have confirmed that this is not a duplicate issue by searching issues
  • [x] I have provided detailed steps to reproduce the issue

simonsonjack avatar Jan 18 '19 17:01 simonsonjack