Stoken ACA strategy

Posted By: alun

Stoken ACA strategy - 09/04/22 21:12

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.
Posted By: Grant

Re: Stoken ACA strategy - 09/04/22 22:32

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.
Posted By: alun

Re: Stoken ACA strategy - 09/05/22 08:41

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.
Posted By: Grant

Re: Stoken ACA strategy - 09/05/22 09:25

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.
Posted By: alun

Re: Stoken ACA strategy - 09/05/22 09:46

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
Posted By: Grant

Re: Stoken ACA strategy - 09/05/22 10:35

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.
Posted By: AndrewAMD

Re: Stoken ACA strategy - 09/05/22 12:26

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.
Posted By: alun

Re: Stoken ACA strategy - 09/05/22 13:44

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.
Posted By: Grant

Re: Stoken ACA strategy - 09/05/22 15:04

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?
Posted By: alun

Re: Stoken ACA strategy - 09/05/22 17:00

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.
Posted By: Grant

Re: Stoken ACA strategy - 09/05/22 19:06

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?
Posted By: alun

Re: Stoken ACA strategy - 09/06/22 08:57

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.
Posted By: Grant

Re: Stoken ACA strategy - 09/06/22 18:18

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?
Posted By: alun

Re: Stoken ACA strategy - 09/08/22 11:04

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
Posted By: Grant

Re: Stoken ACA strategy - 09/08/22 12:42

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/
Posted By: alun

Re: Stoken ACA strategy - 09/08/22 16:43

I wonder why the regular `Commission` in the asset list wouldn't for that?

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

Re: Stoken ACA strategy - 09/08/22 17:00

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).
Posted By: alun

Re: Stoken ACA strategy - 09/08/22 22:49

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...
© 2024 lite-C Forums