Now, let’s say you open a trade worth $50,000 with the same trading account size and leverage ratio. Your required margin for this trade would be $500 (1% of your position size), and your free margin would now also amount to $500. In other words, you could withstand a negative price fluctuation of $500 until your free margin falls to zero and causes a margin call. Your position size of $50,000 could only fall to $49,500 – this would be the largest loss your trading account could withstand.
The currency exchange rate is the rate at which one currency can be exchanged for another. It is always quoted in pairs like the EUR/USD (the Euro and the US Dollar). Exchange rates fluctuate based on economic factors like inflation, industrial production and geopolitical events. These factors will influence whether you buy or sell a currency pair.
If traders are positive on the prospects for the Yen, they would expect the number on the right to go down – i.e. the Yen would be getting stronger against the Dollar. Traders would be buying less Yen with a Dollar as the Yen got stronger. Similarly, if the Yen was expected to weaken, forex traders would expect the Yen number to go up, reflecting the fact that the dollar could buy more yen.
Unit Tests for Position/Portfolio - While I've not mentioned it directly in diary entries #1 and #2, I've actually been writing some unit tests for the Portfolio and Position objects. Since these are so crucial to the calculations of the strategy, one must be extremely confident that they perform as expected. An additional benefit of such tests is that they allow the underlying calculation to be modified, such that if all tests still pass, we can be confident that the overall system will continue to behave as expected.
As you may now come to understand, FX margins are one of the key aspects of Forex trading that must not be overlooked, as they can potentially lead to unpleasant outcomes. In order to avoid them, you should understand the theory concerning margins, margin levels and margin calls, and apply your trading experience to create a viable Forex strategy. Indeed a well developed approach will undoubtedly lead you to trading success in the end.
Equity – Your equity is simply the total amount of funds you have in your trading account. Your equity will change and float each time you open a new trading position, in such a way that all your unrealised profits and losses will be added to or deducted from your total equity. For example, if your trading account size is $1,000 and your open positions are $50 in profit, your equity will amount to $1,050.
Free margin in Forex is the amount of money that is not involved in any trade. You can use it to take more positions, however, that isn't all - as the free margin is the difference between equity and margin. If your open positions make you money, the more they achieve profit, the greater the equity you will have, so you will have more free margin as a result. There may be a situation when you have some open positions and also some pending orders simultaneously.
In a margin account, the broker uses the $1,000 as a security deposit of sorts. If the investor's position worsens and his or her losses approach $1,000, the broker may initiate a margin call. When this occurs, the broker will usually instruct the investor to either deposit more money into the account or to close out the position to limit the risk to both parties.
So, for an investor who wants to trade $100,000, a 1% margin would mean that $1,000 needs to be deposited into the account. The remaining 99% is provided by the broker. No interest is paid directly on this borrowed amount, but if the investor does not close their position before the delivery date, it will have to be rolled over. In that case, interest may be charged depending on the investor's position (long or short) and the short-term interest rates of the underlying currencies.
In particular I've made the interface for beginning a new backtest a lot simpler by encapsulating a lot of the "boilerplate" code into a new Backtest class. I've also modified the system to be fully workable with multiple currency pairs. In this article I'll describe the new interface and show the usual Moving Average Crossover example on both GBP/USD and EUR/USD.
The script is currently hardcoded to generate forex data for the entire month of January 2014. It uses the Python calendar library in order to ascertain business days (although I haven't excluded holidays yet) and then generates a set of files of the form BBBQQQ_YYYYMMDD.csv, where BBBQQQ will be the specified currency pair (e.g. GBPUSD) and YYYYMMDD is the specified date (e.g. 20140112).
In particular I would like to make the system a lot faster, since it will allow parameter searches to be carried out in a reasonable time. While Python is a great tool, it's one drawback is that it is relatively slow when compared to C/C++. Hence I will be carrying out a lot of profiling to try and improve the execution speed of both the backtest and the performance calculations.
To date, we've been experimenting with the OANDA Rest API in order to see how it compared to the API provided by Interactive Brokers. We've also seen how to add in a basic portfolio replication element as the first step towards a proper event-driven backtesting system. I've also had some helpful comments on both previous articles (#1 and #2), which suggests that many of you are keen on changing and extending the code yourselves.
Forex trading, also known as foreign exchange trading or currency trading, is where an investor tries to make money by buying and selling currencies on the foreign exchange market. Most investors will follow trends and use strategies to optimise their return. This is a very basic definition that does not reflect the full complexity of Forex trading; our free workshops are ideal for people who are unfamiliar with the concept and want to quickly achieve an in-depth insight into how this all works.
Monitoring and High Availability - Since we are considering a high-frequency intraday system, we must put comprehensive monitoring and high availability redundancy in place. This means reporting on CPU usage, disk usage, network I/O, latency and checking that any periodic scripts are set to keep running. In addition we need a backup and restore strategy. Ask yourself what backup plans you would have in place if you had large open positions, in a volatile market, and your server suddenly died. Believe me, it happens!
Not all securities can be bought on margin. Buying on margin is a double-edged sword that can translate into bigger gains or bigger losses. In volatile markets, investors who borrowed from their brokers may need to provide additional cash if the price of a stock drops too much for those who bought on margin or rallies too much for those who shorted a stock. In such cases, brokers are also allowed to liquidate a position, even without informing the investor. Real-time position monitoring is a crucial tool when buying on margin or shorting a stock.
Trading on margin refers to trading on money borrowed from your broker in order to substantially increase your market exposure. When opening a margin trade, your broker lends you a certain sum of money depending on the leverage ratio used, and allocates a small portion of your trading account as the collateral, or margin for that trade. The remaining funds in your trading account will act as your free margin, which can be used to withstand negative price fluctuations from your existing leveraged positions, or to open new leveraged trades. The relation between your free margin and other important elements of your trading account, such as your balance and equity, will be explained later. For now, it’s important to understand the meaning of margin in Forex.