support.tsresearchgroup.com Forum Index

TSResearch | Software Products | Online Help | Free Download | Publications | Research

Username:   Password:   
Log me on automatically each visit
 

FAQ |  Search |  Memberlist |  Usergroups |  Profile |  Log in to check your private messages  Register |  Log in 

Fitness
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    support.tsresearchgroup.com Forum Index -> TS Genetic Optimizer for TradeStation
View previous topic :: View next topic  
Author Message
RTS Trading
Customer


Joined: 19 Feb 2004
Posts: 17

PostPosted: Thu Feb 19, 2004 6:37 pm    Post subject: Fitness Reply with quote

It appears I get to start things off on this topic!

I would like to determine the best values for the few variables I have based upon the most linear equity curve generated for the entire data set being optimized.

I believe that the following will suit my needs but am not sure how to write this correctly(newbie at EL):

Fitness = (NetProfit)/stderror(c,for entire data set)
The highest value will give me the most linear equity curve.

Is there a better wayand how to specify the "entire data set"?

_________________
Thanks,
Bob
Back to top
View user's profile Send private message
Mak
Developers Team


Joined: 26 Jan 2004
Posts: 465

PostPosted: Fri Feb 20, 2004 3:40 pm    Post subject: Reply with quote

Quote:
I would like to determine the best values for the few variables I have based upon the most linear equity curve generated for the entire data set being optimized.


It's not enough, the most linear equity curve is zero line.
Genetic optimazer very quickly finds this solution.

Quote:
I believe that the following will suit my needs but am not sure how to write this correctly(newbie at EL):

Fitness = (NetProfit)/stderror(c,for entire data set)
The highest value will give me the most linear equity curve.


It's more correct ...
See example below
EasyLanguage:
 
{main code of signal } 
 
Array: Equity[10000](0); 
Equity[CurrentBar] = NetProfit + OpenPositionProfit
 
if LastBarOnChart then Begin     
    Fitness = Equity[CurrentBar] / MaxList(0.001, StdErrorArray(Equity,CurrentBar-1)); 
    GO_Fitness (Fitness); 
End;
Back to top
View user's profile Send private message
DT
Developers Team


Joined: 03 Feb 2004
Posts: 188

PostPosted: Fri Feb 20, 2004 5:27 pm    Post subject: Reply with quote

Try something like this:
EasyLanguage:
 
Vars: Equity(0), EqMax(0.0001), DD(0), IntegralDD(0), Fitness(0); 
Equity = InitialCapital + NetProfit + OpenPositionProfit
EqMax = maxlist(Equity, EqMax); 
DD = Equity/EqMax; 
IntegralDD = IntegralDD + 1; 
 
Fitness = Equity/InitialCapital + 2/barnumber*IntegralDD;


It is minimize downside (underwater) equity area and maximize equity slope. Upside equity steps holds.

Didn't check it.
Back to top
View user's profile Send private message
kshultz
Guest


Joined: 12 Apr 2004
Posts: 12

PostPosted: Tue Jan 11, 2005 7:27 pm    Post subject: Reply with quote

In your publication you say:
"Building of non-trivial optimization criterion (Fitness)

In our opinion, building of non-trivial optimization criterion is one of the most essential moments of trading systems building. As it we mentioned above in order to lower the risk of overfitting it is necessary to use another characteristics than NetProfit etc., but those which are associated with desirable behavior of Equity as a whole, not only with its absolute value at the end of the testing period. We can maximize the average of the following value for example:

[log W(T)/W(0) + 2/T * sum { log (W(t)/Wmax(t) }], t = 0,..., T,
where Wmax(t) = max{Wmax(t),W(t)}
i.e. we tend to condition the monotonous growth of Equity W(t)). "

How can I code this in my Fitness( ) statement in EasyLanguage? Ken
Back to top
View user's profile Send private message
DT
Developers Team


Joined: 03 Feb 2004
Posts: 188

PostPosted: Wed Jan 12, 2005 11:14 am    Post subject: Reply with quote

kshultz wrote:
In your publication you say:
"Building of non-trivial optimization criterion (Fitness)

We can maximize the average of the following value for example:

[log W(T)/W(0) + 2/T * sum { log (W(t)/Wmax(t) }], t = 0,..., T,
where Wmax(t) = max{Wmax(t),W(t)}
i.e. we tend to condition the monotonous growth of Equity W(t)). "

How can I code this in my Fitness( ) statement in EasyLanguage? Ken


Here you are:

EasyLanguage:
 Inputs: InitialCapital(NumericSimple); 
Vars: Equity(0), EqMax(0.0001), DD(0), IntegralDD(0), Fitness(0);  
Equity = InitialCapital + NetProfit + OpenPositionProfit;  
EqMax = maxlist(Equity, EqMax);  
DD = Equity/EqMax - 1;  
IntegralDD = IntegralDD + DD;  
  
Fitness = Equity/InitialCapital + 2/barnumber*IntegralDD; 


I changed logarithms to percentage. It is the same up to 2nd digit.
This fitness maximizes equity growth and minimizes drowdouns as size as duration in the same time
Back to top
View user's profile Send private message
krc
Guest


Joined: 02 Nov 2005
Posts: 8

PostPosted: Wed Nov 02, 2005 12:15 am    Post subject: Expectancy / Quality Reply with quote

I found code for expectancy and quality at http://unicorn.us.com/trading/src/_SystemQuality.txt

But it doesn't let me optimize for Expectancy or Quality, instead I have to examine in Excel after optimization. Is there an example of Fitness for expectancy and/or quality?
Back to top
View user's profile Send private message
Mak
Developers Team


Joined: 26 Jan 2004
Posts: 465

PostPosted: Wed Nov 02, 2005 4:34 pm    Post subject: Reply with quote

Function SystemQuality
EasyLanguage:
vars: nclosed(0), wins(0), losses(0), scratches(0), scratchloss(0), 
    scratchtrade(0), studystart(0), studydays(0), 
    p(0), j(0), k(0), AW(0), PW(0), AL(0), PL(0), expectancy(0), 
    expectancyscore(0); 
 
{Initializations to occur on first bar} 
 
if currentbar <= 1 then begin 
    nclosed = 0; 
    wins = 0; 
    losses = 0; 
    scratches = 0; 
    scratchloss = 0; 
    studystart = DateToJulian(Date); 
 
    {The maximum loss amount for a "scratch" trade will be a 
    round-turn commission and slippage
    Set Commission and Slippage in Format -> Strategy -> Costs.}
 
 
    scratchtrade = -1.5 * (commission + slippage); 
end
 
{Do the following whenever a position is closed} 
 
if totaltrades > nclosed then begin 
    k = totaltrades - nclosed; 
    for j = 1 to k begin    {loop over multiple simultaneous closed trades} 
        p = PositionProfit(j); 
        if p <= 0 then begin 
            if p >= scratchtrade then begin 
                scratches = scratches + 1; 
                scratchloss = scratchloss + p; 
            end else 
                losses = losses + 1; 
        end else 
            wins = wins + 1; 
    end
    nclosed = totaltrades
end
 
if losses>0 then begin 
    studydays = DateToJulian(Date) - studystart; 
    if studydays < 1 then studydays = 1; 
 
    {Calculate results to be optimized, and output them} 
    if wins > 1 and losses > 0 then begin 
        j = wins - 1 + losses;{total trades excl scratches & max win} 
        AW = (GrossProfit-LargestWinTrade)/(wins-1);  {avg win} 
        PW = (wins-1) / j;                            {% wins} 
        AL = (GrossLoss - scratchloss) / losses;      {avg loss} 
        PL = losses / j;                              {% losses} 
    end else begin       {handle division by zero cases} 
        j = wins + losses; 
        if wins <= 1 then AW = 0 else AW = GrossProfit / (wins-1); 
        if j = 0 then begin 
            PW = 0; PL = 0; 
        end else begin 
            PW = wins / j; PL = losses / j; 
        end
        if losses = 0 then AL = 0 
        else AL = (GrossLoss - scratchloss) / losses; 
    end
 
    if AL = 0 then expectancy = AW*PW 
    else expectancy = (AW*PW + AL*PL) / (-AL); 
    expectancyscore = expectancy * j * 365/studydays; 
 
end
SystemQuality = expectancyscore;    {dummy return value} 


Example of use
EasyLanguage:
Inputs: Gen(1), ShowInd(1), ModeTSGO(0), Population(50), FreshBlood(0), MyReportName("MBOX");    
Vars: Len1(20),Len2(10),Len(0),Q11(0),Q12(0),Q21(0),Q22(0),KATR(10);  
Vars: R(0),K(0),LastRun(0),Ind(0);    
  
If CurrentBar = 1 Then Begin       
    R = TS.GO.Start(MyReportName);  
    If Gen=1 Then Begin  
        R=TS.GO.Mode(ModeTSGO);  
        R=TS.GO.Popul(Population);  
        R=TS.GO.FreshBlood(FreshBlood);  
          
        K=TS.GO.Chrom("O");  
        R=TS.GO.Gen("O.Len",K,1,100,1);  
        R=TS.GO.Gen("O.Q11",K,-1,1,0.1);  
        R=TS.GO.Gen("O.Q12",K,-1,1,0.1);  
        K=TS.GO.Chrom("E");  
        R=TS.GO.Gen("E.Len",K,1,100,1);  
        R=TS.GO.Gen("E.Q21",K,-1,1,0.1);  
        R=TS.GO.Gen("E.Q22",K,-1,1,0.1);  
    end;  
      
    LastRun = TS.GO.Next(Gen);  
    Ind = Iff(LastRun = 1,ShowInd,0);  
      
    Len1 = TS.GO.Get("O.Len",Ind);  
    Len2 = TS.GO.Get("E.Len",Ind);  
    Q11  = TS.GO.Get("O.Q11",Ind);  
    Q12  = TS.GO.Get("O.Q12",Ind);  
    Q21  = TS.GO.Get("E.Q21",Ind);  
    Q22  = TS.GO.Get("E.Q22",Ind);  
    R = TS.GO.ShowViewer;        
End;   
  
{Code of Signal here ...}  
{.................................}  
  
Vars: Fitness(0);  
Fitness = SystemQuality; 
 
IF LastBarOnChart Then Begin  
    R=TS.GO.Fitness(Fitness);  
end ; 
Back to top
View user's profile Send private message
krc
Guest


Joined: 02 Nov 2005
Posts: 8

PostPosted: Fri Nov 04, 2005 6:21 pm    Post subject: Fitness for Walk Forward Optimization Reply with quote

I was reading the articles by Dennis Meyers at:
http://www.meyersanalytics.com/articles.php

and I wonder if I can build a fitness function that helps optimize strategies as he outlines in his articles.

i.e.,
limit the profit factor to a range (1 - 2.5)
restrict the number of consecutive losing trades
make sure that it trades daily (number of trades > N)
(varies by backtest period)
But not too many trades: (number of trades < M)

- Kevin
Back to top
View user's profile Send private message
Mak
Developers Team


Joined: 26 Jan 2004
Posts: 465

PostPosted: Sun Nov 06, 2005 12:48 pm    Post subject: Reply with quote

You can use any limitations in fitness that you can write with EasyLanguage.

Limitations can be presented as "penalty functions".
If set limitations are exeded, we penalize system by reducing fitness.
It's possible to use several penalty fuctions at a time.
For example:
EasyLanguage:
Fitness = SystemQuality   {It's main criteria, may be any ...} 
      - Iff (ProfitFactor &gt; 1 and ProfitFactor &lt; 2.5, 0, 100000) {Limits to profite factor} 
      - Iff (TotalTrades &gt; N and TotalTrades &lt; M, 0, 100000) {Limits to number of trades} 
      - Iff ( ............... ) { .............. } 
Back to top
View user's profile Send private message
bearwatch
Guest


Joined: 22 May 2006
Posts: 30

PostPosted: Tue May 23, 2006 5:14 am    Post subject: great post Reply with quote

This is a great post! I've been busting my head trying to figure out how to use fitness to smooth out the EC.

I have one question, using these criterion, has anyone successfully walked forward their system with same curve line? Thanks.
Back to top
View user's profile Send private message
VladGor
Support Team


Joined: 26 Jan 2004
Posts: 528

PostPosted: Tue May 23, 2006 9:53 am    Post subject: Reply with quote

We didn’t understand your question.
Can describe in more detail what is happening?
Back to top
View user's profile Send private message
bearwatch
Guest


Joined: 22 May 2006
Posts: 30

PostPosted: Tue May 23, 2006 10:46 am    Post subject: Reply with quote

I just wanted to know if anyone has used these criterion (equity curve... high equity growth, small drawdown) and have it trade live or walk forward with same results as during backtest or optimization periods.

One other question is I'm experimenting this SystemQuality function with multiple criterion from the above post, how do implement this in EL code? The ProfitFactor word gave me an error (would not verify).

I have to say so far, this is better than GrailSystem on this very flexible feature to choose your own criteria.
Back to top
View user's profile Send private message
bearwatch
Guest


Joined: 22 May 2006
Posts: 30

PostPosted: Tue May 23, 2006 10:47 am    Post subject: Reply with quote

I cannot get this code to verify in EL. How would I do this? Thanks

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

Fitness = SystemQuality {It's main criteria, may be any ...}
- Iff (ProfitFactor &gt; 1 and ProfitFactor &lt; 2.5, 0, 100000) {Limits to profite factor}
- Iff (TotalTrades &gt; N and TotalTrades &lt; M, 0, 100000) {Limits to number of trades}
Back to top
View user's profile Send private message
Mak
Developers Team


Joined: 26 Jan 2004
Posts: 465

PostPosted: Tue May 23, 2006 11:06 am    Post subject: Reply with quote

ProfitFactor must be calculated befor
EasyLanguage:
Var: ProfitFactor (0); 
 
ProfitFactor = Iff(GrossLoss &lt; 0,-GrossProfit/GrossLoss,0); 
 
Fitness = SystemQuality {It's main criteria, may be any ...} 
Iff (ProfitFactor &gt; 1 and ProfitFactor &lt; 2.5, 0, 100000) {Limits to profite factor} 
Iff (TotalTrades &gt; N and TotalTrades &lt; M, 0, 100000) {Limits to number of trades}
Back to top
View user's profile Send private message
bearwatch
Guest


Joined: 22 May 2006
Posts: 30

PostPosted: Tue May 23, 2006 12:08 pm    Post subject: Reply with quote

Oh yes, I forgot, I'll give it a try. Thanks for a quick response. Good product good support, I'm very close to buying the license!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    support.tsresearchgroup.com Forum Index -> TS Genetic Optimizer for TradeStation All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Copyright © TS Research Group

Powered by phpBB © 2001, 2002 phpBB Group

Developed by: webdesign.tria.lv