import baostock as bs
import pandas as pd
import cv2
import numpy as np


def normalize_one_stock(bs, stock_code):
    if stock_code[:2] == '60':
        stock_code = 'sh.' + stock_code
    else:
        stock_code = 'sz.' + stock_code
    rs = bs.query_history_k_data(stock_code,
                                "date, amount",
                                start_date='2014-01-01', end_date='2018-11-30',
                                frequency="d", adjustflag="2")
    print('Now dealing stock {}'.format(stock_code))
    print(rs.error_msg)
    print(rs.error_code)
    # 获取具体的信息
    result_list = []
    while (rs.error_code == '0') & rs.next():
        result_list.append(rs.get_row_data())
    result_list = [float(date[1]) for date in result_list]
    range = max(result_list) - min(result_list)
    minval = min(result_list)
    normalize_list = [(i-minval)/range for i in result_list]
    return normalize_list


if __name__ == "__main__":
    cv2.namedWindow('Image', 0)
    cv2.resizeWindow('Image', 1200, 640)
    days = 1200
    bs.login()
    stock_list = ['300290','603138','002312','300570','300609','300659','300556','603881','300608','300394','300456','002777','002331','603936','600845','300369','300188','300520','603039','603118','600734','300036','300513','300559','300508','002421','603496','300541','300620','300555','300514','002908','002912','603380','002855','002376','300542','600624','300300','300657','300623','002368','300352','002410','300546','300365','000851','300663','300730','300689','300168','300451','000670','002027','002841','603025','300226','002649','002230','600271','002152','300460','300628','300399','603990','300253','000938','600588','600570','600745','000997','603508','300571','002065','002439','300588','300271','600100','002771','000688','300469','300288','300523','002401','900926','300605','300496','603232','300661','603636','600652','603660','002415','300031','300579','002180','300667','603133','300348','600718','002195','300550','300468','300245','300339','300275','600850','300379','300282','002829','002298','002425','000977','002635','603595','002373','300045','600756','300166','002729','002396','300598','000948','300682','002745','002268','603986','603328','300044','300047','002866','600476','300075','300213','000555','300377','300448','000021','300248','002383','600536','002339','300183','300378','300433','603383','300297','300330','300516','300212','300170','603019','002063','000971','603528','300104','300552','300479','300052','002315','300295','603444','300386','002296','300380','603996','600446','002073','300017','300033','300561','002474','002279','002261','002177','300333','002642','002095','000066','300277','603189','600601','002405','600392','002362','600455','300101','300020','300525','002280','600654','002577','300627','300672','600797','002657','300419','300229','603918','300002','601519','300287','600571','300367','002153','300645','300384','000682','600637','002197','300051','300467','600728','300533','300150','603160','002253','300302','300465','300581','002232','603106','300343','600410','300418','002308','300311','002184','603533','603258','300350','300113','300042','300494','300440','002609','300518','600986','600289','002137','300085','300010','300324','300242','300182','002555','300687']
    price_matrix = []
    # stock_list = ['000691', '600807', '000558']
    for code in stock_list:
        try:
            stock_price = normalize_one_stock(bs, code)
            if len(stock_price) == days:
                price_matrix.append(stock_price)
        except:
            pass

    stock_num = len(price_matrix)
    print(stock_num, days)
    graph = np.array([price for stock in price_matrix for price in stock])
    # print(price_matrix)
    print(graph.shape)
    graph = graph.reshape(stock_num, days, 1) * 255
    print(graph)
    cv2.imshow('Image', graph)
    cv2.imwrite('computer_original.jpg', graph)
    cv2.waitKey(10000)
    bs.logout()

52a8e9e2f93fdfc9ec7545ef3c6999e0664a7654
<mask token>

<mask token>


def normalize_one_stock(bs, stock_code):
    if stock_code[:2] == '60':
        stock_code = 'sh.' + stock_code
    else:
        stock_code = 'sz.' + stock_code
    rs = bs.query_history_k_data(stock_code, 'date, amount', start_date=
        '2014-01-01', end_date='2018-11-30', frequency='d', adjustflag='2')
    print('Now dealing stock {}'.format(stock_code))
    print(rs.error_msg)
    print(rs.error_code)
    result_list = []
    while (rs.error_code == '0') & rs.next():
        result_list.append(rs.get_row_data())
    result_list = [float(date[1]) for date in result_list]
    range = max(result_list) - min(result_list)
    minval = min(result_list)
    normalize_list = [((i - minval) / range) for i in result_list]
    return normalize_list


<mask token>

<mask token>


def normalize_one_stock(bs, stock_code):
    if stock_code[:2] == '60':
        stock_code = 'sh.' + stock_code
    else:
        stock_code = 'sz.' + stock_code
    rs = bs.query_history_k_data(stock_code, 'date, amount', start_date=
        '2014-01-01', end_date='2018-11-30', frequency='d', adjustflag='2')
    print('Now dealing stock {}'.format(stock_code))
    print(rs.error_msg)
    print(rs.error_code)
    result_list = []
    while (rs.error_code == '0') & rs.next():
        result_list.append(rs.get_row_data())
    result_list = [float(date[1]) for date in result_list]
    range = max(result_list) - min(result_list)
    minval = min(result_list)
    normalize_list = [((i - minval) / range) for i in result_list]
    return normalize_list


if __name__ == '__main__':
    cv2.namedWindow('Image', 0)
    cv2.resizeWindow('Image', 1200, 640)
    days = 1200
    bs.login()
    stock_list = ['300290', '603138', '002312', '300570', '300609',
        '300659', '300556', '603881', '300608', '300394', '300456',
        '002777', '002331', '603936', '600845', '300369', '300188',
        '300520', '603039', '603118', '600734', '300036', '300513',
        '300559', '300508', '002421', '603496', '300541', '300620',
        '300555', '300514', '002908', '002912', '603380', '002855',
        '002376', '300542', '600624', '300300', '300657', '300623',
        '002368', '300352', '002410', '300546', '300365', '000851',
        '300663', '300730', '300689', '300168', '300451', '000670',
        '002027', '002841', '603025', '300226', '002649', '002230',
        '600271', '002152', '300460', '300628', '300399', '603990',
        '300253', '000938', '600588', '600570', '600745', '000997',
        '603508', '300571', '002065', '002439', '300588', '300271',
        '600100', '002771', '000688', '300469', '300288', '300523',
        '002401', '900926', '300605', '300496', '603232', '300661',
        '603636', '600652', '603660', '002415', '300031', '300579',
        '002180', '300667', '603133', '300348', '600718', '002195',
        '300550', '300468', '300245', '300339', '300275', '600850',
        '300379', '300282', '002829', '002298', '002425', '000977',
        '002635', '603595', '002373', '300045', '600756', '300166',
        '002729', '002396', '300598', '000948', '300682', '002745',
        '002268', '603986', '603328', '300044', '300047', '002866',
        '600476', '300075', '300213', '000555', '300377', '300448',
        '000021', '300248', '002383', '600536', '002339', '300183',
        '300378', '300433', '603383', '300297', '300330', '300516',
        '300212', '300170', '603019', '002063', '000971', '603528',
        '300104', '300552', '300479', '300052', '002315', '300295',
        '603444', '300386', '002296', '300380', '603996', '600446',
        '002073', '300017', '300033', '300561', '002474', '002279',
        '002261', '002177', '300333', '002642', '002095', '000066',
        '300277', '603189', '600601', '002405', '600392', '002362',
        '600455', '300101', '300020', '300525', '002280', '600654',
        '002577', '300627', '300672', '600797', '002657', '300419',
        '300229', '603918', '300002', '601519', '300287', '600571',
        '300367', '002153', '300645', '300384', '000682', '600637',
        '002197', '300051', '300467', '600728', '300533', '300150',
        '603160', '002253', '300302', '300465', '300581', '002232',
        '603106', '300343', '600410', '300418', '002308', '300311',
        '002184', '603533', '603258', '300350', '300113', '300042',
        '300494', '300440', '002609', '300518', '600986', '600289',
        '002137', '300085', '300010', '300324', '300242', '300182',
        '002555', '300687']
    price_matrix = []
    for code in stock_list:
        try:
            stock_price = normalize_one_stock(bs, code)
            if len(stock_price) == days:
                price_matrix.append(stock_price)
        except:
            pass
    stock_num = len(price_matrix)
    print(stock_num, days)
    graph = np.array([price for stock in price_matrix for price in stock])
    print(graph.shape)
    graph = graph.reshape(stock_num, days, 1) * 255
    print(graph)
    cv2.imshow('Image', graph)
    cv2.imwrite('computer_original.jpg', graph)
    cv2.waitKey(10000)
    bs.logout()

import baostock as bs
import pandas as pd
import cv2
import numpy as np


def normalize_one_stock(bs, stock_code):
    if stock_code[:2] == '60':
        stock_code = 'sh.' + stock_code
    else:
        stock_code = 'sz.' + stock_code
    rs = bs.query_history_k_data(stock_code, 'date, amount', start_date=
        '2014-01-01', end_date='2018-11-30', frequency='d', adjustflag='2')
    print('Now dealing stock {}'.format(stock_code))
    print(rs.error_msg)
    print(rs.error_code)
    result_list = []
    while (rs.error_code == '0') & rs.next():
        result_list.append(rs.get_row_data())
    result_list = [float(date[1]) for date in result_list]
    range = max(result_list) - min(result_list)
    minval = min(result_list)
    normalize_list = [((i - minval) / range) for i in result_list]
    return normalize_list


if __name__ == '__main__':
    cv2.namedWindow('Image', 0)
    cv2.resizeWindow('Image', 1200, 640)
    days = 1200
    bs.login()
    stock_list = ['300290', '603138', '002312', '300570', '300609',
        '300659', '300556', '603881', '300608', '300394', '300456',
        '002777', '002331', '603936', '600845', '300369', '300188',
        '300520', '603039', '603118', '600734', '300036', '300513',
        '300559', '300508', '002421', '603496', '300541', '300620',
        '300555', '300514', '002908', '002912', '603380', '002855',
        '002376', '300542', '600624', '300300', '300657', '300623',
        '002368', '300352', '002410', '300546', '300365', '000851',
        '300663', '300730', '300689', '300168', '300451', '000670',
        '002027', '002841', '603025', '300226', '002649', '002230',
        '600271', '002152', '300460', '300628', '300399', '603990',
        '300253', '000938', '600588', '600570', '600745', '000997',
        '603508', '300571', '002065', '002439', '300588', '300271',
        '600100', '002771', '000688', '300469', '300288', '300523',
        '002401', '900926', '300605', '300496', '603232', '300661',
        '603636', '600652', '603660', '002415', '300031', '300579',
        '002180', '300667', '603133', '300348', '600718', '002195',
        '300550', '300468', '300245', '300339', '300275', '600850',
        '300379', '300282', '002829', '002298', '002425', '000977',
        '002635', '603595', '002373', '300045', '600756', '300166',
        '002729', '002396', '300598', '000948', '300682', '002745',
        '002268', '603986', '603328', '300044', '300047', '002866',
        '600476', '300075', '300213', '000555', '300377', '300448',
        '000021', '300248', '002383', '600536', '002339', '300183',
        '300378', '300433', '603383', '300297', '300330', '300516',
        '300212', '300170', '603019', '002063', '000971', '603528',
        '300104', '300552', '300479', '300052', '002315', '300295',
        '603444', '300386', '002296', '300380', '603996', '600446',
        '002073', '300017', '300033', '300561', '002474', '002279',
        '002261', '002177', '300333', '002642', '002095', '000066',
        '300277', '603189', '600601', '002405', '600392', '002362',
        '600455', '300101', '300020', '300525', '002280', '600654',
        '002577', '300627', '300672', '600797', '002657', '300419',
        '300229', '603918', '300002', '601519', '300287', '600571',
        '300367', '002153', '300645', '300384', '000682', '600637',
        '002197', '300051', '300467', '600728', '300533', '300150',
        '603160', '002253', '300302', '300465', '300581', '002232',
        '603106', '300343', '600410', '300418', '002308', '300311',
        '002184', '603533', '603258', '300350', '300113', '300042',
        '300494', '300440', '002609', '300518', '600986', '600289',
        '002137', '300085', '300010', '300324', '300242', '300182',
        '002555', '300687']
    price_matrix = []
    for code in stock_list:
        try:
            stock_price = normalize_one_stock(bs, code)
            if len(stock_price) == days:
                price_matrix.append(stock_price)
        except:
            pass
    stock_num = len(price_matrix)
    print(stock_num, days)
    graph = np.array([price for stock in price_matrix for price in stock])
    print(graph.shape)
    graph = graph.reshape(stock_num, days, 1) * 255
    print(graph)
    cv2.imshow('Image', graph)
    cv2.imwrite('computer_original.jpg', graph)
    cv2.waitKey(10000)
    bs.logout()

import baostock as bs
import pandas as pd
import cv2
import numpy as np


def normalize_one_stock(bs, stock_code):
    if stock_code[:2] == '60':
        stock_code = 'sh.' + stock_code
    else:
        stock_code = 'sz.' + stock_code
    rs = bs.query_history_k_data(stock_code,
                                "date, amount",
                                start_date='2014-01-01', end_date='2018-11-30',
                                frequency="d", adjustflag="2")
    print('Now dealing stock {}'.format(stock_code))
    print(rs.error_msg)
    print(rs.error_code)
    # 获取具体的信息
    result_list = []
    while (rs.error_code == '0') & rs.next():
        result_list.append(rs.get_row_data())
    result_list = [float(date[1]) for date in result_list]
    range = max(result_list) - min(result_list)
    minval = min(result_list)
    normalize_list = [(i-minval)/range for i in result_list]
    return normalize_list


if __name__ == "__main__":
    cv2.namedWindow('Image', 0)
    cv2.resizeWindow('Image', 1200, 640)
    days = 1200
    bs.login()
    stock_list = ['300290','603138','002312','300570','300609','300659','300556','603881','300608','300394','300456','002777','002331','603936','600845','300369','300188','300520','603039','603118','600734','300036','300513','300559','300508','002421','603496','300541','300620','300555','300514','002908','002912','603380','002855','002376','300542','600624','300300','300657','300623','002368','300352','002410','300546','300365','000851','300663','300730','300689','300168','300451','000670','002027','002841','603025','300226','002649','002230','600271','002152','300460','300628','300399','603990','300253','000938','600588','600570','600745','000997','603508','300571','002065','002439','300588','300271','600100','002771','000688','300469','300288','300523','002401','900926','300605','300496','603232','300661','603636','600652','603660','002415','300031','300579','002180','300667','603133','300348','600718','002195','300550','300468','300245','300339','300275','600850','300379','300282','002829','002298','002425','000977','002635','603595','002373','300045','600756','300166','002729','002396','300598','000948','300682','002745','002268','603986','603328','300044','300047','002866','600476','300075','300213','000555','300377','300448','000021','300248','002383','600536','002339','300183','300378','300433','603383','300297','300330','300516','300212','300170','603019','002063','000971','603528','300104','300552','300479','300052','002315','300295','603444','300386','002296','300380','603996','600446','002073','300017','300033','300561','002474','002279','002261','002177','300333','002642','002095','000066','300277','603189','600601','002405','600392','002362','600455','300101','300020','300525','002280','600654','002577','300627','300672','600797','002657','300419','300229','603918','300002','601519','300287','600571','300367','002153','300645','300384','000682','600637','002197','300051','300467','600728','300533','300150','603160','002253','300302','300465','300581','002232','603106','300343','600410','300418','002308','300311','002184','603533','603258','300350','300113','300042','300494','300440','002609','300518','600986','600289','002137','300085','300010','300324','300242','300182','002555','300687']
    price_matrix = []
    # stock_list = ['000691', '600807', '000558']
    for code in stock_list:
        try:
            stock_price = normalize_one_stock(bs, code)
            if len(stock_price) == days:
                price_matrix.append(stock_price)
        except:
            pass

    stock_num = len(price_matrix)
    print(stock_num, days)
    graph = np.array([price for stock in price_matrix for price in stock])
    # print(price_matrix)
    print(graph.shape)
    graph = graph.reshape(stock_num, days, 1) * 255
    print(graph)
    cv2.imshow('Image', graph)
    cv2.imwrite('computer_original.jpg', graph)
    cv2.waitKey(10000)
    bs.logout()
