Average.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:sogaQuant 作者: idoplay 项目源码 文件源码
def run(self):
        print self.args
        '''
        dateline=%s" % day
        '''
        day = self.args[2]
        pandas.set_option('display.width', 200)
        d2 = self.mysql.getRecord("select s_code from s_stock_list where dateline=%s" % day)
        for row in d2:
            s_code = row['s_code']
            #if s_code != 'sh600000':
            #    continue
            self._chQ = self.getChuQuan(s_code)
            sql_data = "select s_code,code,dateline,chg_m,chg,open,close,high,low,last_close,name FROM s_stock_trade WHERE s_code ='%s' and dateline >20150101 " % s_code
            print sql_data
            tmpdf2 = pandas.read_sql(sql_data, self.mysql.db)
            tmpdf = tmpdf2.apply(self.format_chuquan_hanlder, axis=1)
            tmpdf.sort_values(by=('dateline'), ascending=False)

            ma_list = [5, 10, 20, 30, 60]
            for ma in ma_list:
                tmpdf['MA_' + str(ma)] = pandas.rolling_mean(tmpdf['close'], ma)

            last5 = tmpdf.tail(60)
            #print last5
            #sys.exit()
            for i5 in range(0, len(last5)):
                if str(last5.iloc[i5].dateline) != day:
                    continue

                word = s_code[2:] + str(last5.iloc[i5].dateline)
                if math.isnan(last5.iloc[i5].MA_5):
                    break
                if math.isnan(last5.iloc[i5].MA_10):
                    break

                _m60 = last5.iloc[i5].MA_60
                if math.isnan(last5.iloc[i5].MA_60):
                    _m60 = 0
                else:
                    _m60 = round(_m60, 2)
                _m30 = last5.iloc[i5].MA_30
                if math.isnan(last5.iloc[i5].MA_30):
                    _m30 = 0
                else:
                    _m30 = round(_m30, 2)

                item = {}
                item['s_code'] = s_code
                item['dateline'] = last5.iloc[i5].dateline
                item['hash'] = hashlib.md5(word).hexdigest()
                item['ma5'] = round(last5.iloc[i5].MA_5, 2)
                item['ma10'] = round(last5.iloc[i5].MA_10, 2)
                item['ma20'] = round(last5.iloc[i5].MA_20, 2)
                item['ma30'] = _m30
                item['ma60'] = _m60
                self.mysql.dbInsert('s_stock_average', item)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号