This is a trading item or a component that was created using QuantShare by one of our members.
This item can be downloaded and used by QuantShare Trading Software.
Trading items are of different types. There are data downloaders, trading indicators, trading systems, watchlists, composites/indices...
You can use this item and hundreds of others for free by downloading QuantShare.
Top Reasons Why You Should Use QuantShare:
Works with US and international markets (stock, forex, options, futures, ETF...)
Offers you the tools that will help you become a profitable trader
Allows you to implement any trading ideas
Exchange items and ideas with other QuantShare users
Our support team is very responsive and will answer any of your questions
We will implement any features you suggest
Very low price and much more features than the majority of other trading software
For Free - No Credit Card Required
Multi Currency Stock Portfolio Backtesting - Beta 0.6
This script allows backtesting of stock portfolios in different currencies and/or conversion of backtesting results to a different reporting currency. It works - but as it is quite complex, I would like to have it tested by the community under different environments before releasing it finally. This is why I consider it a Beta version for the moment.
Prerequisites:
1. Your symbols need to have a currency code in symbol master data
2. You need to have currency symbols in your symbols database with price information in the same timeframe as the stocks you are trading.
The following input variables are provided:
1. Method:
Depending on your trading system the interpretation of orders can be different. Given that your trading system generates an order of 1000 shares at a price of 20 USD and your base currency is EUR where the exchange rate EUR/USD is 1.25 the methods will have the following meaning:
a) "System provides B/C, NbShares converted to T/C": it is assumed that you want to spend 20000 EUR, number of shares will be adjusted to 1250
b) "System provides B/C, NbShares unchanged": it is assumed that you want to spend 20000 EUR, number of shares remains 1000
c) "System provides T/C, NbShares unchanged": it is assumed that you want to spend 20000 USD, number of shares remains 1000
2. Reject Position: In case of insufficient cash to open a position, select "Yes", if you want the position to be entirely rejected or select "No" if you want the number of shares to be reduced.
3. Symbol Pattern: specify the pattern of the currency symbols in your database here, e.g. if your symbols are like EURUSD=X (e.g. from Yahoo), then enter "FX1FX2=X" here, if your symbols are like EURUSD (e.g. from Google), then enter "FX1FX2" here. Generally you can use any pattern like "preFX1midFX2post", but make sure that you have the codes FX1 and FX2 in the pattern.
4. Base Currency: put your Base Currency (Reporting Currency) here, e.g. EUR, USD .
5. Timeframe (Historical or Intraday): lets you select daily or intraday timeframe
6. Seconds: enter seconds in one unit of your timeframe, e.g. 1h = 3600, if you have selected historical timeframe, then this variable is meaningless
How it works:
The OnNewPositon events adjusts the number of shares if foreseen in the method you have chosen. Then available cash is checked and the order might be rejected or reduced.
In the OnEndPeriod event currency effects will be calculated and adjusted to cash. For each position the custom variables Var3 (number of shares in transaction currency) and Var4 (cash adjustment) will be defined.
The following example will outline the calculation of currency effects:
Base currency is EUR, method is "System provides B/C, NbShares unchanged"
Buy 1000 shares at 20 USD
Sell 1000 shares at 25 USD
Exchange rate EUR/USD is 1.25 on signal date, 1.26 on entry date and 1.27 on exit date.
a) Number of shares in transaction currency (Var3) will be calculated internally (not updated!) based on the exchange rate of the signal date.
Var3 = 1000 x 1.25 = 1250
b) On Entry, QuantShare will calculate 1000 x 20 = 20000
The script calculates 1250 x 20 / 1.26 = 19841 EUR.
The difference of 20000 - 19841 = 159 EUR will be added to cash and saved in Var4.
c) On Exit, QuantShare will calculate 1000 x 25 = 25000
The script calculates 1250 x 25 / 1.27 = 24606 EUR.
The difference of 24606 - 25000 = -394 EUR will be taken from cash and Var4 will become 159 - 394 = -235 EUR.
So the final profit (ex commissions) is 25000 - 20000 - 235 = 4765 EUR = 24606 - 19841
Output:
You will have the total currency effect in report metrics ("Total FX G/L")
For each position the following metrics are provided:
Entry Price in transaction currency
Exit Price in transaction currency
Position value in transaction currency at entry
Currency gain/loss
Number of shares in transaction currency
Net Profit in base currency (exculding commissions)
Notes:
Only orders that are pushed through the money management script are considered.
The script uses the AddCash function in the OnEndPeriod. This cash adjustment will be effective in the next period, which will lead to a delay in your equity curve.
The script uses custom variables Var3 and Var4. If you use other scripts simultaneously, make sure that those variables do not interfere.
As the profit per position does not include commissions, it is suggested that you define a simulator metric like "Fitness = TotalProfit + TotalLoss - TotalTradingCosts + (double)Global.GetVariable("Total FX G/L");" to get the total result including commissions and currency effects.
Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.