Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Force Index

Hi everyone

I'm new to quantopian and also python so I need some help.

I need to calculate the Force Index within the algorithm.

I'm having trouble defining yesterday's close price separate from the day before yesterday's close price.

I am also having trouble defining the volume of trades done in yesterday's session for an instrument.

The force index calculation is: yesterday's close price (minus) the day before's close price (multiplied by) yesterday's volume of trades.

I would really appreciate your help on this.

Many Thanks

Steven

8 responses

Hello Steven,

Here's an example of how to get the data you need. Via the batch transform, the price and volume data are captured in numpy ndarrays (see http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html). You can then use basic indexing/slicing to get the data you need for computing the Force Index (see http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html).

In the end, you probably will want to write a function (e.g. get_force_index) to compute the index. Also, the code can be more elegant by preserving the Pandas data structure used by the batch transform, rather than converting to ndarrays.

Grant


Example of log output

2013-07-23PRINTData types of prices & volumes:  
2013-07-23PRINT<type 'numpy.ndarray'>  
2013-07-23PRINT<type 'numpy.ndarray'>  
2013-07-23PRINTCurrent & trailing prices & volumes:  
2013-07-23PRINT[[ 104.55 169.5 ] [ 104.45 169.23] [ 103.59 168.53]]  
2013-07-23PRINT[[ 21131904. 64290634.] [ 23743924. 66982780.] [ 26231137. 98715289.]]  
2013-07-23PRINTCurrent price & volume for each security:  
2013-07-23PRINT103.59  
2013-07-23PRINT26231137  
2013-07-23PRINT168.53  
2013-07-23PRINT9871528  

Hi Steven,

I worked up an example algorithm and attached it (no guarantee that it doesn't have a bug, so please check it).

Grant

Thanks Grant, I really appreciate this. It's a big step in working towards an algorithm for Dr Elders triple screen trading technique.

Steven

@grant

33 Warning Undefined name 'batch_transform'
33 Error Runtime exception: NameError: name 'batch_transform' is not defined
batch_transform is no longer supported. Please use history instead.

@ Vlademir -

I suggest re-factoring the code, so that it does not call the batch_transform, which has been deprecated. If you aren't sure how to do it, I suggest giving it a try. The function is simple enough that it'd be a good learning exercise.

@grant...
can we collaborate.... I already took a stab at it.... and I'm still getting errors.... thru trial and error.... need help... thanks....

Vlademir,

Here is my version .

Thanks Vladimir...