Back

Inconsistent order fills

Is anyone having trouble with inconsistent order fills when backtesting? Ill have a string of orders that trade only one share at a time for a series of trades. I believe I have my orders set for market so this is odd  

Update Backtest








Hi John; the best way to get assistance is to attach an algorithm to any requests for help. 99% of the time its an issue with the strategy so attaching the actual code is the only way to determine the fix.

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.


public class ScalpingAlgorithm : QCAlgorithm
{
private WilliamsFractals _wf;


private string symbol = "SPXL";

public override void Initialize()
{
SetStartDate(2016, 4, 1);
SetEndDate(2016, 6, 5);

SetCash(12000);

AddSecurity(SecurityType.Equity, symbol, Resolution.Minute);

Securities[symbol].FeeModel = new ConstantFeeModel(1.0m);

_wf = new WilliamsFractals();

var fiveMinuteConsolidator= new TradeBarConsolidator(TimeSpan.FromMinutes(35));

fiveMinuteConsolidator.DataConsolidated += FiveMinuteBarHandler;

SubscriptionManager.AddConsolidator(symbol, fiveMinuteConsolidator);
}

public void FiveMinuteBarHandler(object sender, TradeBar data)
{
_wf.Update(data);

if (_wf.IsReady)
{
if (data.Price >= _wf.BarryUp)
{
SetHoldings(symbol, -1.0m);
}
else if (data.Price <= _wf.BarryDown)
{
SetHoldings(symbol, 1.0m);
}
}
}
}
}

 

0


Hi John,

In your algorithm, you are using the SetHoldings helper:
"SetHoldings sets a fraction of unlevered equity. e.g. If you have 2x available leverage, and SetHoldings to 1.0 the algorithm will use 1.0 of your available buying power."

// Set fixed percentages (25%) of known tickers:
SetHoldings("IBM", 0.25);
SetHoldings("GOOG", 0.25);
SetHoldings("AAPL", 0.25);
SetHoldings("MSFT", 0.25);

// Or set portfolio to equal weighting of all securities:
var weighting = 1m / Securities.Count;
foreach(var security in Securities.Values) {
SetHoldings(security.Symbol, weighting);
}

Back to your algorithm:
When you call SetHoldings("SPXL", 1m), the algorithm will calculate how many shares of SPXL you can buy using 100% of your cash and send a market order.

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.


Im not sure if you are able to see trade history, but there are many times in this back test where its not executing properly. 5-24 and 5-25 are an example of days where this seems to happen.

0


Hi John,

I have checked the orders and they are ok.
The algorithm starts with $30000. First, it sells 179 shares of SPXL at $83.7 (= $14892.30, about 50% of $30000), then it rebalances on every OnData event to keep the 50% of cash. Since it is losing money, we are buying shares.
On April 4th 2016 at 5:26:00 pm, we are shorting 175 shares and we get a buy signal. The algorithm then buys 350 shares of SPXL at $84.88 and now we hold 175 shares of SPXL, then the rebalancing process continues until we get another sell signal.

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 think I see what you are saying, since the first trade is losing moeny the program buys back 2 shares, then one, and then one more share to keep the account in balance?

0

Hi John,

Yes, precisely.
When the trade is losing money, the absolute quantity of the traded asset descreases. Otherwise, it increases.

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.


Thanks for the help Alex! I'm new to this so I have a long way to be before I have a grasp on everything.

Do you have any suggestions that might clean up the strategy? I've noticed this works well for some streches of months and not so much in others

0


Oh, that's an easy one John.
Here are a few suggestions:

1. Write a letter to all investors asking them to trade the way you like.

2. Find a billionaire quant who knows the answer and will be happy to share.

3. Ask Alex again because surely he knows the answer but for some reason decided to have a job.

And I can say this only because I'm also one of wannabe quants who walks into a room full of wannabe quants and asks 'excuse me, how do I make sh..load or money really quick?'" :-)

I'm new here, btw.
 

0

Kon you should really think about changing your user name to skankHunt42. 

0

To clarify my previuos question, I'm not asking for the secerts to anyones trading strategy.

0

Hi John,

This strategy is on a new phase now: does it trade well other instruments/markets?

To clean it up, diversification may be the answer you are looking for.

When an algorithm trades a single instrument, it occurs on security risk and market risk. When an algorithm trades a basket of instruments, security risk is mitigated. Finally, when an algorithm trades a basket of instruments of different markets, both security and market risk are mitigated.

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