Lean icon indicating copy to clipboard operation
Lean copied to clipboard

`CalculateOrderQuantity` doesn't work for Equities on cash account

Open DerekMelchin opened this issue 3 years ago • 0 comments

Expected Behavior

We can call CalculateOrderQuantity with an Equity Symbol when we have a cash account.

Actual Behavior

We get the following error message:

Backtest Handled Error: Unable to compute order quantity of SPY. Reason: The security type must be SecurityType.Crypto or SecurityType.Forex. Returning null.

Potential Solution

N/A

Reproducing the Problem

Run this backtest

class DeterminedAsparagusBison(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 11, 17)
        self.SetCash(100000) 
        self.SetBrokerageModel(BrokerageName.QuantConnectBrokerage, AccountType.Cash)
        self.symbol = self.AddEquity("SPY", Resolution.Daily).Symbol

    def OnData(self, data: Slice):
        quantity = self.CalculateOrderQuantity(self.symbol, 1)
        self.Quit(f"Quantity: {quantity}")

System Information

QC Cloud

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

DerekMelchin avatar Jul 06 '22 17:07 DerekMelchin