Skip to content

Commit d118125

Browse files
authored
Add files via upload
1 parent 950a83d commit d118125

File tree

1 file changed

+6
-58
lines changed

1 file changed

+6
-58
lines changed

fmz.py

+6-58
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ def __init__(self, task = None, autoRun=False, gApis = None, progressCallback=No
14201420
js = os.path.join(tmpCache, crcFile)
14211421
if os.path.exists(js):
14221422
b = open(js, 'rb').read()
1423-
if os.getenv("BOTVS_TASK_UUID") is None or "0af40e6b08893ffbbd023cdc48ecb55a" in str(b):
1423+
if os.getenv("BOTVS_TASK_UUID") is None or "5d063817216d05c313a7aefa5cf8378c" in str(b):
14241424
hdic = json_loads(b)
14251425
loader = os.path.join(tmpCache, soName)
14261426
update = False
@@ -1868,66 +1868,14 @@ def Join(self, report=False):
18681868
ret = json.loads(self._joinResult)
18691869
pnl = []
18701870
index = []
1871-
symbol = None
1872-
eid = None
1873-
balanceName = 'stocks'
1871+
margin_suffix = ''
18741872
for ele in ret['Snapshots']:
18751873
acc = ele[1][0]
1876-
close = float('nan')
1877-
eid = acc['Id']
1878-
balance = .0
1879-
stocks = .0
1880-
commission = .0
1881-
for asset in acc['Assets']:
1882-
if acc['QuoteCurrency'] == asset['Currency']:
1883-
balance += asset['Amount'] + asset['FrozenAmount']
1884-
commission += asset['Commission']
1885-
elif acc['BaseCurrency'] == asset['Currency']:
1886-
stocks += asset['Amount'] + asset['FrozenAmount']
1887-
else:
1888-
info = acc['Symbols'].get(asset['Currency'] + '_' + acc['QuoteCurrency'], None)
1889-
if info:
1890-
balance += (asset['Amount'] + asset['FrozenAmount']) * info['Last']
1891-
commission += asset['Commission'] * info['Last']
1892-
symbols = acc['Symbols']
1893-
if eid == 'Futures_CTP' or eid == 'Futures_XTP':
1894-
balanceName = 'balance'
1895-
available = balance
1896-
if symbols:
1897-
for s in symbols:
1898-
pos = acc['Symbols'][s]
1899-
for t in ['Long', 'Short']:
1900-
if t in pos:
1901-
balance += pos[t]['Margin'] + pos[t]['Profit']
1902-
pnl.append([available, commission, balance])
1903-
elif 'Futures_' in eid:
1904-
marginNet = .0
1905-
asset = .0
1906-
if symbols:
1907-
for s in symbols:
1908-
pos = acc['Symbols'][s]
1909-
for t in ['Long', 'Short']:
1910-
if t in pos:
1911-
marginNet += pos[t]['Margin'] + pos[t]['Profit']
1912-
if acc['QuoteCurrency'] == 'USDT':
1913-
balanceName = 'USDT'
1914-
asset = balance
1915-
else:
1916-
balanceName = acc['BaseCurrency']
1917-
asset = stocks
1918-
pnl.append([asset, commission, asset+marginNet])
1919-
else:
1920-
if symbol is None and symbols:
1921-
for s in acc['Symbols']:
1922-
symbol = s
1923-
break
1924-
if symbol is not None:
1925-
close = acc['Symbols'][symbol]['Last']
1926-
pnl.append([close, balance, stocks, commission, balance+(stocks*close)])
1874+
if not margin_suffix:
1875+
margin_suffix = '(%s)' % (acc['MarginCurrency'], )
1876+
pnl.append([acc['PnL'], acc['Utilization']*100])
19271877
index.append(pd.Timestamp(ele[0], unit='ms', tz='Asia/Shanghai'))
1928-
columns=["close", "balance", "stocks", "fee", "net"]
1929-
if 'Futures_' in eid:
1930-
columns=[balanceName, "fee", "net"]
1878+
columns=["PnL"+margin_suffix, "Utilization(%)"]
19311879
return pd.DataFrame(pnl, index=index, columns=columns)
19321880

19331881
class Backtest():

0 commit comments

Comments
 (0)