Click here to Login








Multi Currency Stock Portfolio Backtesting - Beta 0.6

by SystemTrade, 4505 days ago
Share |






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.


Share This ->
Share |


You have to log in to bookmark this object
What is this?




Type: Advanced Money Management

Object ID: 1148


Country:


Market:

Style:

Reviews
You must log in first

Join now
and get instant access for free to the trading software, the Sharing server and the Social network website.
Click here


Related objects

Empty

Number of reviews
Click to add a review
Average rate
Click to rate this item
Number of times this object was downloaded
Number of rates the current object received
Report an object
if you can't run it for example or if it contains errors
Click to report this object

Technical Analysis


Fundamental Analysis



Random Blog Posts

Detect chart patterns using the auto support/resistance indicator

Getting Accurate Backtesting Results: Survivorship bias-free S&P 500

10 masks to create thousands of rules to use into your trading system

Trading System Analysis: Backtesting report and custom measures

How to predict and trade the stock market using pivot points

9 mistakes you should avoid when backtesting an end-of-day stock trading system

6 ways to download free intraday and tick data for the U.S. stock market

Reducing risk and increasing return by combining several trading systems

Show All

Number of reviews
Click to add a review
Average rate
Click to rate this item
Number of times this object was downloaded
Number of rates the current object received
Report an object
if you can't run it for example or if it contains errors
Click to report this object






QuantShare
Product
QuantShare
Features
Create an account
Affiliate Program
Support
Contact Us
Trading Forum
How-to Lessons
Manual
Company
About Us
Privacy
Terms of Use

Copyright © 2024 QuantShare.com
Social Media
Follow us on Facebook
Twitter Follow us on Twitter
Google+
Follow us on Google+
RSS Trading Items



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.