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

请问Balance的回测数据是如何获取的

Author: XiaoHuihui0111, Created: 2022-07-23 22:05:11, Updated: 2022-07-24 08:47:41

模拟回测环境

请问通过exchange.GetAccount()获取的账户信息,Balance数值是如何计算的?

初始资金50000,100倍杠杆,开仓初始资金500%,保证金占用理论上应该是5%,可用usdt应该是初始资金95%,实际打印出来的数据是3937


More

发明者量化-小小梦 初始资金*开仓5倍 = 50000 * 5 = 250000 ,100杠杆,即保证金使用开仓规模的1/100 , 即2500。 /upload/asset/16994bd40a7251614992.png /upload/asset/16a9bab6a99666979233.png ``` function main() { exchange.SetContractType("swap") exchange.SetMarginLevel(100) var acc = exchange.GetAccount() Log(acc) //下单 var t = exchange.GetTicker() exchange.SetDirection("buy") exchange.Buy(t.Sell + 1000, acc.Balance * 5 / t.Last) Log(exchange.GetAccount()) } ``` Balance是当前可用保证金。偏差考虑资金费率因素。

XiaoHuihui0111 好的,蟹蟹

发明者量化-小小梦 平仓才有。

XiaoHuihui0111 我的意思是赚钱了,可用保证金应该是放大的,被扣除的资金费率不可能超过盈利数据

发明者量化-小小梦 币安期货有资金费率(回测也有),考虑下。

XiaoHuihui0111 '''backtest start: 2021-09-25 00:00:00 end: 2021-10-25 23:59:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] ''' def main(): exchange.SetContractType("swap") exchange.SetMarginLevel(100) acc = exchange.GetAccount() t = exchange.GetTicker() exchange.SetDirection("buy") exchange.Buy(t.Sell + 1000, acc.Balance * 5 / t.Last) while True: acc = exchange.GetAccount() pos = exchange.GetPosition() Log("Account.Balance: {}, Position.Profit: {}".format(acc.Balance, pos[0].Profit)) Sleep(3600000*8) 麻烦帮忙看看,我这代码是否有问题

发明者量化-小小梦 这边测试正常的,您在具体看下。

XiaoHuihui0111 /upload/asset/20711b5b9230125975968.png 盈利越高,Balance数值越低

XiaoHuihui0111 class Trade(): def __init__(self): exchange.SetContractType("swap") exchange.SetMarginLevel(100) def OnOrder(self): acc = exchange.GetAccount() t = exchange.GetTicker() exchange.SetDirection("buy") exchange.Buy(t.Sell + 1000, acc.Balance * 5 / t.Last) Log(acc) def main(): trade = Trade() trade.OnOrder() while True: acc = exchange.GetAccount() pos = exchange.GetPosition() Log("Account.Balance: {}, Position.Profit: {}".format(acc.Balance, pos[0].Profit)) Sleep(3600000*8) /upload/asset/20711b5b9230125975968.png 盈利越高,Balance数值怎么会越低

XiaoHuihui0111 蟹蟹,我这边查看一下