Page 1 of 1

Found this ela Strategy in a book and can not compile it.

Posted: 06 Jan 2011
by Locust
Produces the error, expecting bars.


Strategy:

Inputs: Price1(Close of data3), Price2(Close of data4), StandartDev(1.5), Lenght(30), Equity(100000), RiskModel(3), RiskPercent(2.0), RiskATR(1.0),LogTrades(False),LogFile("Orders.txt");
Variables: N(0), HV1(0), HV2(0), CV(0), VolBand(0), VolConstant(0.0523),UpperBand(0), LowerBand(0), Spread(0);

if date <> date[1] then begin
N=LOCGetSharesFunc(Equity, RiskModel, RiskPercent, RiskATR) of data3;
HV1= LOCVolatilityFunc(Lenght) of data3;
HV2= LOCVolatilityFunc(Lenght) of data4;
CV= Correlation(Price1, Price2, Lenght);
VolBand=VolConstant*(HV1+HV2)*(1-CV);
UpperBand=StandartDev*VolBand;
LowerBand=StandartDev*(-VolBand);
end;
Spread = ((Close of data1 / Price1) -(Close of data2 / Price2));

if Spread crosses_above LowerBand then
Buy("LOCPT LE") n shares next bar at market;

if Spread crosses_above 0 then
sell("LOCPT LX+") next bar at market
else if Spread <= StandartDev*LowerBand then
Sell("LOCPT LX-") next bar at market;

if Spread crosses_below UpperBand then
sellshort("LOCPT SE") n shares next bar at market;

If Spread crosses_below 0 then
buy("LOCPT SX+") next bar at market
else if Spread >= StandartDev*UpperBand then
buy("LOCPT SC-") next bar at market;

Function:

Inputs: Lenght(Numeric);
variables: DaysInYear(365),DaysInMonth(30),DaysInWeek(7),TimeFactor(0.0);
LOCVolatilityFunc=0;
if close>0 and close[1]>0 then begin
if datacompression>=2 and datacompression <5 then begin
if datacompression =2 then
TimeFactor=DaysInYear
else if datacompression=3 then
TimeFactor=DaysInYear/DaysInWeek
else if datacompression=4 then
TimeFactor=DaysInYear/DaysInMonth;

LOCVolatilityFunc=StdDev(Log(Close/Close[1]), Lenght)*SquareRoot(TimeFactor);
end;
end;

Inputs: Equity(numeric),RiskModel(numeric),RiskPercent(numeric),RiskUnits(numeric);
Variables: MinimumShares(200),RiskShares(0),ERP(0),Lenght(20);
ERP= Equity*RiskPercent/100;
If RiskModel=1 and Close>0 then
RiskShares=maxlist(MinimumShares,100*IntPortion(Equity/(100*Close)));
If RiskModel=2 and RiskUnits>0 then
RiskShares=maxlist(MinimumShares,100*IntPortion(Equity/(100*RiskUnits)));
If RiskModel=3 and Volatility(Lenght)>0 then
RiskShares=maxlist(MinimumShares,100*IntPortion(Equity/(100*Volatility(Lenght))));

Re: Found this ela Strategy in a book and can not compile it

Posted: 06 Jan 2011
by TJ
>Found this ela Strategy in a book and can not compile it.

where did you find it?
what is the name?
what does it do?
any descriptions will help save a lot of time beating around the bush in the dark.

please copy and paste the error message.



ps: pls enclose the code with code tag.
the code tag button is at the top of the message window

Re: Found this ela Strategy in a book and can not compile it

Posted: 06 Jan 2011
by Locust
I found it in : " Professional Stock Trading: System Design and Automation" by Conway.

The function are meant to a.) calculate the volatility and b.) calculate how many share to trade
The strategy is a basic pair-trader, based on a correlation-band.

Function a.)

Code: Select all

Inputs: Lenght(Numeric);
variables: DaysInYear(365),DaysInMonth(30),DaysInWeek(7),TimeFactor(0.0);
LOCVolatilityFunc=0;
if close>0 and close[1]>0 then begin
if datacompression>=2 and datacompression <5 then begin
if datacompression =2 then
TimeFactor=DaysInYear
else if datacompression=3 then
TimeFactor=DaysInYear/DaysInWeek
else if datacompression=4 then
TimeFactor=DaysInYear/DaysInMonth;

LOCVolatilityFunc=StdDev(Log(Close/Close[1]), Lenght)*SquareRoot(TimeFactor);
end;
end;
Function b.)

Code: Select all

Inputs: Equity(numeric),RiskModel(numeric),RiskPercent(numeric),RiskUnits(numeric);
Variables: MinimumShares(200),RiskShares(0),ERP(0),Lenght(20);
ERP= Equity*RiskPercent/100;
If RiskModel=1 and Close>0 then
RiskShares=maxlist(MinimumShares,100*IntPortion(Equity/(100*Close)));
If RiskModel=2 and RiskUnits>0 then
RiskShares=maxlist(MinimumShares,100*IntPortion(Equity/(100*RiskUnits)));
If RiskModel=3 and Volatility(Lenght)>0 then
RiskShares=maxlist(MinimumShares,100*IntPortion(Equity/(100*Volatility(Lenght))));
Strategy:

Code: Select all

Inputs: Price1(Close of data3), Price2(Close of data4), StandartDev(1.5), Lenght(30), Equity(100000), RiskModel(3), RiskPercent(2.0), RiskATR(1.0),LogTrades(False),LogFile("Orders.txt");
Variables: N(0), HV1(0), HV2(0), CV(0), VolBand(0), VolConstant(0.0523),UpperBand(0), LowerBand(0), Spread(0);

if date <> date[1] then begin
N=LOCGetSharesFunc(Equity, RiskModel, RiskPercent, RiskATR) of data3;
HV1= LOCVolatilityFunc(Lenght) of data3;
HV2= LOCVolatilityFunc(Lenght) of data4;
CV= Correlation(Price1, Price2, Lenght);
VolBand=VolConstant*(HV1+HV2)*(1-CV);
UpperBand=StandartDev*VolBand;
LowerBand=StandartDev*(-VolBand);
end;
Spread = ((Close of data1 / Price1) -(Close of data2 / Price2));

if Spread crosses_above LowerBand then
Buy("LOCPT LE") n shares next bar at market;

if Spread crosses_above 0 then
sell("LOCPT LX+") next bar at market
else if Spread <= StandartDev*LowerBand then
Sell("LOCPT LX-") next bar at market;

if Spread crosses_below UpperBand then
sellshort("LOCPT SE") n shares next bar at market;

If Spread crosses_below 0 then
buy("LOCPT SX+") next bar at market
else if Spread >= StandartDev*UpperBand then
buy("LOCPT SC-") next bar at market;
The error code is:

------ Compiled with error(s): ------
syntax error, expecting 'bars'
errLine 0, errColumn 0, errLineEnd 0, errColumnEnd 0
causal study: (Function)

Any help would be appreciated,
Regards

Locust

Re: Found this ela Strategy in a book and can not compile it

Posted: 06 Jan 2011
by TJ
you are missing this function -- LOCGetSharesFunc

I don't think function "b" is needed.

Re: Found this ela Strategy in a book and can not compile it

Posted: 06 Jan 2011
by Locust
That was meant to be function b.
I just see, there is no result. Adding to the end of the code
LOCGetShareFunc=RiskShares;
Does not change the compiling issue.

Locust.

Re: Found this ela Strategy in a book and can not compile it

Posted: 06 Jan 2011
by TJ
That was meant to be function b.
I just see, there is no result. Adding to the end of the code
LOCGetShareFunc=RiskShares;
Does not change the compiling issue.

Locust.
then you have save function "b" with the name "LOCGetShareFunc".

Re: Found this ela Strategy in a book and can not compile it

Posted: 06 Jan 2011
by Locust
I did that already.

Locust

Re: Found this ela Strategy in a book and can not compile it

Posted: 08 Jan 2011
by piranhaxp
May there is an syntax error :

Please use as function name "LOCGetSharesFunc" instaed of "LOCGetShareFunc" like you wrote. Further please delete the underscore in the crosses_above & crosses_below rules. Otherwise EL uses it as a true/false-rule which is not defined.

This already compiled :

Code: Select all

Inputs: Price1(Close of data3), Price2(Close of data4), StandartDev(1.5), Lenght(30), Equity(100000), RiskModel(3), RiskPercent(2.0), RiskATR(1.0),LogTrades(False),LogFile("Orders.txt");
Variables: N(0), HV1(0), HV2(0), CV(0), VolBand(0), VolConstant(0.0523),UpperBand(0), LowerBand(0), Spread(0);

if date <> date[1] then begin
N=LOCGetSharesFunc(Equity, RiskModel, RiskPercent, RiskATR) of data3;
HV1= LOCVolatilityFunc(Lenght) of data3;
HV2= LOCVolatilityFunc(Lenght) of data4;
CV= Correlation(Price1, Price2, Lenght);
VolBand=VolConstant*(HV1+HV2)*(1-CV);
UpperBand=StandartDev*VolBand;
LowerBand=StandartDev*(-VolBand);
end;
Spread = ((Close of data1 / Price1) -(Close of data2 / Price2));

if Spread crosses above LowerBand then
Buy("LOCPT LE") n shares next bar at market;

if Spread crosses above 0 then
sell("LOCPT LX+") next bar at market
else if Spread <= StandartDev*LowerBand then
Sell("LOCPT LX-") next bar at market;

if Spread crosses below UpperBand then
sellshort("LOCPT SE") n shares next bar at market;

If Spread crosses below 0 then
buy("LOCPT SX+") next bar at market
else if Spread >= StandartDev*UpperBand then
buy("LOCPT SC-") next bar at market;


Hope it helped.
Regards.

Mike