Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (SBGuy), 712 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rating: 4
Page 1 of 4 1 2 3 4
Dual Momentum Algorithm - The way Zorro would have done it #468282
09/28/17 02:58
09/28/17 02:58
Joined: Sep 2017
Posts: 235
H
Hredot Offline OP
Member
Hredot  Offline OP
Member
H

Joined: Sep 2017
Posts: 235
Perhaps Zorro would not have done it better than anyone else.
But one thing is for sure:

Zorro would have given it to the people for free!

So, here we go:

Quote:
Disclaimer: Use at your own risk! You alone are responsible for your gains or losses.
Dual Momentum Algorithm V1.0

This script uses the same assets as the Z9 system.
Measuring performance during the years 2012-2017 starting with $5000 capital, we get:



The equity (green line) barely scratches the Balance (blue line) during drawdowns. So the script makes sure that no new trades can be opened if more than 2/3 of balance is tied up in current trades (red line). This makes it extremely unlikely for the green and red lines to ever meet, in turn making a margin call unlikely. Therefore, the script reinvests all profits instead of their square root to boost performance.

How does it compare with Z9 system performance?

Since this script reinvests profits over time, while Z9 does not seem to do so, it is kind of hard to compare their returns. Short term (one or two years period) Z9 does better, whereas long term this script is going to exponentially outgrow Z9.

Already at the above test period with the same starting capital we have:

Z9:
- Trades 151 times
- Makes 12144$ gross win
- Makes -1115$ gross loss

DualMomentumV1.0:
- Trades 84 times
- Makes 13717$ gross win
- Makes -904$ gross loss

We see that about five years is enough for the exponential growth of DualMomentumV1.0 to take over. It trades only half the time compared to Z9, which explains the smaller gross losses due to smaller transaction costs.

Of course gradually increasing the margin in Z9 by hand could exponentiate it as well. But having to estimate by how much to move the slider every couple weeks is less convenient than an automatic solution.

Since DualMomentumV1.0 reinvests automatically, you should not touch the Capital slider after you initially start and adjust the algorithm. The slider is only there to quickly backtest the algorithm with different starting points.

What do you guys think of this implementation?
Any improvement suggestions?

Cheers,
Hredot

PS:
In case if the admins find this a worthy contribution to the community, I'd be happy to find a Zorro S license in my inbox! grin

Last edited by Hredot; 09/28/17 13:32.
Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: Hredot] #468285
09/28/17 06:47
09/28/17 06:47
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
Well done! No Zorro S, but certainly fame and honour. When reinvesting, I hope you used the square root rule.

Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: jcl] #468292
09/28/17 10:10
09/28/17 10:10
Joined: Feb 2015
Posts: 652
Milano, Italy
M
MatPed Offline
User
MatPed  Offline
User
M

Joined: Feb 2015
Posts: 652
Milano, Italy
Nice Job, man!

Last edited by MatPed; 09/28/17 10:10.
Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: MatPed] #468294
09/28/17 10:55
09/28/17 10:55
Joined: Dec 2016
Posts: 71
F
firecrest Offline
Junior Member
firecrest  Offline
Junior Member
F

Joined: Dec 2016
Posts: 71
Kudo to Hredot.

Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: firecrest] #468299
09/28/17 12:41
09/28/17 12:41
Joined: Aug 2017
Posts: 102
Spain
B
Brax Offline
Member
Brax  Offline
Member
B

Joined: Aug 2017
Posts: 102
Spain
This thread literally came out of the blue!

I was about to implement Z9 on my own, so i will have a look into it.

Thank you very much.

Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: firecrest] #468300
09/28/17 13:06
09/28/17 13:06
Joined: Sep 2017
Posts: 235
H
Hredot Offline OP
Member
Hredot  Offline OP
Member
H

Joined: Sep 2017
Posts: 235
Thank you guys!

The system reinvests so that always about 2/3 of Balance are tied up in trades.
Why?
With this strategy, the maximum drawdown in the simulated period was about 6% in 2016. Drawdowns happen once every couple years, but for the sake of discussion let's assume a very pessimistic case of one drawdown per year. If we assume that equity grows linearly (black line), then drawdown is going to increase from the initial 6% with time to the power 1.5 (red line). It will take it about 500 years to hit the 2/3 reinvested margin (green line):



But if we stick to the square root reinvesting rule (blue line) as opposed to the 2/3 rule (green line), we hardly would expect the nice return in equity (black line).

Still, for those who do not feel adventurous there is a comment in the script describing which line to change and how in order to reinvest according to the square root rule instead of linear.

Last edited by Hredot; 09/28/17 13:09.
Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: Hredot] #468301
09/28/17 13:48
09/28/17 13:48
Joined: Jul 2017
Posts: 25
Bangkok
JoFo Offline
Newbie
JoFo  Offline
Newbie

Joined: Jul 2017
Posts: 25
Bangkok
very good job. 1+

Hope you try to code a better Z12 and Z7 too. They pretty useless so far.

Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: JoFo] #468302
09/28/17 13:58
09/28/17 13:58
Joined: Sep 2017
Posts: 235
H
Hredot Offline OP
Member
Hredot  Offline OP
Member
H

Joined: Sep 2017
Posts: 235
@JoFo

I would not say that my script above is better than Z9!
If you increase your margin slider in Z9 by hand over time, you can get the same exponential growth with better trades per time unit.

I'd love to take a closer look at how to implement homebrew versions of the other Z systems. But unfortunately their description is vague, so I'm not too sure what to code.

Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: Hredot] #468465
10/05/17 18:28
10/05/17 18:28
Joined: Jun 2016
Posts: 30
france
S
stephane97490 Offline
Newbie
stephane97490  Offline
Newbie
S

Joined: Jun 2016
Posts: 30
france
is there a way to adapte it on daily trading ?

Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: stephane97490] #468466
10/05/17 18:42
10/05/17 18:42
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Perhaps, but this is an investment algorithm, not a speculative trading algorithm. It might be better to have less trades.

Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: AndrewAMD] #468468
10/05/17 20:01
10/05/17 20:01
Joined: Sep 2017
Posts: 235
H
Hredot Offline OP
Member
Hredot  Offline OP
Member
H

Joined: Sep 2017
Posts: 235
@stephane97490
Short answer: Nope

Long answer:
This strategy opens long only trades, to profit from the constant upwards drift of the market, which is just the fact that market is based on the work of hardworking businesses who constantly tend to produce more value than there was before. Essentially, if you pick all of the assets and long trade all of them in equal amount forever, you will make slightly less money over time than the above script. At daily time frames this upwards drift dilutes to zero, and you are left with fluctuations around the mean. While it is safe to bet on the overall market growth over months and years, daily fluctuations are not as easy to predict. So this would not work at hourly or daily time frames.

Last edited by Hredot; 10/05/17 20:02.
Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: Hredot] #468545
10/09/17 15:53
10/09/17 15:53
Joined: Jun 2016
Posts: 30
france
S
stephane97490 Offline
Newbie
stephane97490  Offline
Newbie
S

Joined: Jun 2016
Posts: 30
france
Thanks, I understand that the main idea is to predict the trend... When you estimate that compenent. You have to use the best filters.

Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: AndrewAMD] #468593
10/11/17 12:14
10/11/17 12:14
Joined: Mar 2017
Posts: 48
Bologna
K
kmerlo Offline
Newbie
kmerlo  Offline
Newbie
K

Joined: Mar 2017
Posts: 48
Bologna
I founded a strange behavior about costs

if I write inside the "function run()" these rows

RollLong= 0;
RollShort=0;
Commission=0;
Spread=0;
Slippage=0;
Fill= ATCLOSE;


In the performant report I found some costs!

Simulation mode Realistic (slippage 0.0 sec)
Capital invested 5000$

Gross win/loss 12728$ / -1195$ (+60334p)
Average profit 1967$/year, 164$/month, 7.56$/day
Max drawdown -622$ 5.4% (MAE -2570$ 22.3%)
Total down time 14% (TAE 85%)
Max down time 77 weeks from Dec 2015
Max open margin 8817$
Max open risk 206$
Trade volume 88079$ (15019$/year)
Transaction costs -151$ spr, 0 slp, 0 rol, -30$ com



instead if I write the same rows in the script "Workshop4_2.c" the result is as I want:

Simulation mode Realistic (slippage 0.0 sec)
Spread 0.0 pips (roll 0.00/0.00)
Contracts per lot 1.0

Gross win/loss 9.45$ / -0.31299591b (+914p)
Average profit 1.39$/year, 0.11589078b/month, 0.00534881b/day
Max drawdown -0.38999176b 4.3% (MAE -1.04$ 11.3%)
Total down time 1% (TAE 73%)
Max down time 14 weeks from Mar 2011
Max open margin 24$
Max open risk 0.82628334b
Trade volume 384$ (58$/year)
Transaction costs 0 spr, 0 slp, 0 rol

Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: kmerlo] #468628
10/11/17 20:04
10/11/17 20:04
Joined: Sep 2017
Posts: 235
H
Hredot Offline OP
Member
Hredot  Offline OP
Member
H

Joined: Sep 2017
Posts: 235
My guess is, the Z9 as well as DualMomentumV1.0 scripts both load asset definitions from AssetsZ9.csv. These probably overwrite your settings. Try to set these parameters to zero for all assets in AssetsZ9.csv as well, then I guess it should work as you want.

Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: Hredot] #468630
10/11/17 20:37
10/11/17 20:37
Joined: Mar 2017
Posts: 48
Bologna
K
kmerlo Offline
Newbie
kmerlo  Offline
Newbie
K

Joined: Mar 2017
Posts: 48
Bologna
Yes the reason was that!
indeed I have changed the file "AssetsZ9.csv" putting the value "0" in column "Spread" and "Commission" and now the result it is OK ! laugh

Transaction costs 0 spr, 0 slp, 0 rol

Thanks A lot!!

Good Night

Last edited by kmerlo; 10/11/17 20:38.
Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: Hredot] #468946
10/28/17 21:08
10/28/17 21:08
Joined: Jan 2017
Posts: 9
M
Mook_Yon Offline
Newbie
Mook_Yon  Offline
Newbie
M

Joined: Jan 2017
Posts: 9
@Hredot

Re your DualMomentumV1.0 script, I have a couple of Qs.
There are two classes (A) Technical, (B) Comparative.

A. TECHNICAL
(1) Kudos for making it public. Fascinating write-up. THX!
(2) How far back was this tested (vs. Z9) (did you succeed in starting earlier than 2008)?
(3) Have you optimized ‘myDaysUpdate’, BarPeriod, etc.?
(4) How did you select the Stop ATR TimePeriod, and the (x3) coefficient?
(5) What is the percentage of losing trades closed by the Stop Loss feature prior to reaching the rebalance event (@myDaysUpdate)?
(6) Did you try making the Stop trailing?

B. COMPARATIVE
We back tested a strategy similar to Antonacci's GEM, wo leverage and wo Stop Loss.

Every month (Jan 2008 thru Sep 2017) we sorted the recent 12 months returns of BIL, CWI, and SPY and invested long in the highest returning instrument (if BIL showed the best return, we invested in AGG). Our back tested CAGR was 5.7%, while Antonacci reported (here: https://www.optimalmomentum.com/gem_trackrecord.html) on 7.85% for the same period. IMHO, there is a significant gap than demands clarification.

I am interested to know if you were successful in replicating the results reported by Antoncci?

Rgds,

Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: Mook_Yon] #468951
10/29/17 00:10
10/29/17 00:10
Joined: Sep 2017
Posts: 235
H
Hredot Offline OP
Member
Hredot  Offline OP
Member
H

Joined: Sep 2017
Posts: 235
Hi Mook_Yon!

A1) Thanks! laugh
A2) No, unfortunately I only went back to the end of 2008, since I did not experiment with other assets. It might be interesting to check the code before 2008!
A3) BarPeriod is set to 1 day since that is the most easily available data format. Since the time frame of momentum is one year, this should be fine graded enough. I did play around with the myDaysUpdate setting and 15 seemed to produce better results than 20 or 10. However, I did no rigorous statistical analysis to support this.
A4) The ATR TimePeriod and x3 coefficient are selected such that the stop loss does not interfere with any of the trades performed in the backtest. The logic is: the algorithm is supposed to work without stop loss, but we cannot be sure that the market will not completely collapse within a period of 15 days some time in the future. So we put a stop loss in place at a very far distance just in case. Ideally it will never be triggered.
A5) 0% closed by stop loss.
A6) Nope, since it is only a precaution, not an applied feature.

B) I'm not sure about the assets you describe. However, we can perform a backtest of DualMomentumV1.0 between 2009 up to today without leveraging. To do that, we just have to open AssetsZ9.csv file in History folder in the main Zorro installation directory and change all leverage fields from 2 to 1. And set e.g. StartDate=2000; in the script (it will only start in 2009 though, since the history of assets used starts at end of 2007).
The result is 8.83% CAGR which can be reconciled with the 7.85% by Antonacci (his value is a bit lower, since his trades have to endure more of the bearish period during the last big crisis).


Last edited by Hredot; 10/29/17 00:15.
Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: Hredot] #468954
10/29/17 14:00
10/29/17 14:00
Joined: Jan 2017
Posts: 9
M
Mook_Yon Offline
Newbie
Mook_Yon  Offline
Newbie
M

Joined: Jan 2017
Posts: 9
Thank you Hredot!

Coming from Value Investment background, after reading Antonacci’s Dual Momentum book, I desperately needed a “sanity check” method. I wished to use Zorro in order to reproduce, and validate Antonacci’s published back test performance.

Unfortunately, using your code, I could not yet validate or re-create Antonacci’s claim to fame (CAGR).

In his Dual Momentum Investing (chapter 8, under the subtitle “HOW TO USE IT”), Antonacci provides a detailed framework of the strategy: look back 12 months, rebalance monthly, at any rebalance invest the entire account balance in a single long position, use IVV or VOO for US stock, and VEU or VXUS for non-US, and finally BIL for checking T-bills (AGG, BND, or SCHZ should be purchased when BIL was the best performer).

Looking at you code, there are plenty of detours from Antonacci’s Dual Momentum framework: usually positions are gradually entered long, leverage is employed, multiple (best past performers) positions are held simultaneously, etc.

Back testing your (greatly done) replica of Z9 (with the initial Z9 asset list) though, produced very nice returns and forum members may consider using it live. Thanks for that!

Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: Mook_Yon] #468982
10/31/17 22:55
10/31/17 22:55
Joined: Mar 2015
Posts: 336
Rogaland
N
nanotir Offline
Senior Member
nanotir  Offline
Senior Member
N

Joined: Mar 2015
Posts: 336
Rogaland

Thanks for sharing!

I have tried to use it, but the trades are not entered. Does "enterLong();" work with IB or another instruction is needed? Or I may added the wrong ETF to IB. I am using the asset list of the z9 system.

This is what I get.

Quote:

Download CSJ.US.. 2720 bars read
[638: Tue 17-10-31 04:00] (105.2700)
enter trade
!Order Message:
BUY 1 XBI ARCA
Warning: your order will not be placed at the exchange until 2017-10-31 09:30:00 US/Eastern XBI-STK--0--SMART--USD
(XBI::L) Can't open 1@83.80 at 04:00:01
enter trade
[SMH::L] Skipped: Lots 0
enter trade
!Order Message:
BUY 2 ITB BATS
Warning: your order will not be placed at the exchange until 2017-10-31 09:30:00 US/Eastern ITB-STK--0--SMART--USD
(ITB::L) Can't open 2@39.36 at 04:00:01
enter trade
!Order Message:
BUY 1 XLV ARCA
Warning: your order will not be placed at the exchange until 2017-10-31 09:30:00 US/Eastern XLV-STK--0--SMART--USD
(XLV::L) Can't open 1@82.14 at 04:00:01

Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: nanotir] #468984
11/01/17 02:35
11/01/17 02:35
Joined: Dec 2016
Posts: 71
F
firecrest Offline
Junior Member
firecrest  Offline
Junior Member
F

Joined: Dec 2016
Posts: 71
I have the same problem previously too but it solved with the latest Zorro version 1.66.5. Not sure if your problem is the same.

Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: firecrest] #468985
11/01/17 04:15
11/01/17 04:15
Joined: Sep 2017
Posts: 235
H
Hredot Offline OP
Member
Hredot  Offline OP
Member
H

Joined: Sep 2017
Posts: 235
Since I did not try live trading this script, I'm afraid I cannot help you there.
Perhaps updating Zorro as firecast suggests might help.

Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: firecrest] #468993
11/01/17 16:19
11/01/17 16:19
Joined: Mar 2015
Posts: 336
Rogaland
N
nanotir Offline
Senior Member
nanotir  Offline
Senior Member
N

Joined: Mar 2015
Posts: 336
Rogaland
Originally Posted By: firecrest
I have the same problem previously too but it solved with the latest Zorro version 1.66.5. Not sure if your problem is the same.


I am using 1.60 but I will try with that one

Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: nanotir] #469019
11/02/17 13:59
11/02/17 13:59
Joined: Sep 2017
Posts: 235
H
Hredot Offline OP
Member
Hredot  Offline OP
Member
H

Joined: Sep 2017
Posts: 235
For some reason I cannot edit the first post any more, to make updates. Here it was pointed out that the INITRUN clause is not needed when loading Assets.csv file (probably to allow the script to load an updated list at any point in time during execution).
The use of INITRUN condition likely came from here. So to stop confusing people I dropped the INITRUN check from the script:

Quote:
Disclaimer: Use at your own risk! You alone are responsible for your gains or losses.
Dual Momentum Algorithm V1.1

Last edited by Hredot; 11/02/17 13:59.
Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: firecrest] #469032
11/03/17 10:47
11/03/17 10:47
Joined: Mar 2015
Posts: 336
Rogaland
N
nanotir Offline
Senior Member
nanotir  Offline
Senior Member
N

Joined: Mar 2015
Posts: 336
Rogaland
Originally Posted By: firecrest
I have the same problem previously too but it solved with the latest Zorro version 1.66.5. Not sure if your problem is the same.


I used 1.66.5 and got the same problem. Did I choose the wrong assets?
The zorro window shows XXXX as price and the box is red in the zorro window but the Ib gateway is window shows green connection

Quote:




Trade: Dual_Momentum (NFA) 2017-11-02
Assets HistoryAssetsZ9.csv
Lookback period (580 bars) .

Download CSJ.US.. 2723 bars read
[638: Fri 17-11-03 04:00] (105.0500)
!Order Message:
BUY 1 XBI ARCA
Warning: your order will not be placed at the exchange until 2017-11-03 09:30:00 US/Eastern XBI-STK--0--SMART--USD
(XBI::L) Can't open 1@82.47 at 04:00:01
[SMH::L] Skipped: Lots 0
!Order Message:
BUY 2 ITB BATS
Warning: your order will not be placed at the exchange until 2017-11-03 09:30:00 US/Eastern ITB-STK--0--SMART--USD
(ITB::L) Can't open 2@39.98 at 04:00:01
!Order Message:
BUY 1 XLV ARCA
Warning: your order will not be placed at the exchange until 2017-11-03 09:30:00 US/Eastern XLV-STK--0--SMART--USD
(XLV::L) Can't open 1@81.31 at 04:00:01


Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: nanotir] #469110
11/05/17 16:41
11/05/17 16:41
Joined: Sep 2017
Posts: 235
H
Hredot Offline OP
Member
Hredot  Offline OP
Member
H

Joined: Sep 2017
Posts: 235
@Nanitek
Actually, it seems that your problem is not with the script but with operating hours of the broker. It says, the code tries to open trades at 4am in the morning. The exchange however only opens at 9:30am. That is what the error message seems to be informing you of: that your trades will only go through once the exchange opens at 9:30am.

I believe there is a flag in Zorro which you might want to search for, that restricts trading only to the hours when the exchange is open. Or perhaps you can shift the local clock on your trading computer by 5-6 hours, so that the script tries to trade after 9:30am. Hope this helps!

Last edited by Hredot; 11/05/17 16:44.
Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: Hredot] #469339
11/11/17 16:48
11/11/17 16:48
Joined: Nov 2017
Posts: 34
C
Cheulmen Offline
Newbie
Cheulmen  Offline
Newbie
C

Joined: Nov 2017
Posts: 34
@Hredot, I'm getting the following error message:

Error 014: ATR needs LookBack 520 > 480

The script runs and it gets a 26% CAGR, but this error makes it a bit scary to put it live laugh

It appears a couple of times, the script I'm running is the v1.1 without any change (but it happened also in v1.0).

(Also it gave a warning about VOO not having the first 175 bars, but that warning disappears using a StartDate=2011)

Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: Cheulmen] #469341
11/11/17 17:21
11/11/17 17:21
Joined: Sep 2017
Posts: 235
H
Hredot Offline OP
Member
Hredot  Offline OP
Member
H

Joined: Sep 2017
Posts: 235
@Cheulmen

I would not recommend using any script, where you do not fully understand what it does and its limitations. Testing after 2011 is very misleading, since its a period of great growth. In fact, in my personal opinion the script performs sub-optimal in the years 2008-2011. I suspect Z9 probably has similar trouble there (which is why its testing period "conveniently" starts in 2011). Long story short:

The Dual Momentum script I posted is not really intended to be traded live, but serves as a proof of concept first iteration, for others to use as a starting point and refine until you are satisfied with the performance. That would also involve figuring out all warning messages, understanding why they appear and fixing them if you think it is necessary.

Last edited by Hredot; 11/11/17 17:25.
Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: Hredot] #469388
11/14/17 13:18
11/14/17 13:18
Joined: Nov 2017
Posts: 34
C
Cheulmen Offline
Newbie
Cheulmen  Offline
Newbie
C

Joined: Nov 2017
Posts: 34
Yep, that's why I was asking, I'm trying to understand... I'm not sure to grasp why the error appears, as 520 is less than two years, and the time involved is over that timeframe

Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: Cheulmen] #469397
11/14/17 17:40
11/14/17 17:40
Joined: Sep 2017
Posts: 235
H
Hredot Offline OP
Member
Hredot  Offline OP
Member
H

Joined: Sep 2017
Posts: 235
Actually, in trading terms, a year is only 12*20 days, since only about 20 days a month are working days.
So two years are 24*20 = 480, which means, you could either increase the LookBack period accordingly, or alter the ATR command later in the script.

Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: Hredot] #469578
11/23/17 02:11
11/23/17 02:11
Joined: Oct 2017
Posts: 52
Brazil
J
jmlocatelli Offline
Junior Member
jmlocatelli  Offline
Junior Member
J

Joined: Oct 2017
Posts: 52
Brazil
Very nice piece of code.
Thanks for sharing.

Looking into the script, what is this code for?

var totalSlope=0;
for(i=0;i<enterNum;i++){ // determine the overall weight of wanted assets
totalSlope=totalSlope+assetWeight[assetSorted[i]];
}

Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: jmlocatelli] #469599
11/24/17 04:21
11/24/17 04:21
Joined: Sep 2017
Posts: 235
H
Hredot Offline OP
Member
Hredot  Offline OP
Member
H

Joined: Sep 2017
Posts: 235
Great question jmlocatelli!
As is, the code assigns an equal share of funds to each asset bought.
You have the option to use assetWeight[assetSorted[i]]/totalSlope instead of just dividing by enterNum to calculate the Lot amount.
That would assign funds to each asset bought proportional to its momentum value in comparison with other bought assets.

Last edited by Hredot; 11/24/17 04:21.
Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: Hredot] #477702
07/22/19 21:23
07/22/19 21:23
Joined: Mar 2019
Posts: 357
D
danatrader Offline
Senior Member
danatrader  Offline
Senior Member
D

Joined: Mar 2019
Posts: 357
// Note: The following is optimized for 2x leveraging!
Lots=(Capital+WinTotal-LossTotal)*Leverage/(4*enterNum*price()*LotAmount);

How would you optimize it for 5 times leverage?

Re: Dual Momentum Algorithm - The way Zorro would have done it [Re: Hredot] #481500
09/22/20 03:21
09/22/20 03:21
Joined: May 2020
Posts: 6
A
Alvin Offline
Newbie
Alvin  Offline
Newbie
A

Joined: May 2020
Posts: 6
I hope it's not too late to revive this topic.

First of all, congrats to OP for coding your own dual momentum strategy!

I'm also working my own flavor dual momentum recently. The biggest problem I have is understanding how to properly do a reality check on a trend following, reinvesting strategy such as dual momentum.

Is it necessary to detrend PRICES for the benchmark result of reality check? As this will remove the trend, it really messes up the results. Any advise and maybe explanation on when and why this would be necessary?

// Reality Check
NumTotalCycles = 1000;
if (TotalCycle > 1) Detrend = PRICES+SHUFFLE;
else Detrend = PRICES;
set(LEAN,PRELOAD);

Or is it enough to just do it this way?

// Reality Check
NumTotalCycles = 1000;
if (TotalCycle > 1) Detrend = SHUFFLE;
set(LEAN,PRELOAD);

Page 1 of 4 1 2 3 4

Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1