Hi,
as a relative newbie on Amibroke I´d like to do some tests on
pairstrading and market neutral strategies.
Therfore I have writte the following code to define a pair of 2 stocks
or a pair of stock/index to be traded. I want to go long in the one
and on the same time go short in the other stock.
The following code seems to work properly on a predefined pair.
But now I want to backtest a portfolio of pairs maybe 10-30 different
pairs! The pairs shoud be created dynamically by analysing
correlations etc.
I have no idea how to start this on portfolio level, so I hope
somebody here can help!
Regards
mmike
My pairstrading code:
Ticker1 = "GM";
Ticker2 = "F";
spread = Foreign( Ticker1, "C") - Foreign( Ticker2, "C");
Plot( spread, "spread", colorRed, styleOwnScale);
LongCond=Cross(spread, EMA(spread, 10) );
ShortCond=Cross( EMA(spread, 10), spread );
if (Name()== Ticker1)
{
Buy=LongCond;
Sell=ShortCond;
Short=Sell; Cover=Buy;
}
else if (Name()==Ticker2)
{
Buy=ShortCond;
Sell=LongCond;
Short=Sell; Cover=Buy;
}
PositionSize = -25;