Fully automated futures trading

GAT,

My current system is currently in Excel and Visual Basic. One thing I don't like about it is how much work it takes to add a new instrument or model/strategy/system. In your system in Python, how much time/effort does it take to add a new instrument? How much time does it take to add a new system to your already existing suite of systems?

Thanks.

Instruments - let's say an hour? Including getting the data.

'Adding a new system' -> have you got a piece of string I can measure? Could be anything from 1 minute for a parameter change to several years.

GAT
 
Instruments - let's say an hour? Including getting the data.

'Adding a new system' -> have you got a piece of string I can measure? Could be anything from 1 minute for a parameter change to several years.

GAT
For new system, I definitely didn't mean a parameter change. I mean, in theory, if you had an idea and it worked right away and you wanted to implement it right away (a lot of ifs there), how long does it take to program, test, and implement? I'm trying to get an idea of the amount of programming time it takes rather than testing.
 
For new system, I definitely didn't mean a parameter change. I mean, in theory, if you had an idea and it worked right away and you wanted to implement it right away (a lot of ifs there), how long does it take to program, test, and implement? I'm trying to get an idea of the amount of programming time it takes rather than testing.

Well let's take the dynamic optimisation. I did a lot of faffing around with different ideas, but once I knew how to do it, it probably took me about 2 days in all to write production quality code that I was happy to implement (the research code I wrote to test the idea, maybe took me a couple of hours).

Implementation is just a question of a few keystrokes once the code is written.

As an interesting PS, from this you can conclude that I write code way too quickly. Pysystemtrade is over 60k lines of python:

Code:
rob@RobLaptop:~$ cloc pysystemtrade/
    2143 text files.
    1113 unique files.                                         
    1685 files ignored.

github.com/AlDanial/cloc v 1.82  T=2.86 s (215.1 files/s, 54328.4 lines/s)
--------------------------------------------------------------------------------
Language                      files          blank        comment           code
--------------------------------------------------------------------------------
Python                          527          25398          12235          62671
YAML                             30             41            584          36248
Markdown                         11           3843              0           8774
Bourne Again Shell               33             64            142            529
JavaScript                        1             18              5            528
INI                               3            104              0            441
HTML                              1             14              0            267
XML                               5              0              0            225
CSS                               1             12              0            125
Jupyter Notebook                  3              0           3237             46
JSON                              1              0              0              8
--------------------------------------------------------------------------------
SUM:                            616          29494          16203         109862
--------------------------------------------------------------------------------

I would guess I've spent the equivalent of 2 full time years writing this code (ignoring research time) which equates to about 86 lines of code a day. That doesn't sound much, but it's a lot. And the reason I can code that fast is I don't write enough tests, my documentation isn't great, and because I don't have to worry about things like user specifications - I am the user.

GAT
 
Last edited:
Well let's take the dynamic optimisation. I did a lot of faffing around with different ideas, but once I knew how to do it, it probably took me about 2 days in all to write production quality code that I was happy to implement (the research code I wrote to test the idea, maybe took me a couple of hours).

Implementation is just a question of a few keystrokes once the code is written.

As an interesting PS, from this you can conclude that I write code way too quickly. Pysystemtrade is over 60k lines of python:

Code:
rob@RobLaptop:~$ cloc pysystemtrade/
    2143 text files.
    1113 unique files.                                        
    1685 files ignored.

github.com/AlDanial/cloc v 1.82  T=2.86 s (215.1 files/s, 54328.4 lines/s)
--------------------------------------------------------------------------------
Language                      files          blank        comment           code
--------------------------------------------------------------------------------
Python                          527          25398          12235          62671
YAML                             30             41            584          36248
Markdown                         11           3843              0           8774
Bourne Again Shell               33             64            142            529
JavaScript                        1             18              5            528
INI                               3            104              0            441
HTML                              1             14              0            267
XML                               5              0              0            225
CSS                               1             12              0            125
Jupyter Notebook                  3              0           3237             46
JSON                              1              0              0              8
--------------------------------------------------------------------------------
SUM:                            616          29494          16203         109862
--------------------------------------------------------------------------------

I would guess I've spent the equivalent of 2 full time years writing this code (ignoring research time) which equates to about 86 lines of code a day. That doesn't sound much, but it's a lot. And the reason I can code that fast is I don't write enough tests, my documentation isn't great, and because I don't have to worry about things like user specifications - I am the user.

GAT
No concerns that your system is overly complex? (I've been spending much of the last 2 week simplifying my system by removing old stuff that made sense at the time but are no longer needed.)
 
No concerns that your system is overly complex? (I've been spending much of the last 2 week simplifying my system by removing old stuff that made sense at the time but are no longer needed.)

Always! That's why I dropped the idea of doing fancy fitting.

I'd say the vol attenuation and mean reverting vol estimation don't add much complexity, and I think they're simple and intuitive by themselves.

Extra trading rules, well they're individually simpler and linearly combined, so as long as I understand them in isolation I'm happy to have dozens of these.

All of the above stuff is fine; it fits in with my philosophy that my system isn't that complicated, but is made up of lots and lots of simple things.

The main thing that doesn't fall into this category is the dynamic optimisation, which fundamentally changes the way the system works. But I think it's worth it, although I've had to build in a lot of diagnostics and fail safes to make sure it doesn't do something stupid.

GAT
 
Here you go: https://qoppac.blogspot.com/2021/12/my-trading-system.html

There are links to the .yaml and code in the post.

GAT

Nice. Do you know what Sharpe ratio it achieved in the 10 year period starting on 2010 Jan 1st? It has been a challenging period for trend following but it looks quite nice on your chart. Or could you post numerical data of the backtest perhaps? Daily performance numbers?

Backtest from the beginning of 2010 to this day:
Screenshot_20211202-191028_Samsung Internet.jpg
 
Nice. Do you know what Sharpe ratio it achieved in the 10 year period starting on 2010 Jan 1st? It has been a challenging period for trend following but it looks quite nice on your chart. Or could you post numerical data of the backtest perhaps? Daily performance numbers?

Backtest from the beginning of 2010 to this day:
View attachment 272266

Sharpe is .... well let's round it up: 1.0

Code:
perc.stats()
[[('min', '-9.323'), ('max', '5.493'), ('median', '0.1334'), ('mean', '0.07394'), ('std', '1.185'), ('skew', '-1.052'), ('ann_mean', '18.91'), ('ann_std', '18.97'), ('sharpe', '0.9967'), ('sortino', '1.17'), ('avg_drawdown', '-13.53'), ('time_in_drawdown', '0.9137'), ('calmar', '0.3882'), ('avg_return_to_drawdown', '1.397'), ('avg_loss', '-0.8708'), ('avg_gain', '0.7933'), ('gaintolossratio', '0.911'), ('profitfactor', '1.196'), ('hitrate', '0.5677'), ('t_stat', '3.469'), ('p_value', '0.0005295')], ]
 
Sharpe is .... well let's round it up: 1.0

Code:
perc.stats()
[[('min', '-9.323'), ('max', '5.493'), ('median', '0.1334'), ('mean', '0.07394'), ('std', '1.185'), ('skew', '-1.052'), ('ann_mean', '18.91'), ('ann_std', '18.97'), ('sharpe', '0.9967'), ('sortino', '1.17'), ('avg_drawdown', '-13.53'), ('time_in_drawdown', '0.9137'), ('calmar', '0.3882'), ('avg_return_to_drawdown', '1.397'), ('avg_loss', '-0.8708'), ('avg_gain', '0.7933'), ('gaintolossratio', '0.911'), ('profitfactor', '1.196'), ('hitrate', '0.5677'), ('t_stat', '3.469'), ('p_value', '0.0005295')], ]

Is it for the period [2010-2019] or does it include 2020 and 2021? I assume this is before costs?
 
Back
Top