A friend recently highlighted to me that when he ran a backtest on PyInvesting with both US and Hong Kong stocks, the backtester did not account for the currency differences. As a result, the simulated portfolio’s performance was incorrect because it did not handle the forex fluctuations between US and Hong Kong stocks.
I’ve been putting off this fix for a while because it was not easy to implement with many details that needed to be handled. However, I decided to implement this feature this week because it was requested by a number of my users and it would be useful going forward as I introduce stocks from other countries into my database.
Being able to handle the forex fluctuations between stocks of different currencies meant that I needed to convert the prices of every stock into a single currency before feeding the prices into the backtester. For example, if a backtest was done using stocks from the US and Hong Kong, I would convert the historical prices of all the Hong Kong stocks from HKD into USD using the HKD/USD historical FX times series. This would make the stocks from different countries comparable with each other and account for the currency differences.
The result of this change is that the net asset value (NAV) of the backtested portfolio will now be in USD and we can observe the performance of our investment strategy in terms of USD. However, what happens if a user is based in Singapore and would like to find out how his investment strategy performs in SGD terms?
The next step would be to convert the historical performance of the backtested strategy from USD into the preferred currency of the user, also known as the base currency. To do that, I have added a drop down menu on every backtest form page, where the user will have to select the base currency for the backtest. Next, PyInvesting will convert the performance numbers from USD to the user’s selected base currency.
Users can also change the base currency on the results page by clicking on the currency shown in the screenshot above. This would allow them to observe how the performance of their investment strategy changes when viewed from the perspective of a different currency. For example, as the Singapore dollar has appreciated against the US dollar over the last 15 years, the performance of an investment strategy in SGD terms will be worse than the performance of an investment strategy in USD terms.
The final impact of this feature update is that the base currency that the user selects will also be applied to the portfolio value which the user inputs when going live with their investment strategy. When users click on “Go live with this strategy” as shown in the screenshot above, PyInvesting will run their strategy daily with live prices and send live orders to users so they can profit from their investment strategy. To calculate the quantity of lots that users need to buy and sell on their personal account, PyInvesting will prompt users to input the size of their portfolio. This portfolio value will be based on the currency selected by the user. If the user selects SGD for example, this portfolio value shown in the screenshot below will be $10k SGD which is used to determine the number of lots to buy or sell for each stock in the user’s personal portfolio.
I’m glad that this feature has finally been rolled out. It was not an easy one to implement and I hope that it will be helpful for users that invest in stocks across different currencies by automatically handling the forex fluctuations for them. I would love to hear your thoughts on this new feature. Do check it out and let me know what you think on the PyInvesting forum (https://pyinvesting.com/forum/).
Happy investing, and may the odds be in your favour.
If you want to develop an effective investment strategy, learning how to utilize the results of backtesting can be one of the best decisions you ever make since backtesting can help you identify an incorrect or correct investment before your money is on the line. PyInvesting is a backtesting platform that helps investors go live with their investment strategies on the cloud without writing a single line of code.
© PyInvesting 2024