大概背景:在把公司的申万分类开始日期改成和他对应股票的上市日期一致:
import rqdatac
from rqdatac import *
rqdatac.init()
import pymongo
from pymongo import MongoClient
client = MongoClient('mongodb://dab:dat@192.168.0.8:27017/')
db = client.datahub
collection = db.shenwan_industry
import numpy as np
import pandas as pd
stock_list = list(all_instruments('CS').order_book_id)
#批量测试逻辑
try:
for stk in stock_list:
#instruments部分的date作为string要搞成datetime64格式
listed_str_time = instruments(stk).listed_date
time_stamp_listed = pd.to_datetime(listed_str_time) #先搞成timestamp
listed_time64 = np.array(time_stamp_listed,dtype=np.datetime64) #再搞成datetime64
shenwan_ind = pd.DataFrame(list(collection.find({"order_book_id":stk})))
listed_date_batch = shenwan_ind.start_date.values
n = len(listed_date_batch)
for i in range(0,n-1):
if listed_time64 > listed_date_batch[i]:
print(stk,listed_date_batch[i])
except Exception as err:
print(stk,err)