Back

Werid Error with multiple stock orders

I keep getting the following error:

Algorithm Error: Error in orders - Order price ($198.73) too far from reality ($198.66).

OnTradeBar code is:


decimal min_limit = 1.02m;
foreach(string security in mySecurities){
if (securityData.ContainsKey(security)){
if (Portfolio[security].HoldStock){
if (securityData[security].high / Portfolio[security].AveragePrice >= min_limit ||
Portfolio[security].AveragePrice / securityData[security].high >= min_limit){
Order(security, -100); //symbol, quantity
}
} else {
Order(security, 100);
}
}

}


mySecurities is defined as an array of strings:

private string[] mySecurities = {"IBM"} // etc etc

The error only occurs when mySecurities has more than one item, eg {"IBM", "AIG", "AXP"}

It seems random and when it occurs the simulation halts.

Any ideas what is going on?
Cheers,
Ryan
Update Backtest








Good catch Ryan, there's something going on in the Portfolio / Order processing. We'll fix it today and let you know. We just did a rewrite of the core of the program so its probably a little glitchy.
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.


I forgot to mention that it was in Series mode not parallel.

I reran the code this evening with mySecurities = {"IBM", "AXP"} and did not encounter the error. However, I noticed that it was buying too many shares for the amount of cash available.

Both IBM and AXP were purchased with maximum of 0.8 Portfolio.Cash (~$24000), however I would expect this to diminish after the first purchase. Ie if IBM purchased first ($24000) then the next purchase would be 0.8 * $6000 (if Portfolio.Cash started at 30k), so and so forth. It would seem that in its current state it can exceed actual Cash limits.

On the very first purchase a total of $48k was spent but it initialized with 30k. Does that make sense?
0

Oops I spoke to soon. Just got the error again.
0

Thank you Ryan, working on it now -- I realized maybe this was unintentional as well: AveragePrice in the Portfolio context means Average holdings purchase price.

So if I buy at 100 @ $1, 10 @ $2 and 1 @ $3 the average per stock is $1.10

Sorry we'll finish the documentation as soon as possible :)
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.


Fixed a few things:
1. Removed ability to place orders when there was no data for the stock
2. Fixed the portfolio bug where you could buy more than cash available.
3. Fixed end of day liquidation bug where it wouldn't liquidate all stocks
4. Fixed the "Price too far from reality" bug!

Theres still a few more things we're working on so it will be slow until 8pm of 12th April. Thanks for highlighting this and your patience while we're in beta!
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.


Thank you @Ryan Hill, just to follow up -- we fixed this bug. There was an error in fee models which actually added to profits in certain circumstances!
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