Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
20 weeks high (weekly frequency)

Hi,
I'm kinda new to both quantopian and python, and was wondering how in research environment I can get the say 20-weeks high of a stock, but I don't want daily prices to be considered, but getting the 20-weeks high only from 20 end of the week prices, i.e. weekly frequency.

and am I right to think that the way to go about researching on this is different from when writing the actual algorithm, i.e. different API are used?

Thanks,

3 responses

Hi,

Any takers for this question please?

I do appreciate your time

Try this in IDE.

# --------------------------------  
STOCK = symbol('SPY'); WEEKS = 20;  
# --------------------------------  
def initialize(context):  
    schedule_function(indicator, date_rules.week_end(), time_rules.market_close())

def indicator(context, data):  
    days = (WEEKS + 1)*5

    OHLC = data.history(STOCK, ['open', 'high', 'low', 'close'], days, '1d')  
    OHLC_W = OHLC.resample('1W-FRI').agg({'open': 'first', 'high': 'max', 'low': 'min', 'close': 'last'})  
    HH_20W = OHLC_W['high'][-WEEKS:].max() # highest high 1W-FRI  
    HC_20W = OHLC_W['close'][-WEEKS:].max() # highest close 1W-FRI

    print (HH_20W, HC_20W)  
    record(HH_20W = HH_20W, HC_20W = HC_20W)  

Thank you Vladimir,

I think this will give me enough to do my research and dive into the docs. Thank you!