Need some help with GP

View: New views
10 Messages — Rating Filter:   Alert me  

Need some help with GP

by Igor2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am currently working on a research project involving creating trade strategies based on GAs and GPs. GA part worked perfectly with JGAP. Now I am trying to understand the GP framework... Still I am having some problems.

Basically I want to input different variables like today’s and yesterday’s prices and volumes, some terminals and some functions like moving averages. Idea is to have GP to generate function in form of:

SMA(200) + todayClose*0.5 >= yesterdayClose^2

If this expression is true the automated trading agent will sell, else buy etc.

My question now: Can somebody help me with public GPGenotype create() part?

I don´t understand how I can initialize an array of multiple variables? How can I create a function in form of expressions {>,<,=} expressions2? Is it possible to directly create function with three different outputs: buy, sell & hold…

JGAP is an awesome framework & helped me a lot during my project. I hope I can overcome my luck of knowledge and use it further.

Thanks!

Re: Need some help with GP

by Klaus Meffert-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Igor2,

Maybe take a look at the example with class examples.gp.MathProblem. In
create() you see the definition of possible GP commands. For your case, you
should skip the second part of argTypes definition
("{CommandGene.FloatClass,CommandGene.FloatClass,CommandGene.FloatClass}"),
and the second part of the nodeSets definition ("new Add3(conf,
CommandGene.FloatClass)").

For the ">=" part, you could use command org.jgap.gp.function.GreaterThan.

Yes, a function can of course output three solutions. Just create a function
that returns, say, 1, 2, or 3. 1 is interpreted as buy, 2 is sell, 3 is
hold...



Best

Klaus
www.klaus-meffert.com

 

> -----Original Message-----
> From: jgap-users-bounces@...
> [mailto:jgap-users-bounces@...] On Behalf Of Igor2
> Sent: Wednesday, April 02, 2008 6:28 PM
> To: jgap-users@...
> Subject: [jgap-users] Need some help with GP
>
>
> I am currently working on a research project involving
> creating trade strategies based on GAs and GPs. GA part
> worked perfectly with JGAP. Now I am trying to understand the
> GP framework... Still I am having some problems.
>
> Basically I want to input different variables like today’s
> and yesterday’s prices and volumes, some terminals and some
> functions like moving averages.
> Idea is to have GP to generate function in form of:
>
> SMA(200) + todayClose*0.5 >= yesterdayClose^2
>
> If this expression is true the automated trading agent will
> sell, else buy etc.
>
> My question now: Can somebody help me with public GPGenotype
> create() part?
>
> I don´t understand how I can initialize an array of multiple
> variables? How can I create a function in form of expressions
> {>,<,=} expressions2? Is it possible to directly create
> function with three different outputs: buy, sell & hold…
>
> JGAP is an awesome framework & helped me a lot during my
> project. I hope I can overcome my luck of knowledge and use
> it further.
>
> Thanks!


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
jgap-users mailing list
jgap-users@...
https://lists.sourceforge.net/lists/listinfo/jgap-users

Re: Need some help with GP

by Igor2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks!

It worked perfectly. Now I get expressions of desired form: something1 > something2. Can you maybe explain how I can limit the output to 3 values (I now have two: true vs. false, I am using boolean)? I am going to implement different technical indicators, prices (Close, High, Open etc.) and volumes as functions (similiar to the antproblem). Their inputs will be terminals and current traiding day number. Like simple moving avarega: SMA(50, 250) - means calculate average price over 50 days with current day being Nr. 250. My other questions: Can I limit trading day number (it will be a variable) to the role of input for fucntions? It is just a running number so expression of buy if trading_day_number>100 do not really make any sense. It should be more like SMA(50, 250) > Close_Price(250)*0.75. Is there a way?

Thanks!


Klaus Meffert-5 wrote:
Igor2,

Maybe take a look at the example with class examples.gp.MathProblem. In
create() you see the definition of possible GP commands. For your case, you
should skip the second part of argTypes definition
("{CommandGene.FloatClass,CommandGene.FloatClass,CommandGene.FloatClass}"),
and the second part of the nodeSets definition ("new Add3(conf,
CommandGene.FloatClass)").

For the ">=" part, you could use command org.jgap.gp.function.GreaterThan.

Yes, a function can of course output three solutions. Just create a function
that returns, say, 1, 2, or 3. 1 is interpreted as buy, 2 is sell, 3 is
hold...



Best

Klaus
www.klaus-meffert.com

 

> -----Original Message-----
> From: jgap-users-bounces@lists.sourceforge.net
> [mailto:jgap-users-bounces@lists.sourceforge.net] On Behalf Of Igor2
> Sent: Wednesday, April 02, 2008 6:28 PM
> To: jgap-users@lists.sourceforge.net
> Subject: [jgap-users] Need some help with GP
>
>
> I am currently working on a research project involving
> creating trade strategies based on GAs and GPs. GA part
> worked perfectly with JGAP. Now I am trying to understand the
> GP framework... Still I am having some problems.
>
> Basically I want to input different variables like today’s
> and yesterday’s prices and volumes, some terminals and some
> functions like moving averages.
> Idea is to have GP to generate function in form of:
>
> SMA(200) + todayClose*0.5 >= yesterdayClose^2
>
> If this expression is true the automated trading agent will
> sell, else buy etc.
>
> My question now: Can somebody help me with public GPGenotype
> create() part?
>
> I don´t understand how I can initialize an array of multiple
> variables? How can I create a function in form of expressions
> {>,<,=} expressions2? Is it possible to directly create
> function with three different outputs: buy, sell & hold…
>
> JGAP is an awesome framework & helped me a lot during my
> project. I hope I can overcome my luck of knowledge and use
> it further.
>
> Thanks!


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
jgap-users mailing list
jgap-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jgap-users

Re: Need some help with GP

by Klaus Meffert-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Igor2,

I didn't exactly understand your questions.

Did you mean how you can manage to get three different output values (e.g.:
1, 2 or 3 as a value) instead of two boolean values (namely true and false)?
If so, you could use an integer with range 1..3, e.g.

The other question is also not completely clear to me: Do you want to make a
function dependent on an input value? You can easily do this by specifying a
child type X where X is the input type desired (and then supply a GP command
with return type X).

If I misunderstood something please clarify.

Best

Klaus
www.klaus-meffert.com

 

> -----Original Message-----
> From: jgap-users-bounces@...
> [mailto:jgap-users-bounces@...] On Behalf Of Igor2
> Sent: Thursday, April 03, 2008 5:22 PM
> To: jgap-users@...
> Subject: Re: [jgap-users] Need some help with GP
>
>
> Thanks!
>
> It worked perfectly. Now I get expressions of desired form:
> something1 > something2. Can you maybe explain how I can
> limit the output to 3 values (I now have two: true vs. false,
> I am using boolean)? I am going to implement different
> technical indicators, prices (Close, High, Open etc.) and
> volumes as functions (similiar to the antproblem). Their
> inputs will be terminals and current traiding day number.
> Like simple moving avarega: SMA(50, 250) - means calculate
> average price over 50 days with current day being Nr. 250.
> My other questions: Can I limit trading day number (it will
> be a variable) to the role of input for fucntions? It is just
> a running number so expression of buy if
> trading_day_number>100 do not really make any sense. It
> should be more like SMA(50, 250) > Close_Price(250)*0.75. Is
> there a way?
>
> Thanks!
>
>
>
> Klaus Meffert-5 wrote:
> >
> > Igor2,
> >
> > Maybe take a look at the example with class
> examples.gp.MathProblem.
> > In
> > create() you see the definition of possible GP commands. For your
> > case, you should skip the second part of argTypes definition
> >
> ("{CommandGene.FloatClass,CommandGene.FloatClass,CommandGene.FloatClas
> > s}"), and the second part of the nodeSets definition ("new
> Add3(conf,
> > CommandGene.FloatClass)").
> >
> > For the ">=" part, you could use command
> org.jgap.gp.function.GreaterThan.
> >
> > Yes, a function can of course output three solutions. Just create a
> > function that returns, say, 1, 2, or 3. 1 is interpreted as
> buy, 2 is
> > sell, 3 is hold...
> >
> >
> >
> > Best
> >
> > Klaus
> > www.klaus-meffert.com
> >
> >  
> >
> >> -----Original Message-----
> >> From: jgap-users-bounces@...
> >> [mailto:jgap-users-bounces@...] On
> Behalf Of Igor2
> >> Sent: Wednesday, April 02, 2008 6:28 PM
> >> To: jgap-users@...
> >> Subject: [jgap-users] Need some help with GP
> >>
> >>
> >> I am currently working on a research project involving
> creating trade
> >> strategies based on GAs and GPs. GA part worked perfectly
> with JGAP.
> >> Now I am trying to understand the GP framework... Still I
> am having
> >> some problems.
> >>
> >> Basically I want to input different variables like today’s and
> >> yesterday’s prices and volumes, some terminals and some functions
> >> like moving averages.
> >> Idea is to have GP to generate function in form of:
> >>
> >> SMA(200) + todayClose*0.5 >= yesterdayClose^2
> >>
> >> If this expression is true the automated trading agent will sell,
> >> else buy etc.
> >>
> >> My question now: Can somebody help me with public GPGenotype
> >> create() part?
> >>
> >> I don´t understand how I can initialize an array of multiple
> >> variables? How can I create a function in form of
> expressions {>,<,=}
> >> expressions2? Is it possible to directly create function
> with three
> >> different outputs: buy, sell & hold…
> >>
> >> JGAP is an awesome framework & helped me a lot during my
> project. I
> >> hope I can overcome my luck of knowledge and use it further.
> >>
> >> Thanks!
> >
> >
> >
> ----------------------------------------------------------------------
> > --- Check out the new SourceForge.net Marketplace.
> > It's the best place to buy or sell services for just about anything
> > Open Source.
> >
> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marke
> > tplace _______________________________________________
> > jgap-users mailing list
> > jgap-users@...
> > https://lists.sourceforge.net/lists/listinfo/jgap-users
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Need-some-help-with-GP-tp16447435p16467559.html
> Sent from the jgap-users mailing list archive at Nabble.com.
>
>
> --------------------------------------------------------------
> -----------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for
> just about anything Open Source.
> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.n
> et/marketplace
> _______________________________________________
> jgap-users mailing list
> jgap-users@...
> https://lists.sourceforge.net/lists/listinfo/jgap-users
>


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
jgap-users mailing list
jgap-users@...
https://lists.sourceforge.net/lists/listinfo/jgap-users

Parent Message unknown Re: Need some help with GP

by Klaus Meffert-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Igor,

OK, I think I understood what you are asking for.

1) Yes you can use a terminal in GP and also use it as input for your Sma
class. In the MathProblem class in method create() a Terminal is used, too.
As it is of type Float it can serve as input parameter for any GP command
that allows a child to have Float type.
2) You can alter the return type ("Class[] type") to Integer. However, your
fitness function must punish values that are outside your desired range. To
limit the range somehow, you could specify the range of inputs, e.g. as with
MathProblem:
new Terminal(conf, CommandGene.FloatClass, 2.0d, 10.0d, true)
This Terminal can only have values between 2.0 and 10.0

Best

Klaus
www.klaus-meffert.com

 

> -----Original Message-----
> From: Igor Lukin [mailto:igor.lukin@...]
> Sent: Thursday, April 03, 2008 9:54 PM
> To: Klaus Meffert
> Cc: jgap-users@...
> Subject: Re: [jgap-users] Need some help with GP
>
> Hi,
>
> Thanks for your answer. Let me clarify my point.
>
> I am currently getting expression generated in such form:
>
> (SMA5_50 - Price) < (9.0 * SMA5_50)
>
> SMA_50 and Price are functions are created, similar to the
> Ant example.
>
> The only Variable I am using is the trade day number (from
> beginning for trade period 1 to the end e.g. 800).
>
> SMA_50 and Price use this Variable to create the output:
> close price and simple moving average of price over 50 day.
>
> Can I modify SMA_50 to output  simple moving average of price
> over X day where X is some kind of numerical terminal generated by GP?
>
> I attached SMA_50 code.
>
> To the question concerning the 3 outputs: How can I specify
> the range of the output? Currently I have Class[] types =
> {CommandGene.BooleanClass}; Can I modify it to Integer and
> somehow input the range limitation?
>
> Thank you for your answers!
>
> Best regards,
>
> Igor
>
> On Thu, Apr 3, 2008 at 2:38 PM, Klaus Meffert
> <jgap@...> wrote:
> > Igor2,
> >
> >  I didn't exactly understand your questions.
> >
> >  Did you mean how you can manage to get three different
> output values (e.g.:
> >  1, 2 or 3 as a value) instead of two boolean values
> (namely true and false)?
> >  If so, you could use an integer with range 1..3, e.g.
> >
> >  The other question is also not completely clear to me: Do
> you want to
> > make a  function dependent on an input value? You can
> easily do this
> > by specifying a  child type X where X is the input type
> desired (and
> > then supply a GP command  with return type X).
> >
> >  If I misunderstood something please clarify.
> >
> >  Best
> >
> >  Klaus
> >  www.klaus-meffert.com
> >
> >
> >
> >  > -----Original Message-----
> >  > From: jgap-users-bounces@...
> >  > [mailto:jgap-users-bounces@...] On Behalf Of
> > Igor2  > Sent: Thursday, April 03, 2008 5:22 PM  > To:
> > jgap-users@...  > Subject: Re: [jgap-users] Need
> > some help with GP  >  >  > Thanks!
> >  >
> >  > It worked perfectly. Now I get expressions of desired form:
> >  > something1 > something2. Can you maybe explain how I can
>  > limit
> > the output to 3 values (I now have two: true vs. false,  >
> I am using
> > boolean)? I am going to implement different  > technical
> indicators,
> > prices (Close, High, Open etc.) and  > volumes as functions
> (similiar
> > to the antproblem). Their  > inputs will be terminals and current
> > traiding day number.
> >  > Like simple moving avarega: SMA(50, 250) - means calculate  >
> > average price over 50 days with current day being Nr. 250.
> >  > My other questions: Can I limit trading day number (it
> will  > be a
> > variable) to the role of input for fucntions? It is just  >
> a running
> > number so expression of buy if  > trading_day_number>100 do
> not really
> > make any sense. It  > should be more like SMA(50, 250) >
> > Close_Price(250)*0.75. Is  > there a way?
> >  >
> >  > Thanks!
> >  >
> >  >
> >  >
> >  > Klaus Meffert-5 wrote:
> >  > >
> >  > > Igor2,
> >  > >
> >  > > Maybe take a look at the example with class  >
> > examples.gp.MathProblem.
> >  > > In
> >  > > create() you see the definition of possible GP
> commands. For your  
> > > > case, you should skip the second part of argTypes
> definition  > >  
> > >
> >
> ("{CommandGene.FloatClass,CommandGene.FloatClass,CommandGene.FloatClas
> >  > > s}"), and the second part of the nodeSets definition ("new  >
> > Add3(conf,  > > CommandGene.FloatClass)").
> >  > >
> >  > > For the ">=" part, you could use command  >
> > org.jgap.gp.function.GreaterThan.
> >  > >
> >  > > Yes, a function can of course output three solutions.
> Just create
> > a  > > function that returns, say, 1, 2, or 3. 1 is
> interpreted as  >
> > buy, 2 is  > > sell, 3 is hold...
> >  > >
> >  > >
> >  > >
> >  > > Best
> >  > >
> >  > > Klaus
> >  > > www.klaus-meffert.com
> >  > >
> >  > >
> >  > >
> >  > >> -----Original Message-----
> >  > >> From: jgap-users-bounces@...
> >  > >> [mailto:jgap-users-bounces@...] On  
> > Behalf
> > Of Igor2  > >> Sent: Wednesday, April 02, 2008 6:28 PM  > >> To:
> > jgap-users@...  > >> Subject:
> [jgap-users] Need some
> > help with GP  > >>  > >>  > >> I am currently working on a research
> > project involving  > creating trade  > >> strategies based
> on GAs and
> > GPs. GA part worked perfectly  > with JGAP.
> >  > >> Now I am trying to understand the GP framework...
> Still I  > am
> > having  > >> some problems.
> >  > >>
> >  > >> Basically I want to input different variables like
> today's and  
> > > >> yesterday's prices and volumes, some terminals and
> some functions  
> > > >> like moving averages.
> >  > >> Idea is to have GP to generate function in form of:
> >  > >>
> >  > >> SMA(200) + todayClose*0.5 >= yesterdayClose^2  > >>  > >> If
> > this expression is true the automated trading agent will
> sell,  > >>
> > else buy etc.
> >  > >>
> >  > >> My question now: Can somebody help me with public
> GPGenotype  >
> > >> create() part?
> >  > >>
> >  > >> I don´t understand how I can initialize an array of
> multiple  >
> > >> variables? How can I create a function in form of  > expressions
> > {>,<,=}  > >> expressions2? Is it possible to directly
> create function  
> > > with three  > >> different outputs: buy, sell & hold…  > >>  > >>
> > JGAP is an awesome framework & helped me a lot during my  >
> project. I  
> > > >> hope I can overcome my luck of knowledge and use it further.
> >  > >>
> >  > >> Thanks!
> >  > >
> >  > >
> >  > >
> >  >
> >
> ----------------------------------------------------------------------
> >  > > --- Check out the new SourceForge.net Marketplace.
> >  > > It's the best place to buy or sell services for just about
> > anything  > > Open Source.
> >  > >
> >  >
> >
> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marke
> >  > > tplace _______________________________________________
> >  > > jgap-users mailing list
> >  > > jgap-users@...
> >  > > https://lists.sourceforge.net/lists/listinfo/jgap-users
> >  > >
> >  > >
> >  >
> >  > --
> >  > View this message in context:
> >  >
> >
> http://www.nabble.com/Need-some-help-with-GP-tp16447435p16467559.html
> >  > Sent from the jgap-users mailing list archive at Nabble.com.
> >  >
> >  >
> >  > --------------------------------------------------------------
> >  > -----------
> >  > Check out the new SourceForge.net Marketplace.
> >  > It's the best place to buy or sell services for  > just about
> > anything Open Source.
> >  > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.n
> >  > et/marketplace
> >  > _______________________________________________
> >  > jgap-users mailing list
> >  > jgap-users@...
> >  > https://lists.sourceforge.net/lists/listinfo/jgap-users
> >  >
> >
> >
>
>
>
> --
> Best regards,
>
> Igor Lukin
>
> Exchange Student at College of Engineering University of
> Illinois at Urbana-Champaign
>
> Graduate Student – Business Administration and Computer
> Science Darmstadt University of Technology
>
> Tel: +1 217 721 8873
> Email: Igor.Lukin@...
>
> 1107 S. Second St. Apt. 25
> Champaign, IL 61820
> USA
>


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
jgap-users mailing list
jgap-users@...
https://lists.sourceforge.net/lists/listinfo/jgap-users

Re: Need some help with GP

by Igor2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

thanks. Now I understand the thing with limiting inputs and punishing
wrong outputs.

Can you maybe give me a code example of how to access a terminal to
pass it to my function (like sma)? I could not really understand how
it worked in MathProblem. I looked at some functions already
implemented like Sine, but they all use variables as their input...

I attached my TradeGP.java...

Sorry for so many questions, but at some point I am just stuck :(

Thanks.

Best regards,

Igor

On Fri, Apr 4, 2008 at 3:02 AM, Klaus Meffert <jgap@...> wrote:

> Igor,
>
>  OK, I think I understood what you are asking for.
>
>  1) Yes you can use a terminal in GP and also use it as input for your Sma
>  class. In the MathProblem class in method create() a Terminal is used, too.
>  As it is of type Float it can serve as input parameter for any GP command
>  that allows a child to have Float type.
>  2) You can alter the return type ("Class[] type") to Integer. However, your
>  fitness function must punish values that are outside your desired range. To
>  limit the range somehow, you could specify the range of inputs, e.g. as with
>  MathProblem:
>  new Terminal(conf, CommandGene.FloatClass, 2.0d, 10.0d, true)
>  This Terminal can only have values between 2.0 and 10.0
>
>
>  Best
>
>  Klaus
>  www.klaus-meffert.com
>
>
>
>  > -----Original Message-----
>
>
> > From: Igor Lukin [mailto:igor.lukin@...]
>  > Sent: Thursday, April 03, 2008 9:54 PM
>  > To: Klaus Meffert
>  > Cc: jgap-users@...
>  > Subject: Re: [jgap-users] Need some help with GP
>  >
>  > Hi,
>  >
>  > Thanks for your answer. Let me clarify my point.
>  >
>  > I am currently getting expression generated in such form:
>  >
>  > (SMA5_50 - Price) < (9.0 * SMA5_50)
>  >
>  > SMA_50 and Price are functions are created, similar to the
>  > Ant example.
>  >
>  > The only Variable I am using is the trade day number (from
>  > beginning for trade period 1 to the end e.g. 800).
>  >
>  > SMA_50 and Price use this Variable to create the output:
>  > close price and simple moving average of price over 50 day.
>  >
>  > Can I modify SMA_50 to output  simple moving average of price
>  > over X day where X is some kind of numerical terminal generated by GP?
>  >
>  > I attached SMA_50 code.
>  >
>  > To the question concerning the 3 outputs: How can I specify
>  > the range of the output? Currently I have Class[] types =
>  > {CommandGene.BooleanClass}; Can I modify it to Integer and
>  > somehow input the range limitation?
>  >
>  > Thank you for your answers!
>  >
>  > Best regards,
>  >
>  > Igor
>  >
>  > On Thu, Apr 3, 2008 at 2:38 PM, Klaus Meffert
>  > <jgap@...> wrote:
>  > > Igor2,
>  > >
>  > >  I didn't exactly understand your questions.
>  > >
>  > >  Did you mean how you can manage to get three different
>  > output values (e.g.:
>  > >  1, 2 or 3 as a value) instead of two boolean values
>  > (namely true and false)?
>  > >  If so, you could use an integer with range 1..3, e.g.
>  > >
>  > >  The other question is also not completely clear to me: Do
>  > you want to
>  > > make a  function dependent on an input value? You can
>  > easily do this
>  > > by specifying a  child type X where X is the input type
>  > desired (and
>  > > then supply a GP command  with return type X).
>  > >
>  > >  If I misunderstood something please clarify.
>  > >
>  > >  Best
>  > >
>  > >  Klaus
>  > >  www.klaus-meffert.com
>  > >
>  > >
>  > >
>  > >  > -----Original Message-----
>  > >  > From: jgap-users-bounces@...
>  > >  > [mailto:jgap-users-bounces@...] On Behalf Of
>  > > Igor2  > Sent: Thursday, April 03, 2008 5:22 PM  > To:
>  > > jgap-users@...  > Subject: Re: [jgap-users] Need
>  > > some help with GP  >  >  > Thanks!
>  > >  >
>  > >  > It worked perfectly. Now I get expressions of desired form:
>  > >  > something1 > something2. Can you maybe explain how I can
>  >  > limit
>  > > the output to 3 values (I now have two: true vs. false,  >
>  > I am using
>  > > boolean)? I am going to implement different  > technical
>  > indicators,
>  > > prices (Close, High, Open etc.) and  > volumes as functions
>  > (similiar
>  > > to the antproblem). Their  > inputs will be terminals and current
>  > > traiding day number.
>  > >  > Like simple moving avarega: SMA(50, 250) - means calculate  >
>  > > average price over 50 days with current day being Nr. 250.
>  > >  > My other questions: Can I limit trading day number (it
>  > will  > be a
>  > > variable) to the role of input for fucntions? It is just  >
>  > a running
>  > > number so expression of buy if  > trading_day_number>100 do
>  > not really
>  > > make any sense. It  > should be more like SMA(50, 250) >
>  > > Close_Price(250)*0.75. Is  > there a way?
>  > >  >
>  > >  > Thanks!
>  > >  >
>  > >  >
>  > >  >
>  > >  > Klaus Meffert-5 wrote:
>  > >  > >
>  > >  > > Igor2,
>  > >  > >
>  > >  > > Maybe take a look at the example with class  >
>  > > examples.gp.MathProblem.
>  > >  > > In
>  > >  > > create() you see the definition of possible GP
>  > commands. For your
>  > > > > case, you should skip the second part of argTypes
>  > definition  > >
>  > > >
>  > >
>  > ("{CommandGene.FloatClass,CommandGene.FloatClass,CommandGene.FloatClas
>  > >  > > s}"), and the second part of the nodeSets definition ("new  >
>  > > Add3(conf,  > > CommandGene.FloatClass)").
>  > >  > >
>  > >  > > For the ">=" part, you could use command  >
>  > > org.jgap.gp.function.GreaterThan.
>  > >  > >
>  > >  > > Yes, a function can of course output three solutions.
>  > Just create
>  > > a  > > function that returns, say, 1, 2, or 3. 1 is
>  > interpreted as  >
>  > > buy, 2 is  > > sell, 3 is hold...
>  > >  > >
>  > >  > >
>  > >  > >
>  > >  > > Best
>  > >  > >
>  > >  > > Klaus
>  > >  > > www.klaus-meffert.com
>  > >  > >
>  > >  > >
>  > >  > >
>  > >  > >> -----Original Message-----
>  > >  > >> From: jgap-users-bounces@...
>  > >  > >> [mailto:jgap-users-bounces@...] On
>  > > Behalf
>  > > Of Igor2  > >> Sent: Wednesday, April 02, 2008 6:28 PM  > >> To:
>  > > jgap-users@...  > >> Subject:
>  > [jgap-users] Need some
>  > > help with GP  > >>  > >>  > >> I am currently working on a research
>  > > project involving  > creating trade  > >> strategies based
>  > on GAs and
>  > > GPs. GA part worked perfectly  > with JGAP.
>  > >  > >> Now I am trying to understand the GP framework...
>  > Still I  > am
>  > > having  > >> some problems.
>  > >  > >>
>  > >  > >> Basically I want to input different variables like
>  > today's and
>  > > > >> yesterday's prices and volumes, some terminals and
>  > some functions
>  > > > >> like moving averages.
>  > >  > >> Idea is to have GP to generate function in form of:
>  > >  > >>
>  > >  > >> SMA(200) + todayClose*0.5 >= yesterdayClose^2  > >>  > >> If
>  > > this expression is true the automated trading agent will
>  > sell,  > >>
>  > > else buy etc.
>  > >  > >>
>  > >  > >> My question now: Can somebody help me with public
>  > GPGenotype  >
>  > > >> create() part?
>  > >  > >>
>  > >  > >> I don´t understand how I can initialize an array of
>  > multiple  >
>  > > >> variables? How can I create a function in form of  > expressions
>  > > {>,<,=}  > >> expressions2? Is it possible to directly
>  > create function
>  > > > with three  > >> different outputs: buy, sell & hold…  > >>  > >>
>  > > JGAP is an awesome framework & helped me a lot during my  >
>  > project. I
>  > > > >> hope I can overcome my luck of knowledge and use it further.
>  > >  > >>
>  > >  > >> Thanks!
>  > >  > >
>  > >  > >
>  > >  > >
>  > >  >
>  > >
>  > ----------------------------------------------------------------------
>  > >  > > --- Check out the new SourceForge.net Marketplace.
>  > >  > > It's the best place to buy or sell services for just about
>  > > anything  > > Open Source.
>  > >  > >
>  > >  >
>  > >
>  > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marke
>  > >  > > tplace _______________________________________________
>  > >  > > jgap-users mailing list
>  > >  > > jgap-users@...
>  > >  > > https://lists.sourceforge.net/lists/listinfo/jgap-users
>  > >  > >
>  > >  > >
>  > >  >
>  > >  > --
>  > >  > View this message in context:
>  > >  >
>  > >
>  > http://www.nabble.com/Need-some-help-with-GP-tp16447435p16467559.html
>  > >  > Sent from the jgap-users mailing list archive at Nabble.com.
>  > >  >
>  > >  >
>  > >  > --------------------------------------------------------------
>  > >  > -----------
>  > >  > Check out the new SourceForge.net Marketplace.
>  > >  > It's the best place to buy or sell services for  > just about
>  > > anything Open Source.
>  > >  > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.n
>  > >  > et/marketplace
>  > >  > _______________________________________________
>  > >  > jgap-users mailing list
>  > >  > jgap-users@...
>  > >  > https://lists.sourceforge.net/lists/listinfo/jgap-users
>  > >  >
>  > >
>  > >
>  >
>  >
>  >
>  > --
>  > Best regards,
>  >
>  > Igor Lukin
>  >
>  > Exchange Student at College of Engineering University of
>  > Illinois at Urbana-Champaign
>  >
>  > Graduate Student – Business Administration and Computer
>  > Science Darmstadt University of Technology
>  >
>  > Tel: +1 217 721 8873
>  > Email: Igor.Lukin@...
>  >
>  > 1107 S. Second St. Apt. 25
>  > Champaign, IL 61820
>  > USA
>  >
>
>


--
Best regards,

Igor Lukin

Exchange Student at College of Engineering
University of Illinois at Urbana-Champaign

Graduate Student – Business Administration and Computer Science
Darmstadt University of Technology

Tel: +1 217 721 8873
Email: Igor.Lukin@...

1107 S. Second St. Apt. 25
Champaign, IL 61820
USA


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
jgap-users mailing list
jgap-users@...
https://lists.sourceforge.net/lists/listinfo/jgap-users

TradeGP.java (8K) Download Attachment

Re: Need some help with GP

by Klaus Meffert-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Igor,

Simply declare (in method create()):
...
  new Terminal(conf, Terminal.class, 2.0d, 10.0d,
...

--> make return type of your Terminal a distinct type, e.g. "Terminal.class"
in the above example. You could also implement a new and empty class of your
own instead and use it as a dummy type.

Then, in your GP command, define which child types are allowed, e.g. by
adding the following method:
  /**
   * Determines which type a specific child of this command has.
   *
   * @param a_ind ignored here
   * @param a_chromNum index of child
   * @return type of the a_chromNum'th child
   */
  public Class getChildType(IGPProgram a_ind, int a_chromNum) {
    if (a_chromNum == 0) {
      return Integer.class;
    }
    else {
      return Terminal.class;
    }
  }


With that the first child must have return Integer and all other children
must be a terminal (see top of my mail: "Terminal.class" <-- Notice: as
said, you could use any Dummy class, just replace "Terminal.class" mentioned
in this mail with "YourDummyClass.class").

Klaus
www.klaus-meffert.com

 

> -----Original Message-----
> From: Igor Lukin [mailto:igor.lukin@...]
> Sent: Friday, April 04, 2008 4:43 PM
> To: Klaus Meffert
> Cc: jgap-users@...
> Subject: Re: [jgap-users] Need some help with GP
>
> Hi,
>
> thanks. Now I understand the thing with limiting inputs and
> punishing wrong outputs.
>
> Can you maybe give me a code example of how to access a
> terminal to pass it to my function (like sma)? I could not
> really understand how it worked in MathProblem. I looked at
> some functions already implemented like Sine, but they all
> use variables as their input...
>
> I attached my TradeGP.java...
>
> Sorry for so many questions, but at some point I am just stuck :(
>
> Thanks.
>
> Best regards,
>
> Igor
>
> On Fri, Apr 4, 2008 at 3:02 AM, Klaus Meffert
> <jgap@...> wrote:
> > Igor,
> >
> >  OK, I think I understood what you are asking for.
> >
> >  1) Yes you can use a terminal in GP and also use it as
> input for your
> > Sma  class. In the MathProblem class in method create() a
> Terminal is used, too.
> >  As it is of type Float it can serve as input parameter for any GP
> > command  that allows a child to have Float type.
> >  2) You can alter the return type ("Class[] type") to Integer.
> > However, your  fitness function must punish values that are outside
> > your desired range. To  limit the range somehow, you could
> specify the
> > range of inputs, e.g. as with
> >  MathProblem:
> >  new Terminal(conf, CommandGene.FloatClass, 2.0d, 10.0d,
> true)  This
> > Terminal can only have values between 2.0 and 10.0
> >
> >
> >  Best
> >
> >  Klaus
> >  www.klaus-meffert.com
> >
> >
> >
> >  > -----Original Message-----
> >
> >
> > > From: Igor Lukin [mailto:igor.lukin@...]
> >  > Sent: Thursday, April 03, 2008 9:54 PM  > To: Klaus
> Meffert  > Cc:
> > jgap-users@...  > Subject: Re: [jgap-users] Need
> > some help with GP  >  > Hi,  >  > Thanks for your answer. Let me
> > clarify my point.
> >  >
> >  > I am currently getting expression generated in such form:
> >  >
> >  > (SMA5_50 - Price) < (9.0 * SMA5_50)  >  > SMA_50 and Price are
> > functions are created, similar to the  > Ant example.
> >  >
> >  > The only Variable I am using is the trade day number (from  >
> > beginning for trade period 1 to the end e.g. 800).
> >  >
> >  > SMA_50 and Price use this Variable to create the output:
> >  > close price and simple moving average of price over 50 day.
> >  >
> >  > Can I modify SMA_50 to output  simple moving average of price  >
> > over X day where X is some kind of numerical terminal
> generated by GP?
> >  >
> >  > I attached SMA_50 code.
> >  >
> >  > To the question concerning the 3 outputs: How can I
> specify  > the
> > range of the output? Currently I have Class[] types =  >
> > {CommandGene.BooleanClass}; Can I modify it to Integer and  
> > somehow
> > input the range limitation?
> >  >
> >  > Thank you for your answers!
> >  >
> >  > Best regards,
> >  >
> >  > Igor
> >  >
> >  > On Thu, Apr 3, 2008 at 2:38 PM, Klaus Meffert  >
> > <jgap@...> wrote:
> >  > > Igor2,
> >  > >
> >  > >  I didn't exactly understand your questions.
> >  > >
> >  > >  Did you mean how you can manage to get three
> different  > output
> > values (e.g.:
> >  > >  1, 2 or 3 as a value) instead of two boolean values  
> > (namely
> > true and false)?
> >  > >  If so, you could use an integer with range 1..3, e.g.
> >  > >
> >  > >  The other question is also not completely clear to
> me: Do  > you
> > want to  > > make a  function dependent on an input value?
> You can  >
> > easily do this  > > by specifying a  child type X where X
> is the input
> > type  > desired (and  > > then supply a GP command  with
> return type
> > X).
> >  > >
> >  > >  If I misunderstood something please clarify.
> >  > >
> >  > >  Best
> >  > >
> >  > >  Klaus
> >  > >  www.klaus-meffert.com
> >  > >
> >  > >
> >  > >
> >  > >  > -----Original Message-----
> >  > >  > From: jgap-users-bounces@...
> >  > >  > [mailto:jgap-users-bounces@...]
> On Behalf Of  
> > > > Igor2  > Sent: Thursday, April 03, 2008 5:22 PM  > To:
> >  > > jgap-users@...  > Subject: Re: [jgap-users]
> > Need  > > some help with GP  >  >  > Thanks!
> >  > >  >
> >  > >  > It worked perfectly. Now I get expressions of desired form:
> >  > >  > something1 > something2. Can you maybe explain how
> I can  >  >
> > limit  > > the output to 3 values (I now have two: true vs.
> false,  >  
> > > I am using  > > boolean)? I am going to implement different  >
> > technical  > indicators,  > > prices (Close, High, Open
> etc.) and  >
> > volumes as functions  > (similiar  > > to the antproblem). Their  >
> > inputs will be terminals and current  > > traiding day number.
> >  > >  > Like simple moving avarega: SMA(50, 250) - means
> calculate  >  
> > > > average price over 50 days with current day being Nr. 250.
> >  > >  > My other questions: Can I limit trading day number
> (it  > will  
> > > be a  > > variable) to the role of input for fucntions?
> It is just  
> > >  > a running  > > number so expression of buy if  >
> > trading_day_number>100 do  > not really  > > make any sense. It  >
> > should be more like SMA(50, 250) >  > >
> Close_Price(250)*0.75. Is  >
> > there a way?
> >  > >  >
> >  > >  > Thanks!
> >  > >  >
> >  > >  >
> >  > >  >
> >  > >  > Klaus Meffert-5 wrote:
> >  > >  > >
> >  > >  > > Igor2,
> >  > >  > >
> >  > >  > > Maybe take a look at the example with class  >  > >
> > examples.gp.MathProblem.
> >  > >  > > In
> >  > >  > > create() you see the definition of possible GP  >
> commands.
> > For your  > > > > case, you should skip the second part of
> argTypes  >
> > definition  > >  > > >  > >  >
> >
> ("{CommandGene.FloatClass,CommandGene.FloatClass,CommandGene.FloatClas
> >  > >  > > s}"), and the second part of the nodeSets
> definition ("new  
> > >  > > Add3(conf,  > > CommandGene.FloatClass)").
> >  > >  > >
> >  > >  > > For the ">=" part, you could use command  >  > >
> > org.jgap.gp.function.GreaterThan.
> >  > >  > >
> >  > >  > > Yes, a function can of course output three solutions.
> >  > Just create
> >  > > a  > > function that returns, say, 1, 2, or 3. 1 is  >
> > interpreted as  >  > > buy, 2 is  > > sell, 3 is hold...
> >  > >  > >
> >  > >  > >
> >  > >  > >
> >  > >  > > Best
> >  > >  > >
> >  > >  > > Klaus
> >  > >  > > www.klaus-meffert.com
> >  > >  > >
> >  > >  > >
> >  > >  > >
> >  > >  > >> -----Original Message-----
> >  > >  > >> From: jgap-users-bounces@...
> >  > >  > >>
> [mailto:jgap-users-bounces@...] On  > >
> > Behalf  > > Of Igor2  > >> Sent: Wednesday, April 02, 2008
> 6:28 PM  >
> > >> To:
> >  > > jgap-users@...  > >> Subject:
> >  > [jgap-users] Need some
> >  > > help with GP  > >>  > >>  > >> I am currently working on a
> > research  > > project involving  > creating trade  > >> strategies
> > based  > on GAs and  > > GPs. GA part worked perfectly  > with JGAP.
> >  > >  > >> Now I am trying to understand the GP framework...
> >  > Still I  > am
> >  > > having  > >> some problems.
> >  > >  > >>
> >  > >  > >> Basically I want to input different variables like  >
> > today's and  > > > >> yesterday's prices and volumes, some
> terminals
> > and  > some functions  > > > >> like moving averages.
> >  > >  > >> Idea is to have GP to generate function in form of:
> >  > >  > >>
> >  > >  > >> SMA(200) + todayClose*0.5 >= yesterdayClose^2  >
> >>  > >>
> > If  > > this expression is true the automated trading agent will  >
> > sell,  > >>  > > else buy etc.
> >  > >  > >>
> >  > >  > >> My question now: Can somebody help me with public  >
> > GPGenotype  >  > > >> create() part?
> >  > >  > >>
> >  > >  > >> I don´t understand how I can initialize an array of  >
> > multiple  >  > > >> variables? How can I create a function
> in form of  
> > > expressions  > > {>,<,=}  > >> expressions2? Is it possible to
> > directly  > create function  > > > with three  > >>
> different outputs:
> > buy, sell & hold…  > >>  > >>  > > JGAP is an awesome framework &
> > helped me a lot during my  >  > project. I  > > > >> hope I can
> > overcome my luck of knowledge and use it further.
> >  > >  > >>
> >  > >  > >> Thanks!
> >  > >  > >
> >  > >  > >
> >  > >  > >
> >  > >  >
> >  > >
> >  >
> >
> ----------------------------------------------------------------------
> >  > >  > > --- Check out the new SourceForge.net Marketplace.
> >  > >  > > It's the best place to buy or sell services for
> just about  
> > > > anything  > > Open Source.
> >  > >  > >
> >  > >  >
> >  > >
> >  >
> >
> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marke
> >  > >  > > tplace _______________________________________________
> >  > >  > > jgap-users mailing list
> >  > >  > > jgap-users@...  > >  > >
> > https://lists.sourceforge.net/lists/listinfo/jgap-users
> >  > >  > >
> >  > >  > >
> >  > >  >
> >  > >  > --
> >  > >  > View this message in context:
> >  > >  >
> >  > >
> >  >
> >
> http://www.nabble.com/Need-some-help-with-GP-tp16447435p16467559.html
> >  > >  > Sent from the jgap-users mailing list archive at Nabble.com.
> >  > >  >
> >  > >  >
> >  > >  >
> --------------------------------------------------------------
> >  > >  > -----------
> >  > >  > Check out the new SourceForge.net Marketplace.
> >  > >  > It's the best place to buy or sell services for  >
> just about  
> > > > anything Open Source.
> >  > >  >
> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.n
> >  > >  > et/marketplace
> >  > >  > _______________________________________________
> >  > >  > jgap-users mailing list
> >  > >  > jgap-users@...  > >  >
> > https://lists.sourceforge.net/lists/listinfo/jgap-users
> >  > >  >
> >  > >
> >  > >
> >  >
> >  >
> >  >
> >  > --
> >  > Best regards,
> >  >
> >  > Igor Lukin
> >  >
> >  > Exchange Student at College of Engineering University of  >
> > Illinois at Urbana-Champaign  >  > Graduate Student – Business
> > Administration and Computer  > Science Darmstadt University of
> > Technology  >  > Tel: +1 217 721 8873  > Email:
> Igor.Lukin@...  
> > >  > 1107 S. Second St. Apt. 25  > Champaign, IL 61820  > USA  >
> >
> >
>
>
>
> --
> Best regards,
>
> Igor Lukin
>
> Exchange Student at College of Engineering University of
> Illinois at Urbana-Champaign
>
> Graduate Student – Business Administration and Computer
> Science Darmstadt University of Technology
>
> Tel: +1 217 721 8873
> Email: Igor.Lukin@...
>
> 1107 S. Second St. Apt. 25
> Champaign, IL 61820
> USA
>


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
jgap-users mailing list
jgap-users@...
https://lists.sourceforge.net/lists/listinfo/jgap-users

Parent Message unknown Re: Need some help with GP

by Igor2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks.

 I still have some problems.

 How can I tell my function (e.g. sma) to use the terminal as an input
parameter.

  public double execute_double(ProgramChromosome a_chrom, int a_n,
 Object[] a_args) {

          return
Signal.sma(((Integer)(((org.jgap.gp.terminal.Variable)a_args[0]).getValue())).intValue(),TradeGP.stock,
 25);
  }

 Instead 25 it should use the terminal generated by GP. How can I achieve this?



 On Fri, Apr 4, 2008 at 11:37 AM, Klaus Meffert <jgap@...> wrote:
 > Igor,
 >
 >  Simply declare (in method create()):
 >  ...
 >   new Terminal(conf, Terminal.class, 2.0d, 10.0d,
 >  ...
 >
 >  --> make return type of your Terminal a distinct type, e.g. "Terminal.class"
 >  in the above example. You could also implement a new and empty class of your
 >  own instead and use it as a dummy type.
 >
 >  Then, in your GP command, define which child types are allowed, e.g. by
 >  adding the following method:
 >   /**
 >    * Determines which type a specific child of this command has.
 >    *
 >    * @param a_ind ignored here
 >    * @param a_chromNum index of child
 >    * @return type of the a_chromNum'th child
 >    */
 >   public Class getChildType(IGPProgram a_ind, int a_chromNum) {
 >     if (a_chromNum == 0) {
 >       return Integer.class;
 >     }
 >     else {
 >       return Terminal.class;
 >     }
 >   }
 >
 >
 >  With that the first child must have return Integer and all other children
 >  must be a terminal (see top of my mail: "Terminal.class" <-- Notice: as
 >  said, you could use any Dummy class, just replace "Terminal.class" mentioned
 >  in this mail with "YourDummyClass.class").
 >
 >
 >  Klaus
 >  www.klaus-meffert.com
 >
 >
 >
 >  > -----Original Message-----
 >  > From: Igor Lukin [mailto:igor.lukin@...]
 >
 >
 > > Sent: Friday, April 04, 2008 4:43 PM
 >  > To: Klaus Meffert
 >  > Cc: jgap-users@...
 >  > Subject: Re: [jgap-users] Need some help with GP
 >  >
 >  > Hi,
 >  >
 >  > thanks. Now I understand the thing with limiting inputs and
 >  > punishing wrong outputs.
 >  >
 >  > Can you maybe give me a code example of how to access a
 >  > terminal to pass it to my function (like sma)? I could not
 >  > really understand how it worked in MathProblem. I looked at
 >  > some functions already implemented like Sine, but they all
 >  > use variables as their input...
 >  >
 >  > I attached my TradeGP.java...
 >  >
 >  > Sorry for so many questions, but at some point I am just stuck :(
 >  >
 >  > Thanks.
 >  >
 >  > Best regards,
 >  >
 >  > Igor
 >  >
 >  > On Fri, Apr 4, 2008 at 3:02 AM, Klaus Meffert
 >  > <jgap@...> wrote:
 >  > > Igor,
 >  > >
 >  > >  OK, I think I understood what you are asking for.
 >  > >
 >  > >  1) Yes you can use a terminal in GP and also use it as
 >  > input for your
 >  > > Sma  class. In the MathProblem class in method create() a
 >  > Terminal is used, too.
 >  > >  As it is of type Float it can serve as input parameter for any GP
 >  > > command  that allows a child to have Float type.
 >  > >  2) You can alter the return type ("Class[] type") to Integer.
 >  > > However, your  fitness function must punish values that are outside
 >  > > your desired range. To  limit the range somehow, you could
 >  > specify the
 >  > > range of inputs, e.g. as with
 >  > >  MathProblem:
 >  > >  new Terminal(conf, CommandGene.FloatClass, 2.0d, 10.0d,
 >  > true)  This
 >  > > Terminal can only have values between 2.0 and 10.0
 >  > >
 >  > >
 >  > >  Best
 >  > >
 >  > >  Klaus
 >  > >  www.klaus-meffert.com
 >  > >
 >  > >
 >  > >
 >  > >  > -----Original Message-----
 >  > >
 >  > >
 >  > > > From: Igor Lukin [mailto:igor.lukin@...]
 >  > >  > Sent: Thursday, April 03, 2008 9:54 PM  > To: Klaus
 >  > Meffert  > Cc:
 >  > > jgap-users@...  > Subject: Re: [jgap-users] Need
 >  > > some help with GP  >  > Hi,  >  > Thanks for your answer. Let me
 >  > > clarify my point.
 >  > >  >
 >  > >  > I am currently getting expression generated in such form:
 >  > >  >
 >  > >  > (SMA5_50 - Price) < (9.0 * SMA5_50)  >  > SMA_50 and Price are
 >  >