예제 #1
0
파일: hot.py 프로젝트: geraybos/zjf_lx
    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()))
예제 #2
0
 def get_k(cls, stock_code, sampleNo, kline, date, index_profit):
     # print(len(date))
     kline = "simulation_" + kline
     profit = Stochastic.get_random(sigma=0.01, sampleNo=sampleNo)
     high_increse = np.abs(
         Stochastic.get_random(sigma=0.005, sampleNo=sampleNo))
     low_increase = np.abs(
         Stochastic.get_random(sigma=0.005, sampleNo=sampleNo))
     resel = []
     reselh = []
     resell = []
     r = 1
     for i, ss in enumerate(profit):
         r *= 1 + profit[i] + index_profit[i]
         h = (r *
              1.1) if (1 +
                       high_increse[i]) > 1.1 else r * (1 + high_increse[i])
         l = (r * 0.9) if r * (1 - low_increase[i]) < 0.9 else r * (
             1 - low_increase[i])
         resel.append(r)
         reselh.append(h)
         resell.append(l)
     dd = pd.DataFrame({
         'stock_code': stock_code,
         'date': date,
         'low': resell,
         'high': reselh,
         'close': resel,
         'open': resel
     })
     ModelData.insert_data(table_name=kline, data=dd)
예제 #3
0
파일: get_fund.py 프로젝트: geraybos/zjf_lx
 def get_stock_basics(cls):  #上市公司基本情况
     data = ts.get_stock_basics()
     data['code'] = data.index
     data.reset_index(drop=True, inplace=True)
     ModelData.remove_data(table_name='stock_basics')
     print('remove success')
     ModelData.insert_data(table_name='stock_basics', data=data)
     print('write success')
예제 #4
0
파일: get_fund.py 프로젝트: geraybos/zjf_lx
 def get_cashflow_data(cls, year, quarter):
     data = ts.get_cashflow_data(year, quarter)
     data['year'] = year
     data['quarter'] = quarter
     data.reset_index(drop=True, inplace=True)
     ModelData.remove_data(table_name='cashflow_data',
                           year=year,
                           quarter=quarter)
     print('remove success')
     ModelData.insert_data(table_name='cashflow_data', data=data)
     print('write success')
예제 #5
0
파일: get_fund.py 프로젝트: geraybos/zjf_lx
 def get_profit_data(cls, year, quarter):  #反应盈利能力的
     data = ts.get_profit_data(year, quarter)
     data['year'] = year
     data['quarter'] = quarter
     data.reset_index(drop=True, inplace=True)
     ModelData.remove_data(table_name='profit_data',
                           year=year,
                           quarter=quarter)
     print('remove success')
     ModelData.insert_data(table_name='profit_data', data=data)
     print('write success')
     print(data.head(5))
예제 #6
0
파일: hot.py 프로젝트: geraybos/zjf_lx
    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()
예제 #7
0
파일: Industry.py 프로젝트: geraybos/zjf_lx
 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()
예제 #8
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())
예제 #9
0
파일: hot.py 프로젝트: geraybos/zjf_lx
        # 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)