<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.2" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>forex.thedaintyarchstudio.com</title>
	<link>http://forex.thedaintyarchstudio.com</link>
	<description>Strategy Programming for Automatic Trading</description>
	<pubDate>Tue, 26 Jun 2007 16:57:55 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2</generator>
	<language>en</language>
			<item>
		<title>Pairs Trading</title>
		<link>http://forex.thedaintyarchstudio.com/2007/06/07/pairs-trading/</link>
		<comments>http://forex.thedaintyarchstudio.com/2007/06/07/pairs-trading/#comments</comments>
		<pubDate>Thu, 07 Jun 2007 17:07:35 +0000</pubDate>
		<dc:creator>Maria Yu</dc:creator>
		
		<category><![CDATA[Pairs Trading]]></category>

		<guid isPermaLink="false">http://forex.thedaintyarchstudio.com/2007/06/07/pairs-trading/</guid>
		<description><![CDATA[One of the first things I learned in Forex was that currency pairs have relationships. Some          currencies tend to move in the same direction, some in inverse direction. These relationships are not hard to memorize, they are clearly indicated in my charts setup.

By looking at these [...]]]></description>
			<content:encoded><![CDATA[<p>One of the first things I learned in Forex was that currency pairs have relationships. Some          currencies tend to move in the same direction, some in inverse direction. These relationships are not hard to memorize, they are clearly indicated in my <a href="http://www.thedaintyarchstudio.com/img/forex/wcsetup.html" title="pairs trading chart setup" target="_blank">charts setup.</a></p>
<p><a href="http://www.thedaintyarchstudio.com/img/forex/wcsetup.html" target="_blank"><img src="http://www.thedaintyarchstudio.com/img/forex/wcsetup.png" alt="chart setup" /></a></p>
<p>By looking at these nine major pairs in my setup, how pairs move relatively to each other is seen directly and visually. I am grateful for my Forex teacher who taught me this setup from the very beginning.</p>
<p>The correlation between two pairs are determined by their correlation coefficient.  The correlation coefficient is always a value between +1 and -1.  When the correlation coefficient of two pairs is +1, these two pairs move in the same direction 100% of the time.  When the correlation coefficient of two pairs is -1, these two pairs move in the opposite direction 100% of the time. This <a href="http://fxtrade.oanda.com/currencyCorrelations/index.html" target="_blank" title="Currency Correlations Table">Currency Correlations Table</a> is updated daily.</p>
<p>Basically the correlation coefficients are computed from the currency prices. Their mean, standard deviation (variance) and covariance are what&#8217;s need in the computation.</p>
<p>I found there are different strategies in applying Pairs Trading to Forex:</p>
<blockquote><p> 1. Statistical Arbitrage</p>
<p>2. Avoid cancellation</p>
<p>3. Diversification</p>
<p>4. Verification</p></blockquote>
<p>Pairs Trading was initially used in equity trading. It is a market neutral strategy, meaning that the return from the strategy is uncorrelated with the market return. Applying Statistical Arbitrage to Forex is to trade two currency pairs at the same time, long one currency pair and short the other. Should two strongly correlated pairs substantially diverge from their statistical correlation they are expected to revert back to their mean. Profit is made in this mean-reverting move. This <a href="http://www.traderslog.com/trading-pairs.htm" title="trading-pairs" target="_blank">article</a> explains Pairs Trading very well.</p>
<p>If trading same positions on two currency pairs with an inverse relationship, these trades will eventually cancel each other. Take EURUSD and USDCHF as an example: the two pairs have a near 100% correlation of -1 , so if we long both and EURUSD rallies, we don&#8217;t make profit because USDCHF sells off.</p>
<p>On the other hand, pairs with a positive correlation move in the same direction but at a different pace. Different countries have different monetary policies, splitting orders  in different currencies may lower risks.</p>
<p>Market trend can be verified and confirmed in pairs with a strong correlation. One of my Forex teacher&#8217;s trader friend trades GBPUSD exclusively.  Once he does his technical analysis on the GBPUSD then he does the same on EURUSD, USDCHF, and USDJPY. If EURUSD shows the same trend he adds another lot to the GBPUSD. If USDCHF also shows the same thing he adds another lot to the GBPUSD. Then if USDJPY also says the same thing he adds another lot to the GBPUSD. Multiple confirmation!</p>
<p>In light of this powerful &#8220;Pairs Trading - Statistical Arbitrage&#8221; strategy I developed automated trading tools for my trading platform, MetaTrader 4. These programs are called Exper Advisors (EAs), they can  analyze the situation on the market, make decisions, open positions, move stops, take profits, and close trades. I will talk about my implementation first and then show my trading results.</p>
<p><strong>Implementation of Pairs_Trading_Forex</strong></p>
<p><strong>1.</strong> Select two statistically strongly correlated currency pairs.</p>
<p><strong>2.</strong>  Use price data of two time frames, one shorter time frame and one longer. The shorter time frame is for the Expert Advisor to attach to and is used to get the current prices. The longer period is used to compute the Mean and Standard Deviations, which are calculated in terms of price ratios of currency pair1 and pair2.</p>
<p><strong>3 .</strong> Set an entry point for the trade. It is suggested to enter when the price ratio of pair1 and pair2 is at least two standard deviations from their Mean. For testing purposes I used 1.5 and I got good results.</p>
<p><strong>4.</strong> Determine which pair goes long and which pair goes short.</p>
<p><strong>5.</strong> Check the 14-day RSI of the current price (I used close price) of pair1 and pair2. No trades are entered if the long candidate&#8217;s RSI is below 40 and the short candidate is over 60.</p>
<p><strong>6.</strong> Set the profit goal, ideally at 2 standard deviations above the entry, but I found for day traders 0.5 to 0.75  standard deviations were more reachable.</p>
<p><strong>7.</strong> Set the stop loss at 1.5 standard deviations below the entry.</p>
<p><strong>8.</strong> Determine the lot ratio of these two pairs. It should be the same dollar amount in both positions.</p>
<p><strong>9.</strong> I developed three versions of Pairs_Trading_Forex. One uses the simple moving averages to compute the Mean (I call this version Pairs_Trading_Forex_v2), one uses the bar close prices to compute the Mean (this version is Pairs_Trading_Forex_v3), and one uses <a href="http://www.cs.unc.edu/~welch/kalman/" target="_blank" title="kalman filtering">Kalman Filtering</a> to compute the current bar close prices and the Mean (this version is Pairs_Trading_KF). In my testing, when one version got triggered to enter a trade, the other ones would do the same, there might be just 1 or a couple pips apart.</p>
<p><strong>10.</strong> For testing purposes I programmed my Expert Advisors to move stops. When a pair has 10 pips of profit it&#8217;s stop is moved to break even (the entry) . At 25 pips of profit, the stop is at 10 pips of profit.</p>
<p><strong>Equilibrium Trading</strong></p>
<p>While developing my &#8220;Pairs_Trading_Forex&#8221; Expert Advisor I got an idea about an Equilibrium Trading startegy. I noticed in May that the market would move one direction and then reverse it&#8217;s direction back to a particular position. My Forex teacher also talked about this equilibrium behavior at our almost weekly tune-up meeting. But how do we find where this equilibrium or pivot is? I thought I could apply the idea of trading two strongly correlated pairs (pairs trading) to trading one pair, when this one pair is doing equilibrium moves. This is because any one currency pair is perfectly correlated with itself, that means its correlation coefficient is +1. Therefore, I could use the Mean computed from a longer time period, say day chart, and use it as the equilibrium that this pair is moving toward to. Just like the mean-reverting behavior occurring in two pairs trading, one single pair could be oscillating back and forth about its longer time Mean. Yesterday (June 6, 2007) when I was testing my Expert Advisor for Equilibrium Trading I got the same Mean from week chart and day chart for the USDCAD.</p>
<p><strong>Math + Art = More</strong></p>
<p>One realization I got while reading Ganapathy&#8217;s <a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;location=http%3A%2F%2Fwww.amazon.com%2FPairs-Trading-Quantitative-Methods-Analysis%2Fdp%2F0471460672%3Fie%3DUTF8%26s%3Dbooks%26qid%3D1181400996%26sr%3D1-4&amp;tag=artlifespirit-20&amp;linkCode=ur2&amp;camp=1789&amp;creative=9325" target="_blank">&#8220;Pairs Trading&#8221;</a><img src="http://www.assoc-amazon.com/e/ir?t=artlifespirit-20&amp;l=ur2&amp;o=1" style="border: medium none  ! important; margin: 0px ! important" border="0" height="1" width="1" /> book was that all the analysis, Math, modeling, computation in trading were so similar to my Master&#8217;s and PhD&#8217;s research work in contact mechanics. The time series and Kalman filitering techniques reminded me so much of my cyclic loading curves and kinematic-hardening, shakedown, ratcheting, incremental projection, and steady-state methods. Here is the link to get a picture of my <a href="http://forex.thedaintyarchstudio.com/category/math-work/" target="_blank">Math work</a>.</p>
<p><strong>Trading Results</strong></p>
<p><em>June 5, 2007 Tuesday</em></p>
<p>I started testing my automated Pairs Trading (Statistical Arbitrage) and Equilibrium Trading programs on Tuesday morning, June 5, 2007. While testing I was still making adjustments.</p>
<p>The GBPUSD and EURUSD got entered for pairs trading. In the beginning it was a loss but it then turned green. These trades were triggered by Pairs_Trading_Forex_v2. The screen shots of the <a href="http://www.thedaintyarchstudio.com/img/forex/gbpeur605.html" title="GBP and EUR">trades</a> and the <a href="http://www.thedaintyarchstudio.com/img/forex/eurusdday605.html" title="EUR day chart">EURUSD day chart</a> can be viewed here. These trades I just used 1 lot for each pair, but I should have calculated their lot ratio. Their correlation of this week was good so I used 500 trading days (+0.97) to compute their Mean and Standard Deviation. The <a href="http://www.thedaintyarchstudio.com/img/forex/pt_input.html" title="input GUI">user input</a> are shown in the GUIs. The Magic_Number is a number for me to identify which Expert Advisor (EA)  I am testing and which chart the EA is attached to. It is also a number for the EA to manage and operate on the opened positions of these trades. A profit of $110.</p>
<p>The USDJPY and USDCAD got triggered independently for Equilibrium Trading. These <a href="http://www.thedaintyarchstudio.com/img/forex/jpycad605.html" title="jpycad">three screen captures</a> show the progression of the trades. Notice that in the third image the stop of USDCAD is at the entry. I programed my Expert Advisor to move the stop to the entry when a pair moves 10 pips. At 25 pips of profit, the stop will be moved to protect 10 pips of profit. The user <a href="http://www.thedaintyarchstudio.com/img/forex/eq_input.html" title="input GUI">input GUI</a> is captured here. And a screen shot of the USDCAD&#8217;s <a href="http://www.thedaintyarchstudio.com/img/forex/cad605wc.html" title="CAD day chart">day chart</a> from the charting system I subscribe.</p>
<p><em>June 6, 2007 Wednesday</em></p>
<p>The (EURUSD, USDCHF) pairs and (EURUSD, AUDUSD) pairs got triggered for Pairs Trading. I was testing  two versions of Pairs Trading EA, Pairs_Trading_Forex_v2 and Pairs_Trading_Forex_KF. The (EURUSD, AUDUSD) was triggered by both EAs but the (EURUSD, USDCHF) was only triggered by Pairs_Trading_Forex_KF. Ths might be due to earlier there was not enough money in the account to buy another (EURUSD, USDCHF). I closed a few trades before the (EURUSD, AUDUSD) got in. The <a href="http://www.thedaintyarchstudio.com/img/forex/correlation_table606.html">correlation table</a> for the day is here and the <a href="http://www.thedaintyarchstudio.com/img/forex/fa606.html">Fundamental Announcements.</a> The screen captures of the trades are shown progressively on this <a href="http://www.thedaintyarchstudio.com/img/forex/6_06_all.html" target="_blank">page.</a> A profit of $540.64.</p>
<p><em>June 7, 2007 Thursday</em></p>
<p><a href="http://www.thedaintyarchstudio.com/img/forex/6_07_all.html" target="_blank"><img src="http://www.thedaintyarchstudio.com/img/forex/6_07_07_all_profit_big.png" alt="$2000" /></a></p>
<p>I woke up this morning and saw the Pairs Trading trades entered last night having a profit of <a href="http://www.thedaintyarchstudio.com/img/forex/6_07_all.html">over $2000 dollars.</a> The (EURUSD, USDCHF) pairs got triggered by both the Pairs_Trading_Forex_v2 and Pairs_Trading_Forex_KF EAs. The (GBPUSD, AUDUSD) pairs got entered at 9:05 AM. Later at 5:25 PM the profit was <a href="http://www.thedaintyarchstudio.com/img/forex/6_07_gbpaud.html">$797.20.</a></p>
<p>A different <a href="http://www.thedaintyarchstudio.com/img/forex/6_07_gbpwc.html">chart setup </a>and the <a href="http://www.thedaintyarchstudio.com/img/forex/correlation_tablegbp.html">correlation table</a> for the GBPUSD are linked.</p>
<p>USDCHF entered Equilibrium Trading. I have two versions of EA, Equilibrium_Trading_v2 and Equilibrium_Trading_v3. The only difference is just the computation of the current price, v2 uses the bar close price, while v3 uses the average of ASK and BID prices. Both trades were triggered when the pairs&#8217; 14-day RSI was below 60. However, <a href="http://www.thedaintyarchstudio.com/img/forex/6_07_eq_chf.html">USDCHF</a> later climbed up to RSI &gt; 70 so both trades were losses.</p>
<p><strong>Conclusions</strong></p>
<p>If I could make $2000 dollars while sleeping I would say Pairs Trading is magic. Here are my findings from my testing, comments from all traders are welcome.</p>
<p><strong>1.</strong> Currency pairs maintain their correlation from time to time. If two pairs deviate from their relationship they try to go back to the statistical or historical correlation coefficient.</p>
<p><strong>2.</strong> Each currency pair is perfectly correlated with itself, it maintains its own equilibrium by oscillating back and forth about this equilibrium.</p>
<p><strong>3.</strong> Both the Pairs Trading Expert Advisor and the Equilibrium Trading Expert Advisor get triggered to enter trades. The currency pair triggered by the Pairs Trading EA may or may not be triggered by the Equilibrium Trading EA. Likewise, the pair triggered by the Equilibrium Trading EA may or may not be triggered by the Pairs Trading EA. When a pair really moves with momentum, most likely both EAs will be triggered. A few screen captures <a href="http://www.thedaintyarchstudio.com/img/forex/6_08_eq.html">here</a>  show the trades entered by the Equilibrium Trading EA.</p>
<p><strong>4.</strong> Using the correlation between two pairs is a good strategy to trade, so is using the correlation of a pair with itself. I do not know which correlation plays a more important role, it might change from time to time. Is it because a pair maintains its own equilibrium so it maintains its correlations with other pairs or is it because it observes its correlations with other pairs so it maintains its own equilibrium? The Market is a correlated place, so a pair might have to do both. It would be possible to trade just one pair against itself rather than adding a different pair with an opposite position, if the Equilibrium correlation is strong. Even so, the correlation between two pairs may have influences in determining the trading ranges.</p>
<p><strong>5.</strong> Checking the Correlation Table regularly is helpful in making trade decisions. If I see two currency pairs&#8217; one week correlation being close to their 1-year or 2-year correlation I know these two pairs probably will not be triggered by my Expert Advisors. If I see day by day two pairs&#8217; one week correlation getting closer to their longer time correlation I know there might be trading opportunities coming.</p>
<p><strong>6.</strong> Taking profit of Pairs Trading at 0.5 Standard Deviation or lower might be more realistic for intraday trading.</p>
<p><strong>7.</strong> Construct the pairs trading portfolio in terms of equal amount of dollar (or any one currency) on both the long and short position. I have seen in my testing that if I just traded one lot for each pair in the pairs&#8217; trades regardless of the dollar amount in each position, it took longer to get profit if not never.</p>
<p><strong>8.</strong> Need to have enough margin to do Pairs Trading. The idea of Pairs Trading is to trade two pairs at the same time, one goes long and the other goes short. When there is not enough money to execute the second trade after the first trade being executed  it breaks the strategy. Or when there is a margin call, the broker might take out one of the pairs&#8217; trades. Here is an example: I was running multiple EAs on multiple pairs this morning (June 8, 2007) on my demo account so there wasn&#8217;t enough money to buy USDCHF for (ERUUSD, USDCHF) at 1:1.62 lot ratio and to buy AUDUSD for (ERUUSD, AUDUSD) at 1:1.65 lot ratio. I ended up having multiple EURUSDs at 1 lot. Luckily, these EURUSDs were on the green side so I actually made a <a href="http://www.thedaintyarchstudio.com/img/forex/6_08_alleur.html">profit.</a> This <a href="http://www.traderslog.com/trading-pairs.htm" target="_blank" title="trading-pairs">article</a> suggests entering the sell position first, I don&#8217;t know if that makes a difference in Forex.</p>
<p><strong>9.</strong> The Pairs Trading and Equilibrium Trading strategies work well when there is momentum in the market. They may not do well at Fundamental announcements. Entering late might be better to avoid picking up false signals.</p>
<p><strong>10.</strong> The Pairs Trading and Equilibrium Trading Expert Advisors help me make trading decisions. I could just run the EAs on a demo account, when I see the trades starting making profits steadily I know the converging trend is on the way and I can enter trades confidently in the right positions on both pairs. On the other hand, if the pairs&#8217; trades keep losing money I know I should enter my trades in their reverse positions. These pairs&#8217; trades can also confirm my technical analysis, and when I see <a href="http://www.thedaintyarchstudio.com/img/forex/6_07_chfwc.html">momentum arrows </a>in my trading charts, I know I can add more lots.</p>
<p><strong>References</strong></p>
<p><a href="http://www.proacttraders.com/our_charts.html" target="_blank">ProAct Traders Visual Charting System</a></p>
<p><a href="http://fxtrade.oanda.com/currencyCorrelations/index.html" target="_blank">Currency Correlations Table</a></p>
<p><a href="http://www.investopedia.com/articles/trading/04/090804.asp" target="_blank">Finding Profit in Pairs</a></p>
<p><a href="http://www.traderslog.com/trading-pairs.htm" target="_blank" title="trading-pairs">Trading Pairs</a></p>
<p><a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;location=http%3A%2F%2Fwww.amazon.com%2FPairs-Trading-Quantitative-Methods-Analysis%2Fdp%2F0471460672%3Fie%3DUTF8%26s%3Dbooks%26qid%3D1181400996%26sr%3D1-4&amp;tag=artlifespirit-20&amp;linkCode=ur2&amp;camp=1789&amp;creative=9325">&#8220;Pairs Trading&#8221; by Ganapathy Vidyamurthy</a><img src="http://www.assoc-amazon.com/e/ir?t=artlifespirit-20&amp;l=ur2&amp;o=1" style="border: medium none  ! important; margin: 0px ! important" border="0" height="1" width="1" /></p>
<p><a href="http://www.cs.unc.edu/~welch/kalman/" target="_blank">Kalman Filter</a></p>
<p><a href="http://www.cs.unc.edu/~welch/kalman/" target="_blank"></a><a href="http://www.learnmoney.co.uk/spread-betting/pairs-1.html" target="_blank">Spread Bet Uses - Pairs Trading</a></p>
<p><a href="http://www.investopedia.com/articles/forex/05/051905.asp" target="_blank">Use Currency Correlations To Your Advantage</a></p>
<p><a href="http://www.pairtrader.com/subject2.html" target="_blank">What is Pair Trading</a></p>
]]></content:encoded>
			<wfw:commentRss>http://forex.thedaintyarchstudio.com/2007/06/07/pairs-trading/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Math Work</title>
		<link>http://forex.thedaintyarchstudio.com/2007/06/07/math-work/</link>
		<comments>http://forex.thedaintyarchstudio.com/2007/06/07/math-work/#comments</comments>
		<pubDate>Thu, 07 Jun 2007 13:00:34 +0000</pubDate>
		<dc:creator>Maria Yu</dc:creator>
		
		<category><![CDATA[Math Work]]></category>

		<guid isPermaLink="false">http://forex.thedaintyarchstudio.com/2007/06/07/math-work/</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[
]]></content:encoded>
			<wfw:commentRss>http://forex.thedaintyarchstudio.com/2007/06/07/math-work/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
