0 registered members (),
1,397
guests, and 7
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Intraday seasonality in FX market
[Re: pcz]
#461098
07/25/16 14:48
07/25/16 14:48
|
Joined: Feb 2014
Posts: 181
RTG
Member
|
Member
Joined: Feb 2014
Posts: 181
|
|
|
|
Re: Intraday seasonality in FX market
[Re: RTG]
#461179
07/28/16 03:40
07/28/16 03:40
|
Joined: Feb 2014
Posts: 181
RTG
Member
|
Member
Joined: Feb 2014
Posts: 181
|
|
|
|
Re: Intraday seasonality in FX market
[Re: pcz]
#461892
08/27/16 17:38
08/27/16 17:38
|
Joined: Aug 2016
Posts: 95 Wien
trenki2
Junior Member
|
Junior Member
Joined: Aug 2016
Posts: 95
Wien
|
Thanks for sharing your system. I took the idea and adapted the algorithm. I thought the same system might work for other currency pairs with different time settings. The modified version uses Zorros optimize feature to automatically find profitable startHour and endHour pairs. The algorithm thus works using WFO optimization. The only thing that is not really out of sample is the OptimalF factors. Even though the drawdowns are less than in the original algorithm the average trade profit is reduced. Here are my results:
Walk-Forward Test Test1 portfolio
Simulated account AssetsFix
Bar period 1 hour (avg 87 min)
Simulation period 05.04.2007-24.08.2016 (56590 bars)
Test period 16.09.2011-24.08.2016 (29952 bars)
Lookback period 80 bars (3 days)
WFO test cycles 5 x 5990 bars (51 weeks)
Training cycles 6 x 23960 bars (206 weeks)
Monte Carlo cycles 200
Assumed slippage 10.0 sec
Capital invested 10000$
Gross win/loss 127761$ / -112703$ (+9647p)
Average profit 3048$/year, 254$/month, 12$/day
Max drawdown -1567$ 10% (MAE -1825$ 12%)
Total down time 90% (TAE 93%)
Max down time 14 weeks from Mar 2015
Max open margin 1239$
Max open risk 643$
Trade volume 140985019$ (28538185$/year)
Transaction costs -7182$ spr, -118$ slp, -88$ rol, -10585$ com
Capital required 2460$
Number of trades 9615 (1947/year, 38/week, 8/day)
Percent winning 50.0%
Max win/loss 597$ / -172$
Avg trade profit 1.57$ 1.0p (+17.0p / -15.0p)
Avg trade slippage -0.01$ -0.0p (+0.3p / -0.3p)
Avg trade bars 5 (+6 / -5)
Max trade bars 40 (40 hours)
Time in market 178%
Max open trades 10
Max loss streak 12 (uncorrelated 14)
Annual growth rate 20%
Profit factor 1.13 (PRR 1.10)
Sharpe ratio 0.96
Kelly criterion 3.02
R2 coefficient 0.842
Ulcer index 3.7%
Prediction error 124%
Confidence level AR DDMax Capital
10% 118% 1735$ 2591$
20% 112% 1911$ 2728$
30% 108% 2023$ 2816$
40% 101% 2278$ 3014$
50% 98% 2382$ 3095$
60% 95% 2511$ 3195$
70% 91% 2711$ 3352$
80% 86% 2963$ 3548$
90% 79% 3354$ 3852$
95% 74% 3725$ 4142$
100% 55% 5459$ 5493$
Portfolio analysis OptF ProF Win/Loss Wgt% Cycles
AUD/USD avg .070 1.17 1181/1091 42.1 /X/X/
EUR/USD avg .091 1.08 1244/1315 15.3 /\\\/
GBP/USD avg .000 ---- 0/0 0.0 .....
NZD/USD avg .045 1.13 1129/1173 12.2 X\/XX
USD/CAD avg .000 ---- 0/0 0.0 .....
USD/CHF avg .000 ---- 0/0 0.0 .....
USD/JPY avg .087 1.15 1258/1224 30.3 //XX/
ISL avg .039 1.09 2478/2505 35.6 XXXX/
ISS avg .054 1.17 2334/2298 64.4 /XXXX
AUD/USD:ISL .130 1.08 616/606 11.7 /\/\/
AUD/USD:ISL:L .130 1.08 616/606 11.7 /\/\/
AUD/USD:ISL:S .000 ---- 0/0 0.0 .....
AUD/USD:ISS .292 1.30 565/485 30.4 /////
AUD/USD:ISS:L .000 ---- 0/0 0.0 .....
AUD/USD:ISS:S .292 1.30 565/485 30.4 /////
EUR/USD:ISL .304 1.07 638/641 9.7 /\\\/
EUR/USD:ISL:L .304 1.07 638/641 9.7 /\\\/
EUR/USD:ISL:S .000 ---- 0/0 0.0 .....
EUR/USD:ISS .061 1.09 606/674 5.6 /\\\/
EUR/USD:ISS:L .000 ---- 0/0 0.0 .....
EUR/USD:ISS:S .061 1.09 606/674 5.6 /\\\/
NZD/USD:ISL .005 0.98 613/666 -0.2 \\/\/
NZD/USD:ISL:L .005 0.98 613/666 -0.2 \\/\/
NZD/USD:ISL:S .000 ---- 0/0 0.0 .....
NZD/USD:ISS .176 1.15 516/507 12.4 /\//\
NZD/USD:ISS:L .000 ---- 0/0 0.0 .....
NZD/USD:ISS:S .176 1.15 516/507 12.4 /\//\
USD/JPY:ISL .119 1.18 611/592 14.4 /////
USD/JPY:ISL:L .119 1.18 611/592 14.4 /////
USD/JPY:ISL:S .000 ---- 0/0 0.0 .....
USD/JPY:ISS .232 1.13 647/632 16.0 //\\/
USD/JPY:ISS:L .000 ---- 0/0 0.0 .....
USD/JPY:ISS:S .232 1.13 647/632 16.0 //\\/
And here is the code:
#define LONG 0
#define SHORT 1
bool Reinvest = false;
bool UseOptimalF = true;
var CalculateMargin(int side)
{
var value = 0.1 * Capital;
if (Reinvest)
{
value *= sqrt(Balance / Capital);
//value *= sqrt(1 + max(0, ProfitClosed/Capital));
}
if (UseOptimalF)
value *= ifelse(side == LONG, OptimalFLong, OptimalFShort);
return value;
}
int hoursLookup[300];
function Initialize()
{
int count = 0;
int startHour, endHour;
for (startHour = 0; startHour <= 23; ++startHour)
for (endHour = startHour + 1; endHour <= 24; ++endHour)
hoursLookup[count++] = (endHour % 24) * 24 + startHour;
}
int NumOpenTrades(int side)
{
string currentAsset = Asset;
string currentAlgo = Algo;
int count = 0;
for (open_trades)
{
if (strcmp(TradeAsset, currentAsset) != 0 || strcmp(TradeAlgo, currentAlgo) != 0)
continue;
if ((TradeIsLong && side == LONG) || (TradeIsShort && side == SHORT))
count++;
}
return count;
}
TRADE* EnterTrade(int side)
{
if (side == LONG)
return enterLong();
else
return enterShort();
}
void ExitTrade(int side)
{
if (side == LONG)
exitLong();
else
exitShort();
}
function TradeIS(int side)
{
int index = (int)(optimize(0, 0, 254, 1) / 254 * 299);
int startHour = hoursLookup[index] % 24;
int endHour = hoursLookup[index] / 24;
// Exit over the weekend.
if (dow() == FRIDAY && hour() >= 21)
{
exitLong();
exitShort();
}
Stop = 55 * PIP;
Trail = 10 * PIP;
// Don't trade from 00:00 to 00:00.
if (startHour == endHour)
return;
// Trade during the week.
if (dow() >= 1 && dow() <= 5)
{
Margin = CalculateMargin(side);
int numOpen = NumOpenTrades(side);
if (numOpen == 0 && hour() == startHour)
EnterTrade(side);
if (numOpen > 0 && hour() == endHour)
ExitTrade(side);
}
}
function run()
{
set(PARAMETERS + FACTORS);
StartDate = 2007;
EndDate = 2016;
BarPeriod = 60;
Capital = 10000;
DataSplit = 80;
WFOPeriod = (312 * 24) * DataSplit / (100 - DataSplit);
if (is(INITRUN))
Initialize();
while (asset(loop("AUD/USD", "EUR/USD", "GBP/USD", "NZD/USD", "USD/CAD", "USD/CHF", "USD/JPY")))
while (algo(loop("ISL", "ISS")))
{
if (Algo == "ISL")
TradeIS(LONG);
else if (Algo == "ISS")
TradeIS(SHORT);
}
}
Unfortunately the strategy is not really tradeable for the average trader. The average trade profit is just 1.0pip which is way too low. I backtested it also with variable spread and then the strategy fails. But I think the strategy can work if one does not have to pay commissions.
Last edited by trenki2; 08/27/16 17:46.
|
|
|
Re: Intraday seasonality in FX market
[Re: trenki2]
#461893
08/27/16 18:21
08/27/16 18:21
|
Joined: May 2015
Posts: 390 Czech Republic
Grat
Senior Member
|
Senior Member
Joined: May 2015
Posts: 390
Czech Republic
|
So, this is looks like the my idea. I'm publish two week before. Is better if optimize for the different days in week. In the monday is not optimal the same open hour like in the friday. But I'm not know, howto optimize for the each day. I get the error 40. But i don't understant this:
int index = (int)(optimize(0, 0, 254, 1) / 254 * 299);
Last edited by Grat; 08/27/16 18:24.
|
|
|
Re: Intraday seasonality in FX market
[Re: Grat]
#461894
08/27/16 18:56
08/27/16 18:56
|
Joined: Aug 2016
Posts: 95 Wien
trenki2
Junior Member
|
Junior Member
Joined: Aug 2016
Posts: 95
Wien
|
So, this is looks like the my idea. I'm publish two week before. Is better if optimize for the different days in week. In the monday is not optimal the same open hour like in the friday. But I'm not know, howto optimize for the each day. I get the error 40. But i don't understant this:
int index = (int)(optimize(0, 0, 254, 1) / 254 * 299);
The optimize function computes an index into a lookup table. The lookup table stores the startHour and endHour combinations. There are 300 combinations per day. The optimize function picks an index into this lookup table. The expression is a bit complicated since it has to work around a limitation in the optimize function. It can only handle 255 steps, that is why it looks for a value between 0 and 254 and than scales that to [0, 299]. So not all entries in the lookup table can be picked but it is good enough. If one would want to pick a different startHour/endHour depending on the weekday one possible solution for that would be to create one separate algorithm for each day f.i. by adding another parameter to the TradeIS() function and then adding more algos in the algo loop.
|
|
|
Re: Intraday seasonality in FX market
[Re: trenki2]
#461895
08/27/16 20:44
08/27/16 20:44
|
Joined: May 2015
Posts: 390 Czech Republic
Grat
Senior Member
|
Senior Member
Joined: May 2015
Posts: 390
Czech Republic
|
So, after i make different open/close hour per day. Walk-Forward Test xcor4_TZD portfolio
Simulated account AssetsFix Bar period 1 hour (avg 121 min) Simulation period 01.05.2016-26.08.2016 (1439 bars) Test period 10.08.2016-26.08.2016 (288 bars) Lookback period 80 bars (3 days) WFO test cycles 1 x 288 bars (17 days) Training cycles 1151..0 bars (0 minutes, anchored) Monte Carlo cycles 200 Assumed slippage 10.0 sec Capital invested 10000$
Gross win/loss 4215$ / -777$ (+512p) Average profit 77268$/year, 6439$/month, 297$/day Max drawdown -250$ 7% (MAE -3558$ 104%) Total down time 6% (TAE 25%) Max down time 31 hours from Aug 2016 Max open margin 14243$ Max open risk 5808$ Trade volume 1697268$ (38149356$/year) Transaction costs -103$ spr, 1.59$ slp, -14$ rol, -134$ com Capital required 14994$
Number of trades 27 (607/year, 12/week, 3/day) Percent winning 63.0% Max win/loss 826$ / -160$ Avg trade profit 127$ 19.0p (+37.0p / -11.6p) Avg trade slippage 0.06$ 0.0p (+0.2p / -0.4p) Avg trade bars 21 (+30 / -8) Max trade bars 86 (3 days) Time in market 206% Max open trades 19 Max loss streak 3 (uncorrelated 4)
Annual growth rate 76516% Profit factor 5.42 (PRR 3.12) Sharpe ratio 3.22 Kelly criterion 1.33 R2 coefficient 0.678 Ulcer index 44.3% Prediction error 116%
Confidence level AR DDMax Capital
10% 539% 35$ 14347$ 20% 538% 41$ 14366$ 30% 537% 51$ 14397$ 40% 536% 61$ 14427$ 50% 535% 71$ 14455$ 60% 532% 90$ 14512$ 70% 528% 129$ 14631$ 80% 525% 160$ 14722$ 90% 521% 193$ 14822$ 95% 520% 208$ 14868$ 100% 514% 268$ 15047$
Portfolio analysis OptF ProF Win/Loss Wgt% Cycles
AUD/USD avg .283 0.96 1/2 -0.2 X EUR/USD avg .406 5.47 2/2 6.9 X GBP/USD avg .414 0.40 2/2 -3.5 X NZD/USD avg .258 6.34 1/1 10.0 X USD/CAD avg .542 3.74 3/3 24.9 X USD/CHF avg .399 ++++ 3/0 4.8 / USD/JPY avg .484 ++++ 5/0 56.9 /
1IS avg .469 0.84 3/4 -1.2 X 2IS avg .499 2.94 2/1 3.5 X 3IS avg .398 15.83 3/1 36.7 X 4IS avg .485 3.97 6/3 30.9 X 5IS avg .180 40.30 3/1 30.0 X
AUD/USD:2IS .999 0.00 0/1 -1.8 \ AUD/USD:2IS:L .999 0.00 0/1 -1.8 \ AUD/USD:2IS:S .999 ---- 0/0 0.0 . AUD/USD:3IS .000 0.00 0/1 -2.5 \ AUD/USD:3IS:L .999 0.00 0/1 -2.5 \ AUD/USD:3IS:S .000 ---- 0/0 0.0 . AUD/USD:4IS .000 ++++ 1/0 4.1 / AUD/USD:4IS:L .000 ---- 0/0 0.0 . AUD/USD:4IS:S .402 ++++ 1/0 4.1 / EUR/USD:1IS .142 0.00 0/1 -0.8 \ EUR/USD:1IS:L .999 0.00 0/1 -0.8 \ EUR/USD:1IS:S .000 ---- 0/0 0.0 . EUR/USD:4IS .786 ++++ 1/0 2.9 / EUR/USD:4IS:L .999 ++++ 1/0 2.9 / EUR/USD:4IS:S .000 ---- 0/0 0.0 . EUR/USD:5IS .547 7.29 1/1 4.8 X EUR/USD:5IS:L .547 ++++ 1/0 5.6 / EUR/USD:5IS:S .524 0.00 0/1 -0.8 \ GBP/USD:1IS .999 ++++ 1/0 1.0 / GBP/USD:1IS:L .999 ++++ 1/0 1.0 / GBP/USD:1IS:S .000 ---- 0/0 0.0 . GBP/USD:2IS .868 ++++ 1/0 1.3 / GBP/USD:2IS:L .999 ++++ 1/0 1.3 / GBP/USD:2IS:S .000 ---- 0/0 0.0 . GBP/USD:4IS .344 0.00 0/2 -5.8 \ GBP/USD:4IS:L .152 0.00 0/1 -1.6 \ GBP/USD:4IS:S .999 0.00 0/1 -4.2 \ NZD/USD:1IS .000 0.00 0/1 -1.9 \ NZD/USD:1IS:L .999 0.00 0/1 -1.9 \ NZD/USD:1IS:S .000 ---- 0/0 0.0 . NZD/USD:3IS .122 ++++ 1/0 11.9 / NZD/USD:3IS:L .582 ++++ 1/0 11.9 / NZD/USD:3IS:S .000 ---- 0/0 0.0 . USD/CAD:1IS .999 0.00 0/2 -4.5 \ USD/CAD:1IS:L .580 0.00 0/1 -2.9 \ USD/CAD:1IS:S .999 0.00 0/1 -1.6 \ USD/CAD:3IS .999 ++++ 1/0 24.0 / USD/CAD:3IS:L .000 ---- 0/0 0.0 . USD/CAD:3IS:S .999 ++++ 1/0 24.0 / USD/CAD:4IS .920 1.34 1/1 1.6 X USD/CAD:4IS:L .402 0.00 0/1 -4.7 \ USD/CAD:4IS:S .999 ++++ 1/0 6.2 / USD/CAD:5IS .227 ++++ 1/0 3.8 / USD/CAD:5IS:L .000 ---- 0/0 0.0 . USD/CAD:5IS:S .452 ++++ 1/0 3.8 / USD/CHF:1IS .878 ++++ 1/0 1.2 / USD/CHF:1IS:L .000 ---- 0/0 0.0 . USD/CHF:1IS:S .999 ++++ 1/0 1.2 / USD/CHF:3IS .999 ++++ 1/0 3.2 / USD/CHF:3IS:L .999 ---- 0/0 0.0 . USD/CHF:3IS:S .999 ++++ 1/0 3.2 / USD/CHF:4IS .999 ++++ 1/0 0.4 / USD/CHF:4IS:L .000 ---- 0/0 0.0 . USD/CHF:4IS:S .999 ++++ 1/0 0.4 / USD/JPY:1IS .039 ++++ 1/0 3.8 / USD/JPY:1IS:L .000 ---- 0/0 0.0 . USD/JPY:1IS:S .999 ++++ 1/0 3.8 / USD/JPY:2IS .201 ++++ 1/0 4.1 / USD/JPY:2IS:L .000 ---- 0/0 0.0 . USD/JPY:2IS:S .999 ++++ 1/0 4.1 / USD/JPY:4IS .952 ++++ 2/0 27.6 / USD/JPY:4IS:L .999 ++++ 1/0 12.2 / USD/JPY:4IS:S .847 ++++ 1/0 15.4 / USD/JPY:5IS .999 ++++ 1/0 21.4 / USD/JPY:5IS:L .000 ---- 0/0 0.0 . USD/JPY:5IS:S .999 ++++ 1/0 21.4 /
|
|
|
|