|
2 | 2 | # update P&L and account equity using delta of old and new P&L |
3 | 3 | new_pnl = calc_pnl_local(pos, close_price) |
4 | 4 | pnl_delta = new_pnl - pos.pnl_local |
5 | | - cash = cash_asset(acc, pos.inst.quote_symbol) |
6 | | - @inbounds acc.equities[cash.index] += pnl_delta |
| 5 | + quote_cash_index = pos.inst.quote_cash_index |
| 6 | + @inbounds acc.equities[quote_cash_index] += pnl_delta |
7 | 7 | pos.pnl_local = new_pnl |
8 | 8 | return |
9 | 9 | end |
|
24 | 24 | commission::Price=0.0, # fixed commission in quote (local) currency |
25 | 25 | commission_pct::Price=0.0, # percentage commission of nominal order value, e.g. 0.001 = 0.1% |
26 | 26 | )::Trade{TTime,OData,IData} where {TTime<:Dates.AbstractTime,OData,IData,CData} |
27 | | - # get quote asset |
28 | | - quote_cash = cash_asset(acc, order.inst.quote_symbol) |
| 27 | + # get quote asset index |
| 28 | + quote_cash_index = order.inst.quote_cash_index |
29 | 29 |
|
30 | 30 | # positions are netted using weighted average price, |
31 | 31 | # hence only one static position per instrument is maintained |
|
48 | 48 | realized_pnl = (fill_price - pos.avg_price) * realized_qty |
49 | 49 |
|
50 | 50 | # add realized P&L to account balance |
51 | | - @inbounds acc.balances[quote_cash.index] += realized_pnl |
| 51 | + @inbounds acc.balances[quote_cash_index] += realized_pnl |
52 | 52 |
|
53 | 53 | # remove realized P&L from position P&L |
54 | 54 | pos.pnl_local -= realized_pnl |
|
98 | 98 | pos.quantity = new_exposure |
99 | 99 |
|
100 | 100 | # subtract paid commissions from account balance and equity |
101 | | - @inbounds acc.balances[quote_cash.index] -= commission |
102 | | - @inbounds acc.equities[quote_cash.index] -= commission |
| 101 | + @inbounds acc.balances[quote_cash_index] -= commission |
| 102 | + @inbounds acc.equities[quote_cash_index] -= commission |
103 | 103 |
|
104 | 104 | # update P&L of position and account equity (w/o commissions, already accounted for) |
105 | 105 | update_pnl!(acc, pos, fill_price) |
|
0 commit comments