Posted By: trenki2
Zorro Crashes (too many algorithms?) - 08/20/16 08:37
I have the following code. It unfortunately crashes Zorro without saying why. It seems to have to do with the large number of algorithms in the algo loop (600):
The Idea of the experiment was to have one algorithm for each startHour/endHour/shortOrLong combination, let Zorro trade all of them and let Zorro compute OptimalF values and then later try to add an Equity filter. I wanted to compare this approach to the one where the optimize function tries to find the best startHour/endHour combination.
Edit: I figured 600 algos/600 cases is just way too slow.
Code:
#define LONG 0 #define SHORT 1 bool Reinvest = false; bool UseOptimalF = true; var CalculateMargin(int shortOrLong) { var value = 0.1 * Capital; if (Reinvest) { value *= sqrt(Balance/Capital); //value *= sqrt(1 + max(0, ProfitClosed/Capital)); } if (UseOptimalF) { if (shortOrLong == SHORT) value *= OptimalFShort; else value *= OptimalFLong; } return value; } #define ISALGOS "IS-0-1-0", "IS-0-1-1", "IS-0-2-0", "IS-0-2-1", "IS-0-3-0", "IS-0-3-1", "IS-0-4-0", "IS-0-4-1", "IS-0-5-0", "IS-0-5-1", "IS-0-6-0", "IS-0-6-1", "IS-0-7-0", "IS-0-7-1", "IS-0-8-0", "IS-0-8-1", "IS-0-9-0", "IS-0-9-1", "IS-0-10-0", "IS-0-10-1", "IS-0-11-0", "IS-0-11-1", "IS-0-12-0", "IS-0-12-1", "IS-0-13-0", "IS-0-13-1", "IS-0-14-0", "IS-0-14-1", "IS-0-15-0", "IS-0-15-1", "IS-0-16-0", "IS-0-16-1", "IS-0-17-0", "IS-0-17-1", "IS-0-18-0", "IS-0-18-1", "IS-0-19-0", "IS-0-19-1", "IS-0-20-0", "IS-0-20-1", "IS-0-21-0", "IS-0-21-1", "IS-0-22-0", "IS-0-22-1", "IS-0-23-0", "IS-0-23-1", "IS-0-0-0", "IS-0-0-1", "IS-1-2-0", "IS-1-2-1", "IS-1-3-0", "IS-1-3-1", "IS-1-4-0", "IS-1-4-1", "IS-1-5-0", "IS-1-5-1", "IS-1-6-0", "IS-1-6-1", "IS-1-7-0", "IS-1-7-1", "IS-1-8-0", "IS-1-8-1", "IS-1-9-0", "IS-1-9-1", "IS-1-10-0", "IS-1-10-1", "IS-1-11-0", "IS-1-11-1", "IS-1-12-0", "IS-1-12-1", "IS-1-13-0", "IS-1-13-1", "IS-1-14-0", "IS-1-14-1", "IS-1-15-0", "IS-1-15-1", "IS-1-16-0", "IS-1-16-1", "IS-1-17-0", "IS-1-17-1", "IS-1-18-0", "IS-1-18-1", "IS-1-19-0", "IS-1-19-1", "IS-1-20-0", "IS-1-20-1", "IS-1-21-0", "IS-1-21-1", "IS-1-22-0", "IS-1-22-1", "IS-1-23-0", "IS-1-23-1", "IS-1-0-0", "IS-1-0-1", "IS-2-3-0", "IS-2-3-1", "IS-2-4-0", "IS-2-4-1", "IS-2-5-0", "IS-2-5-1", "IS-2-6-0", "IS-2-6-1", "IS-2-7-0", "IS-2-7-1", "IS-2-8-0", "IS-2-8-1", "IS-2-9-0", "IS-2-9-1", "IS-2-10-0", "IS-2-10-1", "IS-2-11-0", "IS-2-11-1", "IS-2-12-0", "IS-2-12-1", "IS-2-13-0", "IS-2-13-1", "IS-2-14-0", "IS-2-14-1", "IS-2-15-0", "IS-2-15-1", "IS-2-16-0", "IS-2-16-1", "IS-2-17-0", "IS-2-17-1", "IS-2-18-0", "IS-2-18-1", "IS-2-19-0", "IS-2-19-1", "IS-2-20-0", "IS-2-20-1", "IS-2-21-0", "IS-2-21-1", "IS-2-22-0", "IS-2-22-1", "IS-2-23-0", "IS-2-23-1", "IS-2-0-0", "IS-2-0-1", "IS-3-4-0", "IS-3-4-1", "IS-3-5-0", "IS-3-5-1", "IS-3-6-0", "IS-3-6-1", "IS-3-7-0", "IS-3-7-1", "IS-3-8-0", "IS-3-8-1", "IS-3-9-0", "IS-3-9-1", "IS-3-10-0", "IS-3-10-1", "IS-3-11-0", "IS-3-11-1", "IS-3-12-0", "IS-3-12-1", "IS-3-13-0", "IS-3-13-1", "IS-3-14-0", "IS-3-14-1", "IS-3-15-0", "IS-3-15-1", "IS-3-16-0", "IS-3-16-1", "IS-3-17-0", "IS-3-17-1", "IS-3-18-0", "IS-3-18-1", "IS-3-19-0", "IS-3-19-1", "IS-3-20-0", "IS-3-20-1", "IS-3-21-0", "IS-3-21-1", "IS-3-22-0", "IS-3-22-1", "IS-3-23-0", "IS-3-23-1", "IS-3-0-0", "IS-3-0-1", "IS-4-5-0", "IS-4-5-1", "IS-4-6-0", "IS-4-6-1", "IS-4-7-0", "IS-4-7-1", "IS-4-8-0", "IS-4-8-1", "IS-4-9-0", "IS-4-9-1", "IS-4-10-0", "IS-4-10-1", "IS-4-11-0", "IS-4-11-1", "IS-4-12-0", "IS-4-12-1", "IS-4-13-0", "IS-4-13-1", "IS-4-14-0", "IS-4-14-1", "IS-4-15-0", "IS-4-15-1", "IS-4-16-0", "IS-4-16-1", "IS-4-17-0", "IS-4-17-1", "IS-4-18-0", "IS-4-18-1", "IS-4-19-0", "IS-4-19-1", "IS-4-20-0", "IS-4-20-1", "IS-4-21-0", "IS-4-21-1", "IS-4-22-0", "IS-4-22-1", "IS-4-23-0", "IS-4-23-1", "IS-4-0-0", "IS-4-0-1", "IS-5-6-0", "IS-5-6-1", "IS-5-7-0", "IS-5-7-1", "IS-5-8-0", "IS-5-8-1", "IS-5-9-0", "IS-5-9-1", "IS-5-10-0", "IS-5-10-1", "IS-5-11-0", "IS-5-11-1", "IS-5-12-0", "IS-5-12-1", "IS-5-13-0", "IS-5-13-1", "IS-5-14-0", "IS-5-14-1", "IS-5-15-0", "IS-5-15-1", "IS-5-16-0", "IS-5-16-1", "IS-5-17-0", "IS-5-17-1", "IS-5-18-0", "IS-5-18-1", "IS-5-19-0", "IS-5-19-1", "IS-5-20-0", "IS-5-20-1", "IS-5-21-0", "IS-5-21-1", "IS-5-22-0", "IS-5-22-1", "IS-5-23-0", "IS-5-23-1", "IS-5-0-0", "IS-5-0-1", "IS-6-7-0", "IS-6-7-1", "IS-6-8-0", "IS-6-8-1", "IS-6-9-0", "IS-6-9-1", "IS-6-10-0", "IS-6-10-1", "IS-6-11-0", "IS-6-11-1", "IS-6-12-0", "IS-6-12-1", "IS-6-13-0", "IS-6-13-1", "IS-6-14-0", "IS-6-14-1", "IS-6-15-0", "IS-6-15-1", "IS-6-16-0", "IS-6-16-1", "IS-6-17-0", "IS-6-17-1", "IS-6-18-0", "IS-6-18-1", "IS-6-19-0", "IS-6-19-1", "IS-6-20-0", "IS-6-20-1", "IS-6-21-0", "IS-6-21-1", "IS-6-22-0", "IS-6-22-1", "IS-6-23-0", "IS-6-23-1", "IS-6-0-0", "IS-6-0-1", "IS-7-8-0", "IS-7-8-1", "IS-7-9-0", "IS-7-9-1", "IS-7-10-0", "IS-7-10-1", "IS-7-11-0", "IS-7-11-1", "IS-7-12-0", "IS-7-12-1", "IS-7-13-0", "IS-7-13-1", "IS-7-14-0", "IS-7-14-1", "IS-7-15-0", "IS-7-15-1", "IS-7-16-0", "IS-7-16-1", "IS-7-17-0", "IS-7-17-1", "IS-7-18-0", "IS-7-18-1", "IS-7-19-0", "IS-7-19-1", "IS-7-20-0", "IS-7-20-1", "IS-7-21-0", "IS-7-21-1", "IS-7-22-0", "IS-7-22-1", "IS-7-23-0", "IS-7-23-1", "IS-7-0-0", "IS-7-0-1", "IS-8-9-0", "IS-8-9-1", "IS-8-10-0", "IS-8-10-1", "IS-8-11-0", "IS-8-11-1", "IS-8-12-0", "IS-8-12-1", "IS-8-13-0", "IS-8-13-1", "IS-8-14-0", "IS-8-14-1", "IS-8-15-0", "IS-8-15-1", "IS-8-16-0", "IS-8-16-1", "IS-8-17-0", "IS-8-17-1", "IS-8-18-0", "IS-8-18-1", "IS-8-19-0", "IS-8-19-1", "IS-8-20-0", "IS-8-20-1", "IS-8-21-0", "IS-8-21-1", "IS-8-22-0", "IS-8-22-1", "IS-8-23-0", "IS-8-23-1", "IS-8-0-0", "IS-8-0-1", "IS-9-10-0", "IS-9-10-1", "IS-9-11-0", "IS-9-11-1", "IS-9-12-0", "IS-9-12-1", "IS-9-13-0", "IS-9-13-1", "IS-9-14-0", "IS-9-14-1", "IS-9-15-0", "IS-9-15-1", "IS-9-16-0", "IS-9-16-1", "IS-9-17-0", "IS-9-17-1", "IS-9-18-0", "IS-9-18-1", "IS-9-19-0", "IS-9-19-1", "IS-9-20-0", "IS-9-20-1", "IS-9-21-0", "IS-9-21-1", "IS-9-22-0", "IS-9-22-1", "IS-9-23-0", "IS-9-23-1", "IS-9-0-0", "IS-9-0-1", "IS-10-11-0", "IS-10-11-1", "IS-10-12-0", "IS-10-12-1", "IS-10-13-0", "IS-10-13-1", "IS-10-14-0", "IS-10-14-1", "IS-10-15-0", "IS-10-15-1", "IS-10-16-0", "IS-10-16-1", "IS-10-17-0", "IS-10-17-1", "IS-10-18-0", "IS-10-18-1", "IS-10-19-0", "IS-10-19-1", "IS-10-20-0", "IS-10-20-1", "IS-10-21-0", "IS-10-21-1", "IS-10-22-0", "IS-10-22-1", "IS-10-23-0", "IS-10-23-1", "IS-10-0-0", "IS-10-0-1", "IS-11-12-0", "IS-11-12-1", "IS-11-13-0", "IS-11-13-1", "IS-11-14-0", "IS-11-14-1", "IS-11-15-0", "IS-11-15-1", "IS-11-16-0", "IS-11-16-1", "IS-11-17-0", "IS-11-17-1", "IS-11-18-0", "IS-11-18-1", "IS-11-19-0", "IS-11-19-1", "IS-11-20-0", "IS-11-20-1", "IS-11-21-0", "IS-11-21-1", "IS-11-22-0", "IS-11-22-1", "IS-11-23-0", "IS-11-23-1", "IS-11-0-0", "IS-11-0-1", "IS-12-13-0", "IS-12-13-1", "IS-12-14-0", "IS-12-14-1", "IS-12-15-0", "IS-12-15-1", "IS-12-16-0", "IS-12-16-1", "IS-12-17-0", "IS-12-17-1", "IS-12-18-0", "IS-12-18-1", "IS-12-19-0", "IS-12-19-1", "IS-12-20-0", "IS-12-20-1", "IS-12-21-0", "IS-12-21-1", "IS-12-22-0", "IS-12-22-1", "IS-12-23-0", "IS-12-23-1", "IS-12-0-0", "IS-12-0-1", "IS-13-14-0", "IS-13-14-1", "IS-13-15-0", "IS-13-15-1", "IS-13-16-0", "IS-13-16-1", "IS-13-17-0", "IS-13-17-1", "IS-13-18-0", "IS-13-18-1", "IS-13-19-0", "IS-13-19-1", "IS-13-20-0", "IS-13-20-1", "IS-13-21-0", "IS-13-21-1", "IS-13-22-0", "IS-13-22-1", "IS-13-23-0", "IS-13-23-1", "IS-13-0-0", "IS-13-0-1", "IS-14-15-0", "IS-14-15-1", "IS-14-16-0", "IS-14-16-1", "IS-14-17-0", "IS-14-17-1", "IS-14-18-0", "IS-14-18-1", "IS-14-19-0", "IS-14-19-1", "IS-14-20-0", "IS-14-20-1", "IS-14-21-0", "IS-14-21-1", "IS-14-22-0", "IS-14-22-1", "IS-14-23-0", "IS-14-23-1", "IS-14-0-0", "IS-14-0-1", "IS-15-16-0", "IS-15-16-1", "IS-15-17-0", "IS-15-17-1", "IS-15-18-0", "IS-15-18-1", "IS-15-19-0", "IS-15-19-1", "IS-15-20-0", "IS-15-20-1", "IS-15-21-0", "IS-15-21-1", "IS-15-22-0", "IS-15-22-1", "IS-15-23-0", "IS-15-23-1", "IS-15-0-0", "IS-15-0-1", "IS-16-17-0", "IS-16-17-1", "IS-16-18-0", "IS-16-18-1", "IS-16-19-0", "IS-16-19-1", "IS-16-20-0", "IS-16-20-1", "IS-16-21-0", "IS-16-21-1", "IS-16-22-0", "IS-16-22-1", "IS-16-23-0", "IS-16-23-1", "IS-16-0-0", "IS-16-0-1", "IS-17-18-0", "IS-17-18-1", "IS-17-19-0", "IS-17-19-1", "IS-17-20-0", "IS-17-20-1", "IS-17-21-0", "IS-17-21-1", "IS-17-22-0", "IS-17-22-1", "IS-17-23-0", "IS-17-23-1", "IS-17-0-0", "IS-17-0-1", "IS-18-19-0", "IS-18-19-1", "IS-18-20-0", "IS-18-20-1", "IS-18-21-0", "IS-18-21-1", "IS-18-22-0", "IS-18-22-1", "IS-18-23-0", "IS-18-23-1", "IS-18-0-0", "IS-18-0-1", "IS-19-20-0", "IS-19-20-1", "IS-19-21-0", "IS-19-21-1", "IS-19-22-0", "IS-19-22-1", "IS-19-23-0", "IS-19-23-1", "IS-19-0-0", "IS-19-0-1", "IS-20-21-0", "IS-20-21-1", "IS-20-22-0", "IS-20-22-1", "IS-20-23-0", "IS-20-23-1", "IS-20-0-0", "IS-20-0-1", "IS-21-22-0", "IS-21-22-1", "IS-21-23-0", "IS-21-23-1", "IS-21-0-0", "IS-21-0-1", "IS-22-23-0", "IS-22-23-1", "IS-22-0-0", "IS-22-0-1", "IS-23-0-0", "IS-23-0-1" typedef struct { string name; int type; int startHour; int endHour; } ISALGOPARAMS; ISALGOPARAMS *ISAlgoParams; ISALGOPARAMS* FindISAlgoParams(string name) { int i; for (i = 0; i < 600; ++i) { if (ISAlgoParams[i].name == name) return &ISAlgoParams[i]; } return NULL; } void InitializeIS() { ISAlgoParams = malloc(600 * sizeof(ISALGOPARAMS)); int sh, eh, sl, count = 0; for (sh = 0; sh <= 23; sh++) for (eh = sh + 1; eh <= 24; eh++) { for (sl = 0; sl < 2; ++sl) { char name[12]; sprintf(name, "IS-%i-%i-sl", sh, eh % 24, sl); ISAlgoParams[count].type = sl; ISAlgoParams[count].name = name; ISAlgoParams[count].startHour = sh; ISAlgoParams[count].endHour = eh % 24; count++; } } } function TradeISLong(int startHour, int endHour) { if (dow() >= 1 && dow() <= 5) { Margin = CalculateMargin(LONG); if (NumOpenLong == 0 && hour() == startHour) enterLong(); if (NumOpenLong > 0 && hour() == endHour) exitLong(); } } function TradeISShort(int startHour, int endHour) { if (dow() >= 1 && dow() <= 5) { Margin = CalculateMargin(SHORT); if (NumOpenShort == 0 && hour() == startHour) enterShort(); if (NumOpenShort > 0 && hour() == endHour) exitShort(); } } function run() { BarPeriod = 60; StartDate = 20150101; EndDate = 20160101; InitializeIS(); /* while (asset(loop("EUR/USD"))) while (algo(loop(ISALGOS))) { } */ while (asset(loop("EUR/USD"))) while (algo(loop(ISALGOS))) { ISALGOPARAMS *p = FindISAlgoParams(Algo); if (p->type == 0) TradeISShort(p->startHour, p->endHour); else TradeISLong(p->startHour, p->endHour); } }
The Idea of the experiment was to have one algorithm for each startHour/endHour/shortOrLong combination, let Zorro trade all of them and let Zorro compute OptimalF values and then later try to add an Equity filter. I wanted to compare this approach to the one where the optimize function tries to find the best startHour/endHour combination.
Edit: I figured 600 algos/600 cases is just way too slow.