Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 642 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Stoken ACA strategy #486548
09/04/22 21:12
09/04/22 21:12
Joined: Aug 2022
Posts: 65
alun Offline OP
Junior Member
alun  Offline OP
Junior Member

Joined: Aug 2022
Posts: 65
Implementing my first strategy in Zorro - from Dick Stoken's book "Survival of the fittest for investors"

I will be glad to hear feedback on any suggestions for improvements.

Main repo - https://github.com/alun/stoken-aca

Older version - https://gist.github.com/alun/4424cb0e61a4955355ea82bb72286af3

I had strategy in Python before - https://katlex.com/stoken/

Currently results are quite different (even with Reinvest = true) - I keep working to make both implementations as close as possible.

Last edited by alun; 09/08/22 22:57.
Re: Stoken ACA strategy [Re: alun] #486551
09/04/22 22:32
09/04/22 22:32
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
Nice clean code.
Your asset mix looks like Ray Dalio's all weather portfolio.
All your trade stats look great, except for the sharpe ratio. I wonder why that is.

Last edited by Grant; 09/04/22 22:35.
Re: Stoken ACA strategy [Re: alun] #486553
09/05/22 08:41
09/05/22 08:41
Joined: Aug 2022
Posts: 65
alun Offline OP
Junior Member
alun  Offline OP
Junior Member

Joined: Aug 2022
Posts: 65
Thanks for the feedback, Grant!

yes it's so different to why I found in Python (Sharpe ratio 1.07)

I thought that maybe due to my Zorro test does not reinvest-profits, but with reinvesting it's even less in Zorro - 0.54%

I think there might be differences in how Zorro calculates it.

Re: Stoken ACA strategy [Re: alun] #486555
09/05/22 09:25
09/05/22 09:25
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
I see that you use 'Capital' or '(Capital + Profit)' for your position sizing. This means that your position size is always based on your initial capital + your profit, but not a loss(!).
Do you have a particular reason for this?

I always use 'Balance' for position sizing, which is 'Capital + Wintotal - LossTotal' (see https://zorro-project.com/manual/en/balance.htm)

Always log variables for verification when in doubt about certain calculations, esp before switching to live trading. I believe that's the best way to keep bugs away.

Re: Stoken ACA strategy [Re: alun] #486556
09/05/22 09:46
09/05/22 09:46
Joined: Aug 2022
Posts: 65
alun Offline OP
Junior Member
alun  Offline OP
Junior Member

Joined: Aug 2022
Posts: 65
I think it's similar:

ProfitTotal - Realized and unrealized total profit so far; WinTotal-LossTotal+WinValTotal-LossValTotal.

So it's PnL of all realised and unrealised trades.

https://zorro-project.com/manual/en/winloss.htm

Re: Stoken ACA strategy [Re: alun] #486558
09/05/22 10:35
09/05/22 10:35
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
I understand, but personally I would never calculate a position size based on an unrealised profit or loss, as this can work against you.

Worst case scenario: open position X very profitable > take a large position in Y > open position X ends with a big loss.

Re: Stoken ACA strategy [Re: Grant] #486559
09/05/22 12:26
09/05/22 12:26
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Originally Posted by Grant
I understand, but personally I would never calculate a position size based on an unrealised profit or loss, as this can work against you.

I do this all the time in my stock portfolio rotation system. Positions are regularly adjusted from very long to slightly long to flat, and so on.

Re: Stoken ACA strategy [Re: alun] #486562
09/05/22 13:44
09/05/22 13:44
Joined: Aug 2022
Posts: 65
alun Offline OP
Junior Member
alun  Offline OP
Junior Member

Joined: Aug 2022
Posts: 65
Yeah I believe stock/ETF rotation (especially with no leverage) are quite different from futures/CFD/forex strategies in the sense of how you look at the realised and unrealised profits.

Here I need to look at cost of my overall portfolio - what I don't have yet is when I rotate one component between risk-on/risk-off, I need to rebalance the two other components so they take 33% of the portfolio each.

I plan to add in next versions.

Re: Stoken ACA strategy [Re: alun] #486563
09/05/22 15:04
09/05/22 15:04
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
True, esp with a leveraged portfolio open positions can fluctuate a lot. On the flip side, your strategy is low-frequency, so over time they can fluctuate a lot. To mitigate this you need to rebalance your portfolio indeed, esp in volatile markets. It will a tradeoff between rebalancing your portfolio/risk and limiting your costs.
Maybe a spreadsheet with past trades, powered by a solver could help to find an optimal rebalance frequency?

Re: Stoken ACA strategy [Re: alun] #486564
09/05/22 17:00
09/05/22 17:00
Joined: Aug 2022
Posts: 65
alun Offline OP
Junior Member
alun  Offline OP
Junior Member

Joined: Aug 2022
Posts: 65
I think transactional costs are miserable here.

I have modelled the strategy in Python since 2004 started from $10k initial deposit with reinvesting dividends and rebalance on each event of one of the components rotation.

The overall fee was 394.42 for 17+ years. 19721 ETF stocks traded. My broker has 0.02$ per stock per side.

Re: Stoken ACA strategy [Re: alun] #486566
09/05/22 19:06
09/05/22 19:06
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
Originally Posted by alun
I think transactional costs are miserable here.


Which is why I don't believe in most active trading strategies for non-leveraged products. Passive / buy & hold strategies tend to perform better in that regard.
Maybe you can somehow adjust your portfolio and switch to futures or options?

Re: Stoken ACA strategy [Re: alun] #486570
09/06/22 08:57
09/06/22 08:57
Joined: Aug 2022
Posts: 65
alun Offline OP
Junior Member
alun  Offline OP
Junior Member

Joined: Aug 2022
Posts: 65
There are two problems with derivatives:

1. They have baked-in roll-overs (swaps) in their prices - which works agains a long term investor
2. I'm not sure if I can find all the same futures to cover short and long term bonds , real-estate etc

I believe they are more suitable for short- or midterm trading or hedging but not as replacement for buy and hold type of assets.

Last edited by alun; 09/07/22 15:35.
Re: Stoken ACA strategy [Re: alun] #486574
09/06/22 18:18
09/06/22 18:18
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
Futures/options make automatic trading more complicated and yeah, there aren't always good alternatives to ETFs.

Have you compared your strategy performance with a buy & hold scenario?

Re: Stoken ACA strategy [Re: Grant] #486588
09/08/22 11:04
09/08/22 11:04
Joined: Aug 2022
Posts: 65
alun Offline OP
Junior Member
alun  Offline OP
Junior Member

Joined: Aug 2022
Posts: 65
Originally Posted by Grant
Have you compared your strategy performance with a buy & hold scenario?


I have released the next version of my script https://gist.github.com/alun/4424cb0e61a4955355ea82bb72286af3 and calculated this comparison (without reinvesting).

Stoken's strategy definitely gives better risk-adjusted results than risk-on only buy and hold (with and without periodical rebalance).

https://gist.github.com/alun/80fcedf46e64932a8f4ceb050fcd9a86#file-comparison-csv

Last edited by alun; 09/08/22 11:05.
Re: Stoken ACA strategy [Re: alun] #486589
09/08/22 12:42
09/08/22 12:42
Joined: Aug 2017
Posts: 294
Netherlands
G
Grant Offline
Member
Grant  Offline
Member
G

Joined: Aug 2017
Posts: 294
Netherlands
Nice, that's def a significant improvement, esp the % drawdown.

For a even better comparison it would be interesting when you factor in the transaction costs. This is often part of the reason why buy & hold strategies perform better.
Andrew made a nice blog post on how to incorporate realistic transaction costs in a Zorro script, see https://www.vitaltrades.com/2020/07/14/adding-exact-fee-and-credit-calculations-to-zorro/

Re: Stoken ACA strategy [Re: alun] #486593
09/08/22 16:43
09/08/22 16:43
Joined: Aug 2022
Posts: 65
alun Offline OP
Junior Member
alun  Offline OP
Junior Member

Joined: Aug 2022
Posts: 65
I wonder why the regular `Commission` in the asset list wouldn't for that?

https://zorro-project.com/manual/en/account.htm

Re: Stoken ACA strategy [Re: alun] #486594
09/08/22 17:00
09/08/22 17:00
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
You can set Commission on a trade-by-trade basis, and not on an order-by-order basis. My (overly complex) workaround from my blog attempts to address this.

In other news, you can always use Interactive Brokers' SMART Prefer Rebate or SMART Maximize Rebate routing options. With these, you can place limit orders that add liquidity, and you might actually get paid for order fills (if there are exchanges that do this for the given instrument, I think some stock exchanges do).

Re: Stoken ACA strategy [Re: alun] #486599
09/08/22 22:49
09/08/22 22:49
Joined: Aug 2022
Posts: 65
alun Offline OP
Junior Member
alun  Offline OP
Junior Member

Joined: Aug 2022
Posts: 65
Thanks for the extra input Andrew,

I think I don't need that fine control over fees right now.

But I have reused your idea to explicitly account for dividends here https://github.com/alun/stoken-aca/blob/main/stoken_aca.c#L59

One thing learned - marketVal/marketVol do not work without Zorro S - bummer.

I've hacked the price bars in the way that `close = open` or `close = open + dividends`

I'm only using close prices for my algo anyway.

That seemed to work, but results are still very far from my Python implementation.

One bug I have found - I have modified DowloadEOD.c for building .t6.
I've added a loop to build history for multiple assets. But without `dataNew(1, 0, 6);` it saved same bars for each asset name - so previous results are a way off from being correct.

But not sure about the rest - working further to get to some Zorro/Python parity...

Page 1 of 2 1 2

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