Hi
Twice I have seen recommendations stating do this trade now on this stock as this trade was successful x number of times over the previous couple of months. This happens all the time on toggle.ai and on the 'powerX stratergy' website. So that would be an interesting concept to code out
The ideas is
- Get a universe of stocks, filter the universe down by checking on which stocks the stratergy was successful on over the previous year.
- Open trades on these stocks using the stratergy.
- Repeat
I'm not sure how one would filter the universe, I think it would have to be by looping over arrays and with simple stratergy rules and just counting the number of wins vs the number of losses.
Maybe the ‘Repeat’ can happen when an open trade closes or weekly / monthly.
Do you know of any algo that already uses this structure? I look forward to testing this structure.
Fred Painchaud
Hi Newoptionz,
“do this trade now on this stock as this trade was successful x number of times over the previous couple of months”
Would you please define “this trade”?
“Get a universe of stocks, filter the universe down by checking on which stocks the stratergy was successful on over the previous year”
Would you please define “the strategy” (terms used in the above but also in many places afterwards in your text)?
Fred
Newoptionz
Fred Painchaud will do by tomorrow
Newoptionz
Fred Painchaud, well we can use any system, the powerX system uses
slow Stochastic %K (14,3,13),
RSI (7), and MACD (12,26,9)
for position size it uses ADR (7 days) , typically risking 2% of the account, with profit target of ADR*3 and stop loss of ADR*1.5
Go long when
Go short when
So they present a list of stocks that were profitable with this system over the last 2yrs and then say, choose a few of these stocks and trade the powerx system on them. One can do this every day so there is always a new list to choose from.
So I think that would be great idea to test, is this a valid way to pick stocks and is it successful. I think at least it does show stocks that seem to follow that pattern.
So the goal is to make a universe of stocks that trade at least 500K per day and that have been successful using this system over the last two years, and then trade them going forward using the system. When there is space for new trades, or weekly/monthly redo the check to bring up a new universe and then enter new trades and repeat. That is the idea.
I'm off to hosiptal tomorrow for a small procedure and will work towards this when I am well enough again. Thanks
Fred Painchaud
I see yes.
I don't see why it would not “work”. By that I mean:
1- The second portion of the algo which simply trades a Universe based on some strategy, being PowerX or any other, is not, as you know, something new, so that's all right.
2- The first portion of the algo which makes Universe Selection based on which assets were profitable in the past according to the strategy used in the second portion, has been seen in the past, but, of course, the difficulty with that part usually is always that to know which assets have been profitable in the past, you need to backtest their data with the strategy, which means of lot of backtests on a lot of data, which, to top it all, needs to be kept up to date as time goes by. The novelty here is that you are going to use a third party to get that data - that crunching is going to be done for you.
So yes, it will certainly help your Universe Selection, when everything goes fine. However, I am saying when everything goes fine because of course, your Universe Selection will be highly correlated with your strategy, so when your strategy is no longer profitable, for whatever reason, on the type of assets you trade, your Universe Selection won't help you anymore potentially bring some diversification which could help, in theory.
Do update on your progress.
And good luck with your procedure.
Fred
Adam W
That's an interesting idea. One way to implement something like this may be to use a `ScheduledUniverseSelectionModel` that's run periodically (say, monthly). Inside that function, you can do a `History` request, simulate the performance of the strategy, then return those symbols.
For example (in pseudo-code),
The tricky part here is that if the backtest performance is poor, it is hard to tell whether it is the strategy itself or the universe selection logic. For example, let's say in `SimulateStrategyPerformance` your “strategy” was to simply assign a vector of random portfolio weights every month to S&P 500 components. Then sure each month you get a list of the best historically performing symbols under the strategy, but the actual algorithm's performance will be poor.
Fred Painchaud
I believe that running any non-trivial strategy, calling history on each symbol to top it up, on each symbol of a Universe such as US equities will take quite a long time. If you do it once a month, it will take less than the month, yes (well, maybe NOT EVEN - 8000 assets / 30 days * 24 hours = 11, so you need to process 11 assets / hour - so there are strategies that can take more than 5-6 mins to process per asset), but without careful design (meet threads), your algo will stop trading while doing universe selection.
If you do a pre-selection before the selection, then it's a different idea. And even if you do calculate your selection in just a couple of days, then for the rest of the month, your strategy does not run on freshly selected symbols.
So I believe that you can either:
1- Use an external source to get which assets to select based on your strategy (such as pointed out by the OP), i.e., the big number crunching is done externally or
2- Use C# or libraries to make Python much much faster if you want to be your own source. The Python way with the libraries is not trivial.
Fred
Newoptionz
Hi
Yes, well I think that is what they do at powerX. They definetly don't feed all the best selections back every day, just each day they feed more back. Well one does not have to test thousands of assests, we only need to identify enough assets to keep trading, and following strict trading rules this should be possible. I'm pretty clueless how to do this, but starting tomorrow I'm goint to try.
My procedure in hospital was cancelled, I had Covid three weeks ago and they want everyone to be clear of Covid for at least six weeks before going into surgery.
Adam W
Fred Painchaud Good point. I was thinking more along the lines of “if indicator does this”-type strategies that OP mentioned, which can be vectorized and quickly simulated in a minute or two even for large universes. Memory constraints may be an issue in live trading though, so some pre-filtering (e.g. restricting initial universe to only S&P 500 components) would be helpful.
Fred Painchaud
Hey Adam,
That's ok. I simply saw nothing of that (vectorization) in your pseudo-code, and I believed it was a key point (it meets my option #2).
Anyway.
I also do believe that restricting to S&P500 constituents will likely defeat the purpose of the fancy Universe Selection. I'd then just apply my strategy to the S&P500 constituents, without further filtering.
My 2 cents worth…
Fred
.ekz.
Unless I'm missing something… why not:
This wouldn't involve calling History in any special way just to simulate….
Would still be a pretty expensive system to run though (performance-wise).
I may have missed something though. Operating on very little sleep 😴
Fred Painchaud
Hi Ekz,
I don't think you missed anything. You understood. Your steps 1 to 4 simply creates “the source of information for winners” discussed above. Step 5 backtests using that source. Steps 6 and 7 make sure the “source” is kept up to date.
Calling History is certainly evitable, and would need to be avoided. I suspect that at least in Python, it uses iteration over objects to create the DF which is unnecessarily slow (I haven't checked but I create DFs from MBs of CSV files much faster than History locally - for instance, I load 3 years worth of BTCUSD minute data into a DF in around 5 seconds, History takes more than a minute to return the result if I recall right). But I digress.
The issue is not the difficulty in creating that “source”, it is the time it takes to create it over thousands and thousands of assets and then keep it up to date day after day. Of course, working on daily resolution instead of minutes or seconds would help a lot with performance. But at minute res and below (and maybe also at hour), it is not possible to keep the pace with Python alone, without proper design involving compilation to assembly, vectorization, etc. But with that help, it is certainly possible.
But I understood (maybe mistakenly), that the OP has an external source for that info. If so, the algo is simply about reading the updated info on “winners” and trade them. I'd guess it's less than 100 lines total using self.AddUniverse() in QCAlgorithm as a way to create a custom universe (one that uses the external source as a “selector”).
Fred
Newoptionz
Hi all
Adam W great idea, I will try get the basic system going first, meaning no universe selection to start with, The trading system and universe selection system are related, just the trading system uses QC and the selection system does not.
.ekz. your stratergy sounds like it is set-up for live trading and not backtesting, which is fine.
I think just
Newoptionz
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!