FX trading base currency problem
This might be a newbie only problem, but I am not quite sure when I backtest my strategy, how can I set base currency and product currency to manage my PnL to have all them in a single base currency. Can anyone give me some hit or any crafted code to use for this?
(eg, USD.JPY trade in JPY amount per 1 USD, after the closing of a holding position, my profit or loss result is in JPY. I want to have it in USD.)
You can just take the last JPYUSD close price and perform a currency conversion at that price.
For example, if the last close was 100 JPY to 1 USD and your profit was 500 JPY, then you made 5 USD profit.
It gets more complex if your account currency is in USD and you were trading GBPEUR or something without USD. In that case, you would need to add another currency feed to the system and then do a conversion from the feed with the USD pair.
Many thanks for your reply!
I understand that I need to e.g usd.jpy divide the profit by the price when close out the position to get profit in usd, but I wonder if there are any built-in functions or parameters that I could use or adjust to achieve this? If so, could you please hit me which file I should change or looking at? Or I need to create my own profit & loss function?
Another thing is that, I load data from IB and store in Ib.store, and use it for my backtest directly from the store. I noticed that the plot after the backtests that have been done this way doesn’t really plot out the buy and sell points which the code that provided in the QuickStart does. Is there any solution for that? Or I need to load data to a cav file first and then feed it to backtrader? Do you have any idea?
Thanks a lot Dave.
I have the same problem and have also not yet found an easy solution for that. Would be great if someone in the community that has solved this issue could share his/her approach.
I first thought about just adding two trades that would (in your example) basically convert the "base currency" exposure from USD to JPY. However, in this approach one would have twice as much invested capital per position, portfolio composition gets really messy, etc.
So I am still trying to find a practical solution as well :-)
@jimmyliu Have you found any other solution to your problem? I am facing the same issue here.
Not sure if this is the ideal method, but I would load any traded assets in the same base currency (eg use Unhedged asset prices - so if your stock costs 200JPY, the price data you load is 1.8USD), then have an additional line/datafeed with the local currency prices for any analysis.
So for example run your SMA Crossover indicator on the local prices, but buy/sell the USD denominated asset.
Hope that helps!
Brandon Johnson last edited by
@jimmyliu @ThatBlokeDave @BernardLin @jf @Amien-Johaadien this may have been an addition since this thread was started - but using the a
CommInfoobject you can set
multto scale your profit/loss. In the FOREX sense, you can update your commission scheme during
nextwith the relevant exchange rate in order to 'scale' your profits/losses back to your account currency.