--- In [email protected], "pipadder" <pipad...@...> wrote:
>
> Hi,
>
> I am a systematic mechanical trader (almost exclusively forex). For the last
> couple of years [...]
Ok, it appears that trying to think in "array mode" is giving me a lot more
trouble than I expected. One of the main problems I am finding is the fact that
conditional execution of code (do/calculate stuff which needs to happen only
for some bars, but not for some others) doesn't seem obvious now, and I am
stuck. Or at least, the ways I can come up with to do things don't seem
efficient to me.
Perhaps the best way is to give a concrete example... I am trying to code a
system that is just a variation of your usual breakout box. I am working with a
1-minute bar database. So, the program is going to process these bars and
determine when to place the orders. This will happen once a day, for a given
bar (on a given minute, of course) which I can identify. Let's assume I am at
the point where my program has already determined which bars those are and I
have a nicely populated "buy" array with a few "1" here and there. The problem
comes now: to use volatility-adjusted stops, once a "buy bar" is known the
program needs to run some calculations that use a certain number of prior bars
(several hundreds of them, actually) to determine stop placement (sellprice),
order size, etc. So I am thinking about two possible options to do this:
1) Brute force. I run these calculations and determine the volatility-adjusted
stuff for every bar, whether it is a "buy" bar or not, so that I have those
numbers available in an appropriately created array when needed. This could be
done in AFL array style, but seems like total overkill: in a 1M database and to
place only one order a day, I would only need to run this calculation once
every 1440 bars. So running the calculation for every single bar looks quite
inefficient.
2) Conditional execution... Call a function that will perform the calculation
only for those bars which are tagged as "buy bars". Now... the only way I can
think of to do this is to just run a loop through the whole database and
perform the appropriate calculations only for the bars that require them. This
of course looks more efficient than the solution before, but I am not using the
advantages of simultaneous array operation anymore, and not having a good idea
of the speed advantage of array vs. loop operation I cannot really know whether
it is a better solution.
I suppose many of you have gone through this kind of problem, so do you guys
know which solution is better, or perhaps even have suggestions on how to do
this in a cleaner and more efficient way?
Thanks again for your continued patience!