import csv
import os
import time

import numpy as np
import pandas as pd
data_huice=pd.read_csv('./202301-03打板盈利首笔大于500w开盘价.csv',encoding='gbk')
data_huice['日期']=pd.to_datetime(data_huice['日期'])
data_huice=data_huice[data_huice['日期']>=pd.to_datetime('20230317')]
data_shipan= pd.read_excel('/Users/yumingwu/Desktop/打板.xlsx')
data_shipan['买入时间']=pd.to_datetime(data_shipan['买入时间'])
data_shipan=data_shipan[data_shipan['买入时间']>=pd.to_datetime('20230317')]
data_shipan=data_shipan[data_shipan['买入时间']<pd.to_datetime('20230401')]

data_shipan_weichengjiao= pd.read_excel('/Users/yumingwu/Desktop/打板未成交.xlsx')
data_shipan_weichengjiao['买入时间']=pd.to_datetime(data_shipan_weichengjiao['买入时间'])
data_shipan_weichengjiao=data_shipan_weichengjiao[data_shipan_weichengjiao['买入时间']>=pd.to_datetime('20230317')]
data_shipan_weichengjiao=data_shipan_weichengjiao[data_shipan_weichengjiao['买入时间']<pd.to_datetime('20230401')]


with open('./'+'实盘买入重合'+'.csv','w',encoding='gbk',newline='') as csfile:
    writer =csv.writer(csfile)
    writer.writerow(['代码',	'名称',	'买入时间','实盘'])

    for index, item in data_shipan.iterrows():
        code = str(item['代码']).zfill(6)

        data_huice0 =data_huice[data_huice['代码']==('SZ'+code)]
        if len(data_huice0)>0:
            writer.writerow([item['代码'],
                             item['名称'],
                             item['买入时间'],
                             0
                             ])
        else:
            writer.writerow([item['代码'],
                             item['名称'],
                             item['买入时间'],
                             1
                             ])
    for index, item in data_shipan_weichengjiao.iterrows():
        code = str(item['代码']).zfill(6)

        data_huice0 = data_huice[data_huice['代码'] == ('SZ' + code)]
        if len(data_huice0) > 0:
            writer.writerow([item['代码'],
                             item['名称'],
                             item['买入时间'],
                             2
                             ])
        else:
            writer.writerow([item['代码'],
                             item['名称'],
                             item['买入时间'],
                             3
                             ])







