Adventures in python and algorithmic trading

In addition to this excellent ongoing stuff that Sharky is giving to us, there is also some not-immediately-apparent benefit for traders who aren't participating in the "automation" route. The algos that Sharky has referenced can provide the basis for some very sound manual trading systems. You can put the algo into a scanner and come up with a decent list of potential trades, in order of quality preferably, before you ever get near to opening a chart. I've been doing it that way for a long time and for anyone just starting out, if you haven't tried it you will be surprised at how much work it saves. There is nothing quite as gonad-aching as going through the SP 500 constituent charts from start to finish just looking for something that seems "right" – and ending up completely chart-dazed with subsequent matching results.

A suitable scanner is one of my best trading tools!
 
@Sharky You may already have mentioned this but in case you haven't, what were the trades you have taken that has now given a £200 profit ?
 
Interesting journal, will definitely follow it. I've previously automated strategies using python+excel+tws api, but was uncomfortable runing algo's with significant money. Lost a bunch early on due to stupid errors (buying & selling the same stock lots of times because it was falling, so fulfilling buy criteria and then immediately hitting stop loss).

Currently looking into tensorflow, looking to really find new strategies instead of just automating what I could theoretically do manually.
 
@Sharky You may already have mentioned this but in case you haven't, what were the trades you have taken that has now given a £200 profit ?

Good question. I've been planning to create a summary of all trades, probably a google spreadsheet. I'll put this together this week, then share it here, so you can see exactly where that profit came from!

Interesting journal, will definitely follow it. I've previously automated strategies using python+excel+tws api, but was uncomfortable runing algo's with significant money. Lost a bunch early on due to stupid errors (buying & selling the same stock lots of times because it was falling, so fulfilling buy criteria and then immediately hitting stop loss).

Currently looking into tensorflow, looking to really find new strategies instead of just automating what I could theoretically do manually.

Yeah, I'm looking forward to playing around with Tensorflow when I get into more advanced topics. I know QuantConnect has support for Tensorflow and Keras for machine learning (see for example: https://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/PythonPackageTestAlgorithm.py).

The QuantConnect FAQ lists all the libraries currently white-listed for use: numpy, pandas, scipy, sklearn, blaze, cvxopt, cvxpy, pykalman, statsmodels, statistics, copulalib, keras, theano, stats, tensorflow, ta-lib and xgboost.

The Quantopian Help section lists the portions of Python modules that can be imported, as far as I can see, the only ML related library supported is Sklearn.
 
Just a quick update to anyone who might be disappointed about the lack of updates to my journal. The good news is I'm still actively trading options, mostly non-directional on US stocks and ETFs. My account is up about 5% after commissions, after a couple of months of trading (and I'm spending minimal time on it as everyone know's I'm time poor, so I'm using alert services mostly to initiate and close trades). The algorithmic side is on hold for now, I feel like I got off to a good start and found a direction to take things in, but realistically I was a bit ambitious to think I'd have time to pursue both the options trading and the algorithmic side at the same time. I'm going to continue to post on here as I have insights to share, right now I'm really don't the grunt work of placing trades, monitoring and understanding my trading personality; so I don't feel there's really much to say. Thanks for reading!
 
I expect we are all waiting in anticipation for your gold plated, stand alone profitable system.
Good work.
 
I did have a read through this thread again during the last week so I am still looking forward to how it develops.
 
Since you're coming to our quarterly meet-up (shameless plug) , lunch and a pint, happy to fill you in with the gaps the ;)
 
By way of an update, I downloaded Allen Downey's book called Think Python. Its been very helpful and is available free of charge.

Also, there are a couple of excellent online courses here:

https://quantra.quantinsti.com/courses

I have completed the free "Python for Trading: Basic" course and found it to be an excellent introduction, pitched exactly at the right level for me.

I'm about to start the "Python for Trading!" course which is not free. NB I have no affiliation to the book author/publisher or course provider.
 
I'm pretty excited about a new book that's just released by Andreas Clenow called 'Trading Evolved'. I'm a big fan of Clenow, and this book is super targeted to readers of this journal. I'm also a fan of Rob Carver and apparently he's written a guest chapter of the book.

Here are the links (not affiliated in any way or compensated for the plug):

https://www.amazon.co.uk/dp/109198378X/ (paperback - almost £40)
https://www.amazon.co.uk/dp/B07VDLX55H/ (ebook - just £8 pre-order, out Sat 10th Aug)

I pre-ordered a copy of the e-book and once I get the time to read it, hope to post a review.

Here's the jacket blurb:

Systematic trading allows you to test and evaluate your trading ideas before risking your money. By formulating trading ideas as concrete rules, you can evaluate past performance and draw conclusions about the viability of your trading plan.

Following systematic rules provides a consistent approach where you will have some degree of predictability of returns, and perhaps more importantly, it takes emotions and second guessing out of the equation.

From the onset, getting started with professional grade development and backtesting of systematic strategies can seem daunting. Many resort to simplified software which will limit your potential.

Trading Evolved will guide you all the way, from getting started with the industry standard Python language, to setting up a professional backtesting environment of your own. The book will explain multiple trading strategies in detail, with full source code, to get you well on the path to becoming a professional systematic trader.

This is a highly practical book, where every aspect is explained, all source code shown and no holds barred.
 
I'm pretty excited about a new book that's just released by Andreas Clenow called 'Trading Evolved'. I'm a big fan of Clenow, and this book is super targeted to readers of this journal. I'm also a fan of Rob Carver and apparently he's written a guest chapter of the book.

Here are the links (not affiliated in any way or compensated for the plug):

https://www.amazon.co.uk/dp/109198378X/ (paperback - almost £40)
https://www.amazon.co.uk/dp/B07VDLX55H/ (ebook - just £8 pre-order, out Sat 10th Aug)

I pre-ordered a copy of the e-book and once I get the time to read it, hope to post a review.

Here's the jacket blurb:

Clenow always talks good, simple as possible, plain common sense when it comes to trading. I'm looking forward to his new book.
 
Clenow "Trading Evolved" – first impressions

Having just had a quick "first read", my opinion is that this is an excellent book well up to the usual Clenow standard and one of the best trading related 8-Quidsworth (go for the E-edition) you're likely to see at the moment.

Although it does major on using Python for automated trading and back testing there is so much more of interest to any trader wanting to widen his horizons. As far as using Python is concerned he suggests that his idea of throwing you in the deep end will allow you to pick up what's going on: that's the only bit of the book that I'm not really convinced by (you've got to remember he's a pretty bright guy) and although he's got an excellent knack for explaining the complicated in a simple way I'm not sure he really appreciates how difficult it would be for a complete nerd to pick up the logic of coding. I would therefore recommend doing a basic Python intro course (plenty of excellent stuff available free on the net) before you start looking at the coding stuff in the book.

He recommends that you will need to read the book at least several times to get the best out of it and I'd agree with that. It's one of those books that you just need to get a general idea about and then go back into and find all the bits that didn't quite register fully the first time but later on make you realise their value. For the reader not particularly bothered with coding/Python the rest of the book is still very worthwhile and gives some excellent insights as to how the professional as opposed to retail trader thinks and operates. He explains very well why there are differences and does not disparage the retail trader but at the same time shows how the retail trader by realigning his thinking into more "professional" ways can benefit himself. One of his most interesting (and worthwhile in my opinion) beliefs is that one of the more common retail trader's way of assessing risk (distance to stop price) is flawed as a definition of risk and he spends some time in explaining how a professional hedge fund manager such as himself measures and deals with what he considers to be risk.

As a fund manager (and he has some pretty harsh words about the way some funds and their achievements are managed) he takes a longer view than say, the average day trader but I don't think that invalidates the principles of what he has to say – after all don't we all look at trends: it's only the timeframe that changes? He also has some very informative stuff about different asset classes for trading and how many traders actually increase their risk by remaining stuck in one asset class while thinking they are reducing their risk by diversifying within that class. It's the sort of thing that makes you think. It's very easy (in my experience) to get stuck in set ways once you find a profitable strategy – there's nothing wrong in that of course but on the other hand I believe it's always good to have an open mind and look for fresh opportunities.

In summary I would thoroughly recommend this book. Even if it turns out to be totally useless for you (and I would be gobsmacked if that was the case) the worst that you've done is lose £8 and that's a totally trivial amount in terms of everyday trading costs.
 
Last edited:
Assuming that you will eventually make a profitable EA, will you be selling copies of it ?
Perhaps to members ?
Could call it Shark fin soup or something.
lol
 
Assuming that you will eventually make a profitable EA, will you be selling copies of it ?
Perhaps to members ?
Could call it Shark fin soup or something.
lol

Haha.. or how about "Shark Invested" - the name of these forums before they became Trade2Win.
 
Yes it was all stocks for that particular strategy.
Hello,
you first have to choose if you want to divergent or convergent trade the two instruments. Majority of my trades where convergent hedge. You have two options to convergent hedge trade.

1) Based on fundamental ( long to medium range time ). choose a basket of technology against a basket of defensive stocks.
2) Based on technical. you have 2 options here

a) Use a mean reversion strategy with VWAP to be the mean. Easy to code
b) Use an alternative statistical Quant code Easy to code

The risk analysis of such a trade is controlled by a dynamic position sizing and not a static or Fixed pos size throughout the trade. if the pos sizing is inaccurate then the edge will disappear and you often end up with an overall losing trade ( market efficiency ).

The above strategy is market neutral.

Alternatively, you can directional trade. if you are directional trading then the best instrument needs to be an Index futures since they are zero-sum concepts ( all loops MUST close ) and one can predict the probability of the next move using various statistical methods. ( very much like the Heisenberg uncertainty principle where we would not know the certain value of the particle's position yet we can assign the probability to each occurrence ) .
 
Nice to hear from you Iraj, thank you for your reply and I hope all is well.

When you said
Use an alternative statistical Quant code Easy to code

Can you give more information on what you mean by this ?
 
Another book due to published shortly, worth adding to your Amazon wish list, is Leveraged Trading by Robert Carter:

Harriman House were kind enough to send me a review copy, which I received today (it's out in hardback and ebook end of October). Look forward to reading it His two previous books Smart Portfolios and Systematic Trading are both excellent reads, as is his blog: https://qoppac.blogspot.com/
 
The word "killer" in the title and the table of contents to Trading Evolved makes it look pretty suspect to me. Looks like just recreating the same useless algorithms from retail trading platforms in python.

I just picked up Mastering Python for Finance second edition by James Ma Weiming for 10 bucks ebook on Packt that is nice. Probably a little too academic to ever be very popular but there is no retail fluff. It goes well with De Prado's book.

A few months ago I also grabbed Hands-On Machine Learning For Algorithmic Trading from Packt for 10 bucks too that just terrible. Maybe the notebooks that you can download are worth 10 bucks but the book itself is like a collection of machine learning tutorials stolen from blogs that have nothing to do with trading and wrapped into a half ass book.
 
Clenow "Trading Evolved" – first impressions

Having just had a quick "first read", my opinion is that this is an excellent book well up to the usual Clenow standard and one of the best trading related 8-Quidsworth (go for the E-edition) you're likely to see at the moment.

Although it does major on using Python for automated trading and back testing there is so much more of interest to any trader wanting to widen his horizons. As far as using Python is concerned he suggests that his idea of throwing you in the deep end will allow you to pick up what's going on: that's the only bit of the book that I'm not really convinced by (you've got to remember he's a pretty bright guy) and although he's got an excellent knack for explaining the complicated in a simple way I'm not sure he really appreciates how difficult it would be for a complete nerd to pick up the logic of coding. I would therefore recommend doing a basic Python intro course (plenty of excellent stuff available free on the net) before you start looking at the coding stuff in the book.

He recommends that you will need to read the book at least several times to get the best out of it and I'd agree with that. It's one of those books that you just need to get a general idea about and then go back into and find all the bits that didn't quite register fully the first time but later on make you realise their value. For the reader not particularly bothered with coding/Python the rest of the book is still very worthwhile and gives some excellent insights as to how the professional as opposed to retail trader thinks and operates. He explains very well why there are differences and does not disparage the retail trader but at the same time shows how the retail trader by realigning his thinking into more "professional" ways can benefit himself. One of his most interesting (and worthwhile in my opinion) beliefs is that one of the more common retail trader's way of assessing risk (distance to stop price) is flawed as a definition of risk and he spends some time in explaining how a professional hedge fund manager such as himself measures and deals with what he considers to be risk.

As a fund manager (and he has some pretty harsh words about the way some funds and their achievements are managed) he takes a longer view than say, the average day trader but I don't think that invalidates the principles of what he has to say – after all don't we all look at trends: it's only the timeframe that changes? He also has some very informative stuff about different asset classes for trading and how many traders actually increase their risk by remaining stuck in one asset class while thinking they are reducing their risk by diversifying within that class. It's the sort of thing that makes you think. It's very easy (in my experience) to get stuck in set ways once you find a profitable strategy – there's nothing wrong in that of course but on the other hand I believe it's always good to have an open mind and look for fresh opportunities.

In summary I would thoroughly recommend this book. Even if it turns out to be totally useless for you (and I would be gobsmacked if that was the case) the worst that you've done is lose £8 and that's a totally trivial amount in terms of everyday trading costs.

Blimey, it's been pretty much a year since I posted anything of merit on my journal. Time flies when you're in a pandemic. I'm pleased to say I've finally recovered some time from my week to dive back into the topic of this journal.

Great first impressions @0007, I'm still just as excited as I was last year about this book. So to ease me back into the subject matter, I'm going to be working my way through the book and the examples in the coming weeks, and will post my observations along the way.
 
Don't be bashfull. Is your python system up and running ?
But more importantly is it profitable ???
 
Top