trophy

Long Only, ETF Alpha Streams Competition with $27,500 Prize Pool

Back

How to check current position in futures

I am using the following code to see if I am long or short in a futures trade for "NQ":

def _in_long_position(self):
return (self.Portfolio["NQ"].Quantity > 0)

def _in_short_position(self):
return (self.Portfolio["NQ"].Quantity < 0)

def _is_flat(self):
return (self.Portfolio["NQ"].Quantity == 0)

However, I am getting the following error: Runtime Error: Exception : This asset symbol ( ) was not found in your security list.

When trading futures, we trade a specific contract (like NQH19). Which symbol are we supposed to use, "NQ" or "NQH19" (obtained from self.front_contract.Symbol)? Or is teh symbol really "/NQ" or somthing like that?

Update Backtest







0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hi Marc,

I would suggest that you use the specific contract symbol, but you could also filter self.Portfolio.Keys for all contracts prefixed with "NQ" if you don't know the specific ones. Additionally, you can use the IsLong and IsShort attributes for securities to check the direction of your positions (self.Securities[symbol].Invested can also replace the last check you've written above -- you can read more about these here).

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed