Example #1
0
    def hot_min(self, date, time, kline):
        data = ModelData.read_data(table_name=kline,
                                   field=['stock_code', 'close', 'open'],
                                   date=date,
                                   time=time)
        if len(data) <= 0 and time == 1130:
            data = ModelData.read_data(table_name=kline,
                                       field=['stock_code', 'close', 'open'],
                                       date=date,
                                       time=1300)

        data = data.drop(['_id'], axis=1)
        data['profit'] = data.close / data.open - 1
        data['profit'] = data[abs(data.profit) < 0.11].profit
        data['pro'] = data.profit
        # data['pro'] = data.profit.map(lambda x: 1 if x > 0 else 0)
        data = data.dropna()
        data = pd.merge(stock_codes, data, on=['stock_code'])
        data = data.fillna(0)
        # print(data.stock_code.tolist())
        # data=data[0:56*56]
        arr = np.array(data.pro.tolist() + [0] *
                       (64 * 64 - len(data))).reshape(64, 64)
        # ax = sns.heatmap(arr, vmin=-0.03, vmax=0.03,cbar=False)
        # plt.matshow(arr, cmap='hot')
        # plt.show()
        BaseModel('hot_min5_version4').insert_batch(
            dict(date=date, time=time, value=arr.tolist()))
Example #2
0
    def hot_day(self, date):
        data = ModelData.read_data(table_name='kline_day',
                                   field=['stock_code', 'close', 'open'],
                                   date=date)
        data = data.drop(['_id'], axis=1)
        data['profit'] = data.close / data.open - 1
        data['profit'] = data[abs(data.profit) < 0.11].profit
        data['pro'] = data.profit.map(lambda x: True if x > 0 else False)
        data = data.dropna()
        # data=data[0:56*56]

        arr = np.array(data.pro.tolist() + [0] *
                       (64 * 64 - len(data))).reshape(64, 64)
        # ax = sns.heatmap(arr, vmin=-0.03, vmax=0.03,cbar=False)
        plt.matshow(arr, cmap='hot')
        plt.show()
Example #3
0
 def add_industry(cls, table):
     from Calf import ModelData
     import pymongo
     url = 'mongodb://*****:*****@192.168.1.104:27017/?connectTimeoutMS=2000;authSource=admin'
     industry = ModelData.read_data(table_name='platestock')
     dic = {}
     for i, r in industry.iterrows():
         dic[r.stock_code] = r.hangye
     myclient = pymongo.MongoClient(url)
     mydb = myclient["ppp"]
     mycol = mydb[table]
     for s_c in industry.stock_code.tolist():
         myquery = {"stock_code": s_c}
         newvalues = {"$set": {"hangye": dic[s_c]}}
         x = mycol.update_many(myquery, newvalues)
         print(x.modified_count, s_c + "文档已修改")
     myclient.close()
Example #4
0
            try:
                data, address = s.recvfrom(65535)
                data = data.decode('utf-8')
                print('Server received from {}:{}'.format(address, data))
                data = json.loads(data)
                if data['identification'] == 'getdata':
                    result[data['kline']] = True
                    if result['index_min5'] and result['kline_min5']:
                        print('start')
                        # dosomething
                        # your function
                        result = {'kline_min5': False, 'index_min5': False}
            except Exception as e:
                print(e)


# Messages.receive()
# import datetime as dt
# date=dt.datetime.now()
# # messages = {'identification': 'getdata', 'status': 200, 'kline': 'index_min5', 'other': 'ok','datetime':date}
# messages2 = {'identification': 'getdata', 'status': 200, 'kline': 'kline_min30', 'other': 'ok','datetime':str(date)}
# # Messages.send(messages)
# Messages.send(messages2)
import datetime as dt
kline = 'kline_min5'
date = dt.datetime(2018, 8, 6)
data = ModelData.read_data(table_name=kline,
                           field=['stock_code', 'close', 'open'],
                           date=date,
                           time=1130)
print(data.stock_code.tolist())
Example #5
0
        # plt.show()
        BaseModel('hot_min5_version4').insert_batch(
            dict(date=date, time=time, value=arr.tolist()))


def fun(data):
    for i, r in data.iterrows():
        try:
            print('date', r.date, 'time', r.time)
            Hot().hot_min(date=r.date, time=r.time, kline='kline_min5')
        except Exception as e:
            print(e)


# Hot().hot_day(date=dt.datetime(2018,8,1))

if __name__ == '__main__':

    data = ModelData.read_data(table_name='kline_min5',
                               field=['date', 'time'],
                               stock_code='000001',
                               date={
                                   '$gte': dt.datetime(2016, 1, 1),
                                   '$lte': dt.datetime(2018, 8, 6)
                               })
    m = 10
    # data=data[0:1]
    li = [data[i:i + m] for i in range(0, len(data), m)]
    pool = multiprocessing.Pool(processes=3)
    pool.map(fun, li)