Example #1
0
def calculate_technicals(start,end):
    
    end_date_time = datetime.datetime.now()  # mysqldb.get_maxdate()[0]   
    start_date_time = end_date_time - relativedelta(days=constants.DAYS_FOR_TECHNICALS)
    
    list_symbol=dbdao.get_symbols_list_limit(start,end)
    
    list_symbol=['MSFT']
    hist_dates= dbdao.get_historical_dates()
    
    
   
    
    days_behind=100
    
    df_mkt=mongodao.getsymbol_data(constants.MKT_SYMBOL, start_date_time, end_date_time)
    
    
    
    if(start=='0'):        
         
        dbdao.execute_query(["drop table df_technical","truncate table df_history","truncate table  df_alerts"])
    df_technicals = technical_manager.calculate_technical(df_mkt,constants.MKT_SYMBOL,df_mkt, start_date_time, end_date_time, hist_dates,days_behind)
    
    frames=[df_technicals]
    for symbol in list_symbol:    
        try:
            df_symbol=mongodao.getsymbol_data(symbol, start_date_time, end_date_time)
            
            if df_symbol.empty:
                continue
            
            
            logger.info("Getting Technicals for symbol=%s ",symbol)
            df_technicals_new = technical_manager.calculate_technical(df_symbol,symbol,df_mkt, start_date_time, end_date_time, hist_dates,days_behind)
            
            
            frames.append(df_technicals_new)
            
            logger.info("Got Technicals for symbol=%s ",symbol)
        except Exception ,ex:
            logger.error(ex)
            logger.error( traceback.format_exc())
def gethistory_dates():
    end_date = dt.datetime.now()
    start_date = end_date + relativedelta(years=-2)
    # df1 = mongodao.get_symbollist_data(list_symbols, start_date, end_date)
    curdate = dt.datetime.now().date()
    month = curdate.month
    
    monthstartdate = dt.date(curdate.year, curdate.month, 1)
    yearstartdate = dt.date(curdate.year, 1, 1)
    if (month > 3):
                    
                        if (month > 3 and month <= 6):
                        
                            quatermonth = 4;
                        
                        elif (month > 6 and month <= 9):
                        
                            quatermonth = 7;
                        
                        elif (month > 9 and month <= 12):
                        
                            quatermonth = 10;
                        
                    
    else:
                    
                        quatermonth = 1;
    weekstart = curdate - timedelta(days=(curdate.weekday() + 1))
    quarterstartdate = dt.date(curdate.year, quatermonth, 1) - timedelta(days=1)                
     
    #mongodbdao = mongoutil.
    prices_mkt = mongodao.getsymbol_data(constants.MKT_SYMBOL, start_date, end_date)
   
    oneyearbeforedate=curdate - relativedelta(years=1)
    oneMonth=curdate - relativedelta(months=1)
    
    oneyearbeforedate = datetimeutil.getdate(getspecificdate(oneyearbeforedate, prices_mkt)) 
    oneMonth = datetimeutil.getdate(getspecificdate(oneMonth, prices_mkt))
    yesterday = datetimeutil.getdate(getspecificdate(curdate - timedelta(days=1), prices_mkt))
    
    day2 = datetimeutil.getdate(getspecificdate(curdate - timedelta(days=2), prices_mkt))
    day3 = datetimeutil.getdate(getspecificdate(curdate - timedelta(days=3), prices_mkt))
    day5 = datetimeutil.getdate(getspecificdate(curdate - timedelta(days=5), prices_mkt))
    
    weekdstart = datetimeutil.getdate(getspecificdate(weekstart, prices_mkt))
    monthstart = datetimeutil.getdate(getspecificdate(monthstartdate, prices_mkt))
    quaterstart = datetimeutil.getdate(getspecificdate(quarterstartdate, prices_mkt))
    yearstart = datetimeutil.getdate(getspecificdate(yearstartdate, prices_mkt))
    
    return {"current":curdate, "PreviousDay":yesterday, "2days":day2, "3days":day3, "5days":day5, 
            "Weekly":weekdstart, "Monthly":monthstart, "Quaterly":quaterstart, 
            "Yearly":yearstart, "oneyearbeforedate":oneyearbeforedate,"oneMonth":oneMonth}