Back

SetHolding and Portfolio Quantity

Hi, I have a question regarding SetHoldings and Portfolio Quantity. Im not sure if im missing something basic here, but the following code beollow will result in Portfolio["SPY"].Quantity will be 0.           

SetCash(3000);

  

SetHoldings("SPY", 1.0, true);
Log("Active Pos SPY " + Portfolio["SPY"].Quantity);

Logfile: 

2016-02-01 00:00:00 Launching analysis for d7cc9af835c9d21ba2fddd76d4f2cd73 with LEAN Engine v2.2.0.2.733
2016-02-02 00:00:00 Converted OrderID: 1 into a MarketOnOpen order.
2016-02-02 00:00:00 Active Pos SPY 0
2016-08-02 00:00:00 Algorithm Id:(d7cc9af835c9d21ba2fddd76d4f2cd73) completed in 7.57 seconds at 0k data points per second. Processing total of 566 data points.
2016-08-02 00:00:00 Your log was successfully created and can be downloaded from: http://data.quantconnect.com/backtests/24380/356187/d7cc9af835c9d21ba2fddd76d4f2cd73-log.txt
Update Backtest








Please share the complete backtest Martin, its impossible to know from the snippet :)

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.


First time post, misst that you could do that :)

0


In your algorithm, SPY is subscribed with daily resolution. Since OnData is triggered when TradeBars are ready/closed, SetHoldings is called when the market is closed (daily bars are ready when at EOD).

At this scenario, the market order created by SetHoldings is converted into a market on open (market order sent to the exchange as soon as it is opened). Since the algorithm didn't fill any order until next morning, the portfolio does not hold SPY soon after SetHoldings.

If your put a code line to print out SPY quantity every timestep:

public override void OnData(Slice data)
{
Log("Active Pos SPY " + Portfolio["SPY"].Quantity);

/* ... */
}

you will see that the portoflio holds 15 shares of SPY from the 2nd trading day forward.

1

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