Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Calculating Slope or Magnitude of a Trend?

I'm hoping this is a simple question with a simple answer. I'm having a difficult time defining what I want in TA or Quantopian terms even though I know what I want must exist.

I simply want to quantify the slope or I guess more importantly, magnitude (slope + volume) of a swing or trend. Where should I look first? Thanks in advance!

4 responses

Hi Pawel,

Quantopian supports the Python numpy and scipy modules (see http://docs.scipy.org/doc/). Depending on what you have in mind, you may want to have a look at http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.linregress.html.

You might try computing the slope of the dollar-volume. For a given security, both the trailing prices and the volumes are available with the batch transform. To obtain the dollar-volume vector, simply multiply the price and volume vectors elementwise (e.g. with http://docs.scipy.org/doc/numpy/reference/generated/numpy.multiply.html).

Grant

Perfect reply, much appreciated. That said other opinions and perspective are more than welcome too! :)

Thanks Grant!

Pawel,

You're welcome. Let us know how things go...just use the "Add Backtest" button once you get your algorithm working (or if you can't, just paste it into the discussion editor box).

Grant

Pawel,

Here's a quick example...it could be extended to multiple securities straightforwardly.

Grant