def main(indexname, dtstr): # ---------------------------------------------------------------- indexspec = { 'r1000': cfg.r1000spec, 's500': cfg.s500spec, 'n100': cfg.n100spec, }[indexname] # ---------------------------------------------------------------- enddt = str_to_dt(dtstr) startdt = enddt - datetime.timedelta(days=500) run_single_spec = { **indexspec, "universe/opt/date_range/0": startdt, "universe/opt/date_range/1": enddt, } print(run_single_spec) # ---------------------------------------------------------------- (actions, rtcfg) = run_single(run_single_spec) print(containerChecksum(rtcfg)) for action in actions: print("#" * 80) print('rundate', dt64_to_str(action['rundate'])) print('sysfilter', action['sysfilter']) print('stageopen', action['stageopen'][1].tolist()) print('stageclose', action['stageclose'])
def load_history_for_symbols(symbols,pp_opt={},startdate=str_to_dt('1970-01-01'),enddate=None,interval="D"): pp_opt_json = json.dumps(pp_opt) pricehistory = {} symbar = tqdm(symbols,leave=None,desc="history") for symbol in symbar: pricehistory[symbol] = load_history(symbol,pp_opt=pp_opt_json,startdate=startdate,enddate=enddate,interval=interval) pricehistory = pd.concat(pricehistory.values(),keys=pricehistory.keys(),axis=1) return pricehistory
def symbols_btw(self,startdate=None,enddate=None): if(startdate is None): startdate = str_to_dt('1970-01-01') if(enddate is None): enddate = datetime.datetime.now().date() # -- uni = self.__membership uni = uni[inrange(uni.index,ge=startdate,le=enddate)] return uni.columns.to_numpy()
def trade_dates_btw_(self, startdate=None, enddate=None): if (startdate is None): # startdate = __0_date_str__('1970-01-01') startdate = str_to_dt('1970-01-01') if (enddate is None): enddate = datetime.datetime.now().date() # -- uni = self.__universe # uni = uni[__inrange__(uni.index,ge=startdate,le=enddate)] uni = uni[inrange(uni.index, ge=startdate, le=enddate)] return list(uni.index)
def load_ng_index_membership(indexname,symbol,startdate=str_to_dt('1970-01-01'),enddate=None): mbr_array = ng.index_constituent_timeseries( symbol, indexname, start_date=startdate, end_date=enddate, padding_setting=ng.PaddingType.ALLWEEKDAYS, format='pandas-dataframe') mbr_array.rename(inplace=True,columns={"Index Constituent":symbol}) mbr_array.replace(0,math.nan,inplace=True) return mbr_array
def load_history(symbol,pp_opt=None,startdate=str_to_dt('1970-01-01'),enddate=None,interval="D"): ngprice = load_ng_historical(symbol,startdate=startdate,enddate=enddate,interval=interval).copy() # -- ngprice.drop(inplace=True,columns=['Turnover','Dividend']) ngprice.rename(inplace=True,columns={ 'Unadjusted Close':'Uclose' }) ngprice['note'] = "" ngprice['last_n_bar'] = range(len(ngprice)-1,-1,-1) # -- for pp in postprocessors(pp_opt) : pp(symbol,ngprice) return ngprice
def load_ng_historical(symbol,startdate=str_to_dt('1970-01-01'),enddate=None,interval="D"): pricedata = ng.price_timeseries( symbol, stock_price_adjustment_setting = ng.StockPriceAdjustmentType.TOTALRETURN, padding_setting=ng.PaddingType.ALLWEEKDAYS, start_date = startdate, end_date = enddate, interval=interval, format='pandas-dataframe' ) return pricedata
"cls": demo1_entry_algo.demo1_entry_algo, "opt": { "pp": { 'lperiod': 200, 'speriod': 50, }, }, }, "exitalgo": { "cls": demo1_exit_algo.demo1_exit_algo, "opt": { "pp": { 'period': 60, 'multiple': 20, 'max_pct_risk': 0.35, }, "op": { 'max_age': 650, }, }, }, "universe": { "cls": index_universe.IndexUniverse, "opt": { "indexname": "NASDAQ 100", "date_range": [str_to_dt('2000-01-01'), str_to_dt('2020-03-31')], } } }