교육 전략, 관련 기사 주소:https://www.fmz.com/bbs-topic/5080
import random def CancelPendingOrders(): while True: orders = _C(exchange.GetOrders) if len(orders) == 0 : return for j in range(len(orders)): exchange.CancelOrder(orders[j]["Id"]) if j < len(orders) - 1: Sleep(Interval) LastBuyPrice = 0 InitAccount = None def dispatch(): global InitAccount, LastBuyPrice account = None ticker = _C(exchange.GetTicker) LogStatus(_D(), "ticker:", ticker) if LastBuyPrice > 0: if len(_C(exchange.GetOrders)) > 0: if ticker["Last"] > LastBuyPrice and ((ticker["Last"] - LastBuyPrice) / LastBuyPrice) > (2 * (EntrustDepth / 100)): Log("偏离过多, 最新成交价:", ticker["Last"], "委托价", LastBuyPrice) CancelPendingOrders() else : return True else : account = _C(exchange.GetAccount) Log("买单完成, 累计花费:", _N(InitAccount["Balance"] - account["Balance"]), "平均买入价:", _N((InitAccount["Balance"] - account["Balance"]) / (account["Stocks"] - InitAccount["Stocks"]))) LastBuyPrice = 0 BuyPrice = _N(ticker["Buy"] * (1 - EntrustDepth / 100)) if BuyPrice > MaxBuyPrice: return True if not account: account = _C(exchange.GetAccount) if (InitAccount["Balance"] - account["Balance"]) >= TotalBuyNet: return False RandomAvgBuyOnce = (AvgBuyOnce * ((100.0 - FloatPoint) / 100.0)) + (((FloatPoint * 2) / 100.0) * AvgBuyOnce * random.random()) # 随机数 0~1 UsedMoney = min(account["Balance"], RandomAvgBuyOnce, TotalBuyNet - (InitAccount["Balance"] - account["Balance"])) BuyAmount = _N(UsedMoney / BuyPrice) if BuyAmount < MinStock: return False LastBuyPrice = BuyPrice exchange.Buy(BuyPrice, BuyAmount, "花费:¥", _N(UsedMoney), "上次成交价", ticker["Last"]) return True def main(): global LoopInterval, InitAccount CancelPendingOrders() InitAccount = _C(exchange.GetAccount) Log(InitAccount) if InitAccount["Balance"] < TotalBuyNet: raise Exception("账户余额不足") LoopInterval = max(LoopInterval, 1) while dispatch(): Sleep(LoopInterval * 1000) Log("委托全部完成", _C(exchange.GetAccount))
처칠시다른 방법으로는 헤지 전략에서 한쪽의 구매와 다른 쪽의 판매량이 일치하는지 어떻게 보장합니까?
발명가들의 수량화 - 작은 꿈이것은 현금일 뿐이며, 선물로 수정될 수 있다. 헤지핑은 정확한 헤지핑 포지션을 계산해야 한다.