Hi
I am new to Quantconnect and is testing a forex pairs trading strategy and puzzalling about profit calculation. I have two groups of trade -- Opening trade: long USDJPY, short GBPUSD. closing trade: short USDJPY, long GBPUSD. See orders log below:
TimeSymbolPriceQuantityTypeStatusValueTag2020-03-08T23:00:00ZGBPUSD1.30955-853MarketFilled-1117.04615 2020-03-08T23:00:00ZUSDJPY103.94718MarketFilled1871.046 2020-03-14T00:00:00ZGBPUSD1.22847853Market On OpenFilled1047.88491Liquidated2020-03-14T00:00:00ZUSDJPY107.837-18Market On OpenFilled-1941.066LiquidatedQuantconnect backtest shows a net profit of $69.82, no fees. However, the "Value" in log gives me $139.18 profit (GBPUSD:1117.04615-1047.88491 + USDJPY:1941.066-1871.046) Am I missing something?RegardsWei
Arthur Asenheimer
Hello Wei,
did you consider the spreads when you manually calculated the profit?
Otherwise, please attach a backtest so we can give further assistance.
Regards,
Arthur
Wei Cheng
Hello Arthur,
I cannot recreate exact backtest, attached is another example where "net profit" is shown as 72.6, no fees , no unrealized, however, my calculation from "Orders" is 93.7. I would have thougtht "orders" value already take into account the spreads? I used MarketOrder for long (positive unit) and short (negative unit), and Liquidate() for closing all positions.
Below is the orders:
Date TimeSymbolTypePriceQuantityStatusTag+2020-03-08 19:00:00GBPUSDSell MarketFill: $1.30955 USD
-1395Filled +2020-03-08 19:00:00USDJPYBuy MarketFill: ¥103.947 JPY
30Filled +2020-03-12 20:00:00GBPUSDBuy MarketFill: $1.25765 USD
1395FilledLiquidated+2020-03-12 20:00:00USDJPYSell MarketFill: ¥104.657 JPY
-30FilledLiquidatedArthur Asenheimer
Hello Wei,
you're right that spreads are already taken into account in the fill prices of the order list. Just wanted to say that spreads are not part of the fees and that's why you see fees = 0,00 USD.
However, I've an idea where the difference comes from.
You've calculated a Profit of 93.7 USD where 72.4 came from the GBP/USD trade and 21.3 from the USD/JPY trade. But you need to convert the profit from your USD/JPY trade to USD currency since it's generated in JPY (see screenshot).
So you actually have:
72.4 USD + 21.3 JPY = 72.4 USD + ( 21.3 JPY * 104.657 USD/JPY) = 72.4 USD + 0.2 USD = 72.6 USD
which is exactly the displayed net profit value of your backtest.
So remeber to convert back to your base currency (USD).
The orders summary also show that the profit of the USD/JPY trade is made in JPY (see screenshot).
Arthur Asenheimer
One more addition: Since QC supports only USD as account base currency I guess QC internally always convert the profit/loss when you close a FX position. If you have a multi-currency account (for example at IB), you would see something like this:
where the Total value is calculated by the current USD/JPY exchange rate.
Wei Cheng
Thanks Arthur, that make sense
Wei Cheng
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!