FACTORS flag

Posted By: 3DCat

FACTORS flag - 07/23/13 10:17

Hi, I'm just struggling how to properly test my strategies i play with:)
At the moment i have a question about the capital allocation factors.

I understand that if the FACTORS flag is set the OptimalF factors are generated from the whole training+test period - not only from the training period.

a) is this done dynamically step by step while the test period is running on the test period? Or is the whole training+test period used to allocate optimalF factors BEFORE running the actual WalkForward Test?

b) is there a FLAG or method i could use to only train the OptimalF Factors from the training period only?

Thanks:)
Posted By: jcl

Re: FACTORS flag - 07/23/13 10:28

It is done by running a complete walk-forward test and then calculating the factors from this test.

Taking factors only from a certain period must be done by script. For this, first generate the parameters, then set only the FACTORS flag, and exclude trades from outside the desired period with an if(..) condition, like this:

if(year() < 2011 or month() < 6) enterLong();

or

if(year() >= 2011 and month() >= 6) quit();

for only calculating factors until June 2011. Setting StartDate and EndDate won't work here because it would also affect the WFO cycles.
Posted By: 3DCat

Re: FACTORS flag - 07/23/13 10:53

Ok thanks! I will use that. Your help is very appreciated!

Wouldn't it be more realistic to have the Factors be created "on the run" as if you were retraining every week in live trading for example? Instead of getting them "from the future":)

I can't think of a practical way of implementing that in a script though
Posted By: jcl

Re: FACTORS flag - 07/23/13 15:09

OptimalF factors need a relatively large trade history. So they should not be calculated on the run for the past weeks - those factors could be way off and misleading.
Posted By: 3DCat

Re: FACTORS flag - 07/23/13 15:39

Ok sorry to be nagging, but i didn't mean to calculate them from a few weeks only, but from the beginning of the training period right into the test period to the point where zorro "walks forward" at the moment. Simply not taking into account the rest of the test period that lies "in the future" from the single trade perspective.

Could that be implemented somehow? I get huge discrepancies in backtesting with vs without factors.
I am just testing your tip from above though.. sounds pretty reasonable.

I just don't feel good backtesting if you take into account information that would practically lie in the future:)
Posted By: dusktrader

Re: FACTORS flag - 07/24/13 10:13

Please correct me if I'm wrong here in my understanding... but FACTORS are mostly used for trade weighting purposes... ie, to know "how much" of a component your strategy should buy or sell.

Since I believe this is the case, what I normally do is work with flat-lots only (ie, minimum Lots=1) to develop the strategy first. You want to make sure the trading logic is correct/profitable before applying any OptimalF "enhancements"

Once the trading logic is in place, then you can use OptimalF to weight your trade basket accordingly, so that the most profitable trades historically get precisely the optimal allocation factor of your funds.

To me it is a mistake and very misleading to allow Lots > 1 while developing the strategy.

Again, please correct my line of thinking if this is not correct. I'm still a n00b too. But I personally feel this philosophy has served me well in my discretionary trading.
Posted By: jcl

Re: FACTORS flag - 07/24/13 10:53

This is absolutely correct. Factors and Margin should not be used for developing, only for the final trading. If you have a losing portfolio system, but convert it to winning with OptimalF factors, the profits come likely not from the system but from selection bias.

Aside from that, you can generate factors at runtime in a retraining process. But unlike parameters, factors normally need not be updated often. It's normally sufficient to do that once a year.
Posted By: 3DCat

Re: FACTORS flag - 07/24/13 11:07

OK, my strategy was developed like that - without the Factors flag, exactly for the reasons you wrote... but now everything gets more complicated...
I first added a few Algos, then a lot of additional assets. Somewhere on the way i noticed the strategy wasn't profitable anymore if i excluded the FActors flag. But with it, it is hugely profitable.
So im actually now trying to discern what is reasonable and what isn't. Perhaps i should go a few steps back.

I'm still playing around with different methods of Factor allocation for only a limited timeperiod. I'll report back when im done.
Posted By: dusktrader

Re: FACTORS flag - 07/24/13 14:14

My opinion is that you should not try to define "reasonable" or put it in a box. Because I'd say 100% of your definition of that comes from what the media reports, and that is definitely wrong (or at least limiting).

Instead, keep an open mind, a clean slate. My personal intention is to just see what shakes out and learn along the way. Perhaps you will find that your definition of "reasonable" is some combination of high profit factor and low drawdown. You'll probably get a sense for it over time.

One use of OptimalF that I am exploring, that I think should be "ok", is for the purpose ONLY of knowing which pairs/algos/directions to trade. In other words, let your backtest run all variations of pairs/algos/directions and then based on OptimalF, trade only those proven profitable... but do not apply the OptF factor to the trade weight.

In other words... test every combination, but only keep the ones that show any profitability at all. Still test only with minimum flat lots.

Depending on your strategy, my guess is that some assets will show "excellent" performance while others will seem only "mediocre". However, OptimalF does know best... so once you find the cream-of-crop, you can then apply OptimalF to maximize your bang-for-buck.
Posted By: 3DCat

Re: FACTORS flag - 08/09/13 11:23

Im back from holidays:p
Ok, i rechecked all my Algos(I'm having fun with them), and what i did is this:

I tested them without FACTORS
I tested them with fixed FACTORS(eg. everything on 0.1 - no idea if that helps, but i managed to test Z12 like that)
I tested them with FACTORS which where only generated in the Training period.
What i learned is you should really proceed step by step - if a script isn't profitable without FACTORS, it probably will never be - thus i ditched a few:(

Also i thought a lot about SelectionBias. I can't write a script without it - i mean you change a thing and hit Test- if it doesn't work out, you change something until you get a straight equity curve. implementing the PARAMETERS is great help for that! I first didn't grasp it - but i think a script is less biased WITH PARAMETERS than without.

Last thing to overcome SelectionBias: Im running my backtests on a MacBookPro with WinOnX. I can't download any PriceData there(but btw its much faster than on Windows8 on the same MBP), so my SelectionBias only runs until early 2013. Thus i can see if it still performs after that later.
Posted By: dusktrader

Re: FACTORS flag - 08/09/13 12:37

You should be able to download data through the Download script using your Mac emulator. Why do you say it doesn't work?

Also, you can simply copy the .bar files from Windows to Mac if that helps. There is a default set and more you can download right from this website (including EURUSD all the way back to 2002)

SelectionBias... I personally think there is no way to avoid it on some level. It is not "bad" in my opinion, unless you are trying to build some strategy logic that works for everything and can hit the ground running. In other words, to me at least, that seems a bit unlikely. I'd rather choose SOME of the characteristics of the assets to be traded (for example, I might not trade EURDKK which has low history, low volume and jumpy volatility).

I could be wrong about this, but I think the FACTORS flag is only useful if you are somehow using OptimalF calculations in your script (FACTORS just tells Zorro to calculate OptimalF for each asset during training). The intent of using those factors, as I understand, is for trade weighting purposes (ie, in a basket portfolio of assets, allow a specific factor of margin to be given to a particular Asset/Algo/Direction combination)

As always, let me know if you disagree or see anything a different way!

PS: I read somewhere in the manual that if you do utilize OptimalF in your script, but don't turn on the FACTORS flag... then all factors are set to 1 (ie, equal weight)
Posted By: 3DCat

Re: FACTORS flag - 08/09/13 13:58

The Broker DLLs don't work with the Emulator. But thats ok, because i have Windows also- and a VM.

Whats the most interesting thing about Zorro is being creative and develop scripts:) Its nice to learn how it works - and how to not overfit a strategy is one of the more difficult parts i guess.

And yes - of course i have some OptimalF calculations in my script:) otherwise they would be pretty useless!

Youre right about the OptF Values being set to 1 when FACTORS is not set.
© 2024 lite-C Forums