Is it possible to generate trading rules from portfolio level statistics ?
Author: mikesblack
Creation Date: 10/2/2009 11:38 AM
profile picture

mikesblack

#1
Hi Cone and Eugene,

e.g. Data set: S and P 500.
Condition A: 5 day sma crosses over 10 day sma
Condition B: 20 day roc <= -10

If: Condition A
and
(percent of) data set(S and P 500)= condition B <= (e.g.50%)
then
buy at market.

--
This is just an example. It's just as well be number or percentage of portfolio >,< or = to some advances/ decliners ratio or really just meeting any condition. Is there any reference to this someplace and is this possible to create?

Thanks very much.
Mike
BTW Do you guys live in Ireland?
profile picture

Eugene

#2
Hi Mike,

Sure it's possible:
CODE:
Please log in to see this code.
profile picture

mikesblack

#3
Thanks Eugene. I'll work with it. Much appreciated.
profile picture

mikesblack

#4
roc_percent[ bar ]<= 50 is bool ConditionB is true as defined by the system.

What I would like to be able to accomplish is to write a system by rules and plug in bool ConditionB is true . Can this be done easily?

I just am not at the point where I know the language structure and syntax well enough to be able to formulate this without some form of "plug and play".

So system by rules + (ConditionB >= some variable ( 50 in this case.)is true) for entry.
Thanks.

CODE:
Please log in to see this code.
profile picture

Eugene

#5
CODE:
Please log in to see this code.

To attach Condition B to a rule-based strategy (of course, after converting to code-based strategy), copy and paste the whole code inside your Execute() method body and define ConditionB as shown above.
profile picture

mikesblack

#6
QUOTE:
copy and paste the whole code inside your Execute() method body and define ConditionB as shown above


Sorry Eugene, I'm not quite sure of what you mean.
profile picture

Eugene

#7
Do you see this?
CODE:
Please log in to see this code.

This is your Execute() method, aka the main entry point of a WealthScript program.

Copy the code inside the Execute() method of your posting and paste it inside the same method of a rule-based strategy. Say, right when it starts - after the opening curly brace.
profile picture

mikesblack

#8
Thanks . . .
So I did what you suggested and in addition, put "bool ConditionB= roc-pct[bar]<=50" at the end in addition to the other conditions for buying. At first I wrote," if ( conditionB, and also, if boolConditionB is true, but only the following compiled correctly so I assume that it is correct. I applied it on individual stocks, but have not checked if the results makes sense yet. I applied it to a data set of 500, but it froze.

Did I do this correctly?



CODE:
Please log in to see this code.
profile picture

Eugene

#9
No, that will compile but won't work because you're not putting ConditionB to use.

Look Mike, a complete example code was produced by your request but it's doesn't seem optimal to troubleshoot some changes to it going behind the scenes [which aren't obvious]. If you want to modify this code, please consider telling us your enhancement/idea and we'll see what can be done.
profile picture

mikesblack

#10

CODE:
Please log in to see this code.


Ok, So here is the buy conditions from the original example. I'm not interested in a simple moving average cross over system, but merely used it as a hypothetical with hope I could apply the same logic to many other strategies that I would like to test .

Perhaps my level of knowledge of programing makes understanding and applying this less easy than you or I would like at this time. It seems it may be too inefficient to tackle this at this stage and I would rather not take up your time with it if it isn't easy.

Thanks very much for trying, but if unless you can think of an easy solution that you think I might be able to grasp, I'll continue to grind away at the books.

Cheers.


profile picture

Eugene

#11
I always believed in power of learning by examples. If you show me some wizard-generated code you want to apply the portfolio level logic above, I'll plug it in and hopefully, this could help you.
profile picture

mikesblack

#12
Thanks. I am working hard at understanding c# programing and I hope these concepts will become clear soon.

Is it possible to make this filter, and or other similar ideas into an indicator that I can copy to the W.L. indicators folder from that I can then use in the drag and drop wizard? I don't see any fast and easy way to do this by design, but I believe I have read about it being done on one of the threads.

. Here is a modified version of the 3 x 2 system.

CODE:
Please log in to see this code.
profile picture

Eugene

#13
No, not as a drag-and-drop indicator.

Selecting external series for a formal indicator (e.g. Beta from Community.Indicators) isn't possible when used in drag & drop manner -- only in code-based strategies, but making it loop over a DataSet... formal indicators weren't designed for operating on external series.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).