Back

Algorithm for scanning premarket stocks/ unusual volume and volatility

I want to build an algorithm to scan pre-market stocks trading in the NASDAQ for big volume and large volatility.
Is there any similar algorithm or algorithms in c#, c++ that I can use as a reference?
Also, I would place the stop loss 10 percent below the trading price.
Can anyone please provide some code snippets or an algorithm for these particular issues?

Update Backtest








I'm working on something similar and there is definitely a way to do it on this platform. What you're looking for is called the coarse universe function. I believe that QC has a database of over 9000 securities so it scans through all of those.

Here is a snippet for the coarse universe selection:

https://kobra.io/#/e/-KBBPeqpbdI8g0SS4tIo

The return function will take the stocks that meet the filter requirements and put them into the IEnumerable collection.

Since volatility can be determined in a number of ways you'll have to be a little more specific on what criteria you would like to use.

There are over 40 algorithms within the university that are great to look at if you need a better grasp of c#. The community also has a search function so you can find just about anything that you're looking for if you're clever with your words. I'm about to leave work so I'll finish my response when I get home. Hope this helped in some way.

0

@Olivera, there isn't a way to scan based on pre-market data (using QuantConnect data) at this time. Coarse Universe Selection allows scanning but uses normal market hours prices and volumes.

If you have your own premarket activity data you can import this as as custom universe data source. This isn't well documented yet but you can see some examples here: https://github.com/QuantConnect/Lean/blob/master/Algorithm.CSharp/CustomDataUniverseAlgorithm.cs

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.


Is there anything similar to this in Python?  Market-hours is fine.  thx

0

In Python, we can use Coarse Universe Selection that allows scanning but uses normal market hours prices and volumes:

# In Initialize:
self.AddUniverse(self.CoarseSelectionFunction, self.FineSelectionFunction)

These functions receive the Coarse and Fine universes, where returns a list of symbols that obey our filtering criteria. E.g.::

def CoarseSelectionFunction(self, coarse):
# sort descending by daily dollar volume
sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)

# return the symbol objects of the top entries from our sorted collection
top5 = sortedByDollarVolume[:self.__numberOfSymbols]

# we need to return only the symbol objects
list = List[Symbol]()
for x in top5:
list.Add(x.Symbol)

return list

Please checkout the working example below.
For other examples, take a look at the open-source project

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.


How can this example of volume-based selection be modified to use volume averaged over some period? Otherwise the universe changes quite a bit. The built-in universe python object has no history associated with it, so it seems x.DollarVolume above is just the last day's volume

0

We can start from the EmaCrossUniverseSelectionAlgorithm and instead of using two moving averages of price, we would use only one moving average of dollar volume.

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.


Fantastic, thanks very much!
0

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