Back to Community
Beginner Question: Windows of Data

Hi,

Any help would be greatly appreciated...

I am playing around with some code, and have a window length of 95.

In that trailing window, I would like to identify if in the first 20 days, the rate of change (ROC or ROCP in TA-Lib?) of the closing price, is not negative or downward sloping.

How do I call this using ROC?

import zipline.transforms.ta as ztt

(and then later to call the function)

RateOfChange = ztt.talib.ROC( ???????not sure what the parameters are).

What are those parameters?

Thanks! Rich

2 responses

My ultimate goal by the way, is to identify high and tight flags in a universe of stocks. This seems very complicated at this phase. I want to check for slope of line 3 months prior, then watch for a 90% increase in stock price within about 2 months, then check for flag formation. Does this sound too complicated for python?

Hello Rich,

Don't use the 'import zipline.transforms.ta as ztt' as that was a workaround I used to access candlestick indicators etc. I now just 'import talib'.

ROC uses close prices and an optional time period which defaults to 10 periods. I haven't given your strategy any thought but the attached shows some of the syntax.

I've never used ROC or ROCP but this is some documentation from within the TA-Lib source:

   /* The interpretation of the rate of change varies widely depending  
    * which software and/or books you are refering to.  
    *  
    * The following is the table of Rate-Of-Change implemented in TA-LIB:  
    *       MOM     = (price - prevPrice)         [Momentum]  
    *       ROC     = ((price/prevPrice)-1)*100   [Rate of change]  
    *       ROCP    = (price-prevPrice)/prevPrice [Rate of change Percentage]  
    *       ROCR    = (price/prevPrice)           [Rate of change ratio]  
    *       ROCR100 = (price/prevPrice)*100       [Rate of change ratio 100 Scale]  
    *  
    * Here are the equivalent function in other software:  
    *       TA-Lib  |   Tradestation   |    Metastock  
    *       =================================================  
    *       MOM     |   Momentum       |    ROC (Point)  
    *       ROC     |   ROC            |    ROC (Percent)  
    *       ROCP    |   PercentChange  |    -  
    *       ROCR    |   -              |    -  
    *       ROCR100 |   -              |    MO  
    *  
    * The MOM function is the only one who is not normalized, and thus  
    * should be avoided for comparing different time serie of prices.  
    *  
    * ROC and ROCP are centered at zero and can have positive and negative  
    * value. Here are some equivalence:  
    *    ROC = ROCP/100  
    *        = ((price-prevPrice)/prevPrice)/100  
    *        = ((price/prevPrice)-1)*100  
    *  
    * ROCR and ROCR100 are ratio respectively centered at 1 and 100 and are  
    * always positive values.  
    */  

P.

Clone Algorithm
7
Loading...
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
Returns 1 Month 3 Month 6 Month 12 Month
Alpha 1 Month 3 Month 6 Month 12 Month
Beta 1 Month 3 Month 6 Month 12 Month
Sharpe 1 Month 3 Month 6 Month 12 Month
Sortino 1 Month 3 Month 6 Month 12 Month
Volatility 1 Month 3 Month 6 Month 12 Month
Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 5316632b873a3907498ff572
This backtest was created using an older version of the backtester. Please re-run this backtest to see results using the latest backtester. Learn more about the recent changes.
There was a runtime error.