from KYBT.BT import engine2 
from KYBT.util.kySDK import *
import logging
logger = logging.getLogger(__name__)
logger.setLevel(logging.CRITICAL)
import time
from KYBT.BT.evaluator import evaluator



# ['600000','000002']
#用户输入

# "stockPicker":{'pick':True,'dateList':['2014-07-01','2014-07-05']},
# "stockPicker":{'pick':False,'dateList':None},
inputJson = \
{   "strategyID":'01',
    "stockPicker":{'pick':False,'dateList':None},
    "criteriaDict" : {'存货周转率':['最近一年',None,None],'主营收入同比':['最近一年',None,None],'流动资产':['最近一期',None,None]},
    "portforlio": 'ZZ500', 
    "benchmark": 'ZZ500', 
    "money": 5000000, 
    "startDate": '2013-04-01', 
    "endDate": '2018-04-12', 
    "turnover": 10, 
    "tradingHabit": "OpenPrice",
    "status":0
}


inputJson = \
{
    "strategyID":'2',
    "stockPicker":{"pick":False,"dateList":["2017-05-05"]},
    "criteriaDict" : {"存货周转率":["最近一年",None,None],"主营收入同比":["最近一年",None,None],"流动资产":["最近一期",None,None]},
    "portforlio": "SZ50", 
    "benchmark": "ZZ500", 
    "money": 5000000, 
    "startDate": "2017-04-06", 
    "endDate": "2018-04-12", 
    "turnover": 10, 
    "tradingHabit": "OpenPrice",
    "status":0
}




starttime = time.time()
myBT = engine2.Engine(inputJson) #initialize engine
if myBT.stockPicker['pick'] == False: 
    myBT.backTesting()
    evaluator(myBT.strategyID,myBT.BTRecords,myBT.IndexRecords,plot = False)
elif myBT.stockPicker['pick'] == True:
    for day in myBT.stockPicker['dateList']:
        myBT.stockPicking(day) #是选的哪一天的？？？
endtime = time.time()
print('it takes %0.2f seconds to finish BT'%(endtime-starttime))
