[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RT] Re: Mutual fund switching



PureBytes Links

Trading Reference Links

At 11:43 AM -0400 6/16/00, HBernst963@xxxxxxx wrote:

>With the advent of Rydex sector funds two years ago, I've been doing
>more and more sector switching. But I have a problem. Tradestation is
>only built to trade data 1. With sector switching you need to trade
>any of your data depending on which one gives a buy signal. Has
>anyone been able to program Tradestation to allow trading from other
>data besides data 1? Any help would be appreciated.

I built a system a while back that would trade up to 30 of the Fidelity Select funds, selecting the ones that were moving the fastest and buying the five fastest moving funds.

I recently did the same thing for trading a basket of commodities, optimizing the use of capital to maximize the Sharpe Ratio of the overall portfolio. It also worked OK.

The trick is that you have to keep track of all of your positions and do all of the accounting in your code and not use the trading capacity of TradeStation at all.

In addition, you have to use arrays for everything and use "for" loops to cycle through the system rules for each symbol (You can refer to "Close of data(j)" where "j" is the index of the loop, etc.)

An example of the code to do the accounting is listed below:

{------Update Accounting-----}
for j = 1 to NumP begin

   MP[j] = nMP[j];                  {Update MarketPositions}

   if (MP[j] = +1 or MP[j] = -1) and MP[j][1] = 0 then begin
      ePrice[j] = Open of data(j);
      eDate[j] = Date of data(j);
   end;

   if MP[j] = 0 and MP[j][1] = +1 then begin
      posProfit = Num[j] * (Open of data(j) - ePrice[j])
         * BigPointValue of data(j);
      nProfit[j] = nProfit[j] + posProfit;
      tProfit = tProfit + posProfit;
      Print(EDate[j]:7:0, Date of data(j):8:0, j:3:0, " XL",
         Num[j]:3:0, "  ", GetSymbolName of data(j), ePrice[j]:5:2, Open of data(j):5:2,
         posProfit:6:2, nProfit[j]:8:0, tProfit:8:0);
   end;

   if MP[j] = 0 and MP[j][1] = -1 then begin
      posProfit = Num[j] * (ePrice[j] - Open of data(j))
         * BigPointValue of data(j);
      nProfit[j] = nProfit[j] + posProfit;
      tProfit = tProfit + posProfit;
      Print(EDate[j]:7:0, Date of data(j):8:0, j:3:0, " XS",
         Num[j]:3:0, "  ", GetSymbolName of data(j), ePrice[j]:5:2, Open of data(j):5:2,
         posProfit:6:2, nProfit[j]:8:0, tProfit:8:0);
   end;
end;

------

The final problem is that the functions in TradeStation, such as "Average", have to be rewritten to calculate using the data in the arrays rather than using the built-in functions. An example of Average and Standard Deviation are listed below:

-------------

for j = 1 to NumP begin;            {Loop for each data series}

{-------Calculate Average---------}

   Sum = 0;
   for counter = 0 to Length - 1
   begin
      Sum = Sum + Close[counter] of data(j);
   end;

   if Length > 0 then
      Ave = Sum / Length;

{-------Calculate Std Dev---------}

   SumSqr = 0;
   for counter = 0 to Length - 1
   begin
      Value1 = (Close[counter] of data(j) - Ave);
      SumSqr = SumSqr + Value1 * Value1;
   end;
   if Length > 0 then
      StdDev = SquareRoot(SumSqr / Length);

end;

---------

You can write it as a system and use the Print Log (Message Log) to print the results of the optimization run. You then import it into Excel to sort/chart the results.

I never used either for real trading, just for testing concepts as part of a study.

Needless to say, the code was very complicated - not for the faint of heart...

Bob Fulks