2014-10-15 09:40:00 FDN Market $56.604339 USD -17,619 Sell Filled Warning: fill at stale price (10/15/2014 12:00:00 AM America/New_York)
2014-10-15 09:40:00 FDN Market $56.615661 USD 8,810 Buy Filled Warning: fill at stale price (10/15/2014 12:00:00 AM America/New_York)
I basically have 2+ pages of this churning, and algo fails out at 10000 trades. Not exactly what I'm wanting.
Here's the trading/insight code. I'm looking for a more robust way to limit trading. Once a day at open+ 10 mins is my goal,
not churning in a few seconds.
Schedule.On(DateRules.EveryDay(), TimeRules.AfterMarketOpen("XLK", 10), ScheduledUpdate);
//
//Update and provide insights
public void ScheduledUpdate()
{
foreach (var symbolData in _symbolDataBySymbol.Values)
{
if (symbolData.Fast.IsReady && symbolData.Slow.IsReady)
{
var insightPeriod = _resolution.ToTimeSpan().Multiply(_predictionInterval); //1 day
if (symbolData.FastIsOverSlow)
{
if (symbolData.Slow > symbolData.Fast) fast and slow moving avg.
{
EmitInsights(Insight.Price(symbolData.Symbol, insightPeriod, InsightDirection.Down));
}
}
else if (symbolData.SlowIsOverFast)
{
if (symbolData.Fast > symbolData.Slow)
{
EmitInsights(Insight.Price(symbolData.Symbol, insightPeriod, InsightDirection.Up));
}
}
}
symbolData.FastIsOverSlow = symbolData.Fast > symbolData.Slow;
}
}
Jeff Ward
I agree. I do not understand the trading algorithm used to test the insights. It does some crazy looking things sometimes.
Alexandre Catarino
Hi Tim Bohmann,
The code snippet doesn't give us enough information to access the issue.
What's the data resolution (it looks like Daily because of the stale price message)?
Could you please share a backtest?
Jeff Ward
Alexandre, that isn't the problem. With Alphas, you never issue any trades. You only emit insights about whether you think the equity will go up, down, or flat. This is because an institution will use your ideas to implement an actual trading strategy. We don't get to tell institutions how to trade or what risk management to use. I see the same thing with my alphas. On a single up insight, the framework will make a buy order, then sell 2 shares, then 1, then buy 7 more, then sell some more all in rapid succession, ramping up costs and doing complete nonsense. It's a problem with the framework itself since we aren't issuing any trades.
Jeff Ward
Check it out. This simply emits an up insight every day at the market open. At 9:30 on the first day,
Buy 311 SPY
Sell -22 SPY
Sell -19 SPY
Sell -17 SPY
Sell -15 SPY
What?! It goes on like this forever. All I'm saying is up every day.
Alexandre Catarino
Hi Jeff Ward ,
It is up every day:
Holds Buy 311 SPY 311 Sell -22 SPY 289 Sell -19 SPY 270 Sell -17 SPY 253 Sell -15 SPY 238
The algorithm is using EqualWeightingPortfolioConstructionModel. When this PCM receives a new insight (or an existing expiry expires or a security is removed from the universe), it rebalances the portfolio. In the case above, the market is going against the insight price direction prediction, therefore the algorithm needs to sell stocks because of the lower portfolio value.
In order to confirm it is up, we can use:
def ResetTrades(self): for kvp in self.Portfolio: if not kvp.Value.IsLong: self.Log(f'{kvp.Key} is not long on {self.Time}') for symbol, assetData in self.universe.items(): self.EmitInsights(Insight.Price(symbol, timedelta(2), InsightDirection.Up))
Jeff Ward
Thanks, that explains a lot. I guess the follow-up question would be is there a sensible way to backtest? This seems crazy. I can see how this makes sense for alphas that produce very few insights, but for the competition we should be producing at least one per day. This would result in constant rebalancing and incurring tons of fees. To me, it makes sense to do something like x% of portfolio is the initial position (also not constantly resizing as the portfolio resizes). I guess at that point you are writing a trading algorithm, and not an alpha. Actually, glancing at the EqualWeightingPortfolioConstructionModel code, it would be pretty easy to whip up a PortfolioConstructionModel that does this. I'm not sure if that is legal for backtesting in the competition.
Tim Bohmann
Jeff, you nailed it, really. I can't submit a backtest for only a few months when 5 years is required. I get way too many trades in one day unless I manually limit trades to one per day per symbol, using setholdings and liquidate.
It works like a charm. If I go back to using EmitInsights, it churns like crazy. Just as an aside, if I decide to post my algo for the market, instead of the competition, do the same rules apply?
Also, to Jeff's point, can we write our own ConstructionModel code for the competition. At one point, I was using emitinsights and doing setholding and liquidate together. Is this allowed for the competition?
Some clarification would be good at this point.
Tim Bohmann
I think a quick tutorial or some ideas about stopping this action would be beneficial to all. I feel like it might be happening to alot of people that are trying to submit competetion entries. 10000 trades in 20 days is.
Time Symbol Price Quantity Type Status Value Tag 2014-10-18T04:00:00Z SVXY 110.551956 4482 Market On Open Filled 495493.8668 2014-10-18T04:00:00Z TQQQ 11.88596666 41857 Market On Open Filled 497510.9066 2014-10-20T13:33:00Z SVXY 111.248874 -1494 Market Filled -166205.8178 Warning: fill at stale price (10/18/2014 12:00:00 AM America/New_York) 2014-10-20T13:33:00Z TQQQ 11.91180849 -13951 Market Filled -166181.6402 Warning: fill at stale price (10/18/2014 12:00:00 AM America/New_York) 2014-10-20T13:33:00Z SPY 170.4156548 1951 Market Filled 332480.9424 2014-10-20T13:34:00Z SVXY 111.248874 -1 Market Filled -111.248874 Warning: fill at stale price (10/18/2014 12:00:00 AM America/New_York) 2014-10-20T13:34:00Z TQQQ 11.91180849 -6 Market Filled -71.47085094 Warning: fill at stale price (10/18/2014 12:00:00 AM America/New_York) 2014-10-20T13:35:00Z SPY 170.6169462 -1951 Market Filled -332873.6621 2014-10-20T13:35:00Z SVXY 111.271126 1496 Market Filled 166461.6045 Warning: fill at stale price (10/18/2014 12:00:00 AM America/New_York) 2014-10-20T13:35:00Z TQQQ 11.91419109 13967 Market Filled 166405.507 Warning: fill at stale price (10/18/2014 12:00:00 AM America/New_York) 2014-10-20T13:36:00Z TQQQ 11.91180849 -4 Market Filled -47.64723396 Warning: fill at stale price (10/18/2014 12:00:00 AM America/New_York) 2014-10-20T13:37:00Z SVXY 111.248874 -1495 Market Filled -166317.0666 Warning: fill at stale price (10/18/2014 12:00:00 AM America/New_York) 2014-10-20T13:37:00Z TQQQ 11.91180849 -13953 Market Filled -166205.4639 Warning: fill at stale price (10/18/2014 12:00:00 AM America/New_York) 2014-10-20T13:37:00Z SPY 170.551473 1950 Market Filled 332575.3723 2014-10-20T13:38:00Z SPY 170.7165263 -1950 Market Filled -332897.2264 2014-10-20T13:38:00Z SVXY 111.271126 1496 Market Filled 166461.6045 Warning: fill at stale price (10/18/2014 12:00:00 AM America/New_York) 2014-10-20T13:38:00Z TQQQ 11.91419109 13960 Market Filled 166322.1076 Warning: fill at stale price (10/18/2014 12:00:00 AM America/New_York) 2014-10-20T13:39:00Z SVXY 111.248874 -1495 Market Filled -166317.0666 Warning: fill at stale price (10/18/2014 12:00:00 AM America/New_York) 2014-10-20T13:39:00Z TQQQ 11.91180849 -13957 Market Filled -166253.1111 Warning: fill at stale price (10/18/2014 12:00:00 AM America/New_York) 2014-10-20T13:39:00Z SPY 170.7144549 1948 Market Filled 332551.7581 2014-10-20T13:40:00Z SPY 170.9066338 -1948 Market Filled -332926.1227 2014-10-20T13:40:00Z TQQQ 11.91419109 13963 Market Filled 166357.8502 Warning: fill at stale price (10/18/2014 12:00:00 AM America/New_York) 2014-10-20T13:40:00Z SVXY 111.271126 1495 Market Filled 166350.3334 Warning: fill at stale price (10/18/2014 12:00:00 AM America/New_York)
I'm sure that's not what an institution wants to see. Just guessing. Also, it's trading my Benchmark, which I don't think should be happening.
I like the theory behind the algorithm that I'm using, and it's solid. I just need some way to fix the churn.
Jared Broad
Use the classic style algorithm Tim and emit trades manually. You'll see below each universe competition thread there are two algorithms shared -- a framework and a classic. Use the classic if the framework doesn't suit your needs. With the classic, you control the trades and signals emitted manually.
The EWPCM is doing exactly as instructed, the rebalance period is just too frequent for your preferences. Rather than debate this just switch to manual/classic algorithms and do what you want.
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.
Tim Bohmann
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.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!