def setup(param={ 'code': "300022.SZ", 'begin': '20200107', 'end': '20210607', 'money': 20000 }): print(param) global code global begin global end global money global inScale global inScale global outScale global stores global acount money = 20000 acount = 2000 code = param.get('code') begin = param.get('begin') end = param.get('end') if param.__contains__("money"): money = float(param.get('money')) if param.__contains__("acount"): acount = float(param.get('acount')) if param.__contains__("inScale"): inScale = float(param.get('inScale')) if param.__contains__("outScale"): outScale = float(param.get('outScale')) stores = Stores(balance=money) spd = share(code) if spd.cdata is None: return [] logging.info(spd.cdata) list = spd.appendma(data=spd.cdata, ma=5) list = spd.appendma(data=list, ma=10) list = spd.appendma(data=list, ma=20) if begin != None: list = list[list.date >= begin] logging.info(list) if end != None: list = list[list.date <= end] logging.info(list) logging.info(list) shares = json.loads(list.to_json(orient='records')) logging.info(shares) logging.info(''' setup 余额:{} 持仓:{} 持仓记录:{} 代码:{} '''.format(stores.balance, stores.assets, stores.online, code)) return shares
amount = '10000' start = '2019-01-01' end = '2020-01-01' tcode = '300022' if len(sys.argv)>1: tcode = sys.argv[1] if len(sys.argv)>2: amount = sys.argv[2] if len(sys.argv)>3: start = sys.argv[3] if len(sys.argv)>4: end = sys.argv[4] logging.info("begin tcode:%s amount:%s start:%s end:%s",tcode,amount,start,end) tradecenter.balance = float(amount) share = share(tcode) data = share.appendmacd(share.cdata) data = share.appendma(data,30) data_fecha = data.set_index('date') selectData = data_fecha.loc[start: end] balance = [] for i in range(len(selectData)): temdata = selectData.iloc[i] judgeBuy(temdata) judgeSell(temdata) balance.append({"balance":tradecenter.balance,"store":tradecenter.store, "all":tradecenter.balance+tradecenter.store*temdata.close,"date":temdata.name})
def setup(param={ 'code': "300022.SZ", 'begin': '20200107', 'end': '20210607', 'money': 20000 }): try: print(param) global code global begin global end global money global inScale global inScale global outScale global stores global acount money = 20000 acount = 2000 code = param.get('code') begin = param.get('begin') end = param.get('end') if param.__contains__("money"): money = float(param.get('money')) if param.__contains__("acount"): acount = float(param.get('acount')) if param.__contains__("inScale"): inScale = float(param.get('inScale')) if param.__contains__("outScale"): outScale = float(param.get('outScale')) stores = Stores(balance=money) spd = share(code) if spd.cdata is None: return [] data = spd.cdata data = spd.appendma(data=data, ma=5) data = spd.appendma(data=data, ma=10) data = spd.appendma(data=data, ma=20) data = spd.appendma(data=data, ma=30) data['yclose'] = data["close"].shift(1) data['yopen'] = data["open"].shift(1) data['yma30'] = data["ma30"].shift(1) print(data) if begin != None: data = data[data.date >= begin] if end != None: data = data[data.date <= end] shares = json.loads(data.to_json(orient='records')) logging.info(''' 02 -setup 余额:{} 持仓:{} 持仓记录:{} 代码:{} '''.format(stores.balance, stores.assets, stores.online, code)) return shares except Exception as e: logging.warning("real error%s", e)
def test_share(self): tb = share(code='600111.SH', begin="2021-01-01", end="2021-03-01") logging.info("result:\n%s", share.cdata)