资源加载中... loading...

回测中exchange.GetAccount()的使用

Author: 羽于羊, Created: 2021-03-11 18:28:35, Updated:

我使用如下代码进行回测 def CalculateMA(n,record): sumMA = 0 for i in range(n): sumMA += record[-(i+1)][“Close”] return sumMA/n

def SimpleMAStrategy(status): account = exchange.GetAccount() ticker = exchange.GetTicker() record = exchange.GetRecords(RecordsTime) MAFast = CalculateMA(MAFastN,record) MASlow = CalculateMA(MASlowN,record) balance = account[“Balance”] stocks = account[“Stocks”] Log(“当前持仓量是:”, account[“Stocks”],“当前余额是:”, account[“Balance”]) currSell1Price = ticker[“Sell”] if (MAFast >= MASlow and status == 0): id = exchange.Buy(-1, balance*rate/ticker[“Sell”]) status = 1 if (MAFast <= MASlow and status == 1): id = exchange.Sell(-1, stocks) status = 0 return status

status = 0 while(true): status = SimpleMAStrategy(status) Sleep(3000)

发现回测中始终输出当前持仓量是: 3.89e-07 当前余额是: 19999.166986677. 请问回测中exchange.GetAccount是始终只会返回配置参数中设定的信息吗?


More

小草 回测需要把原来添加的删掉,重新添加才会生效