Home Beginners Resources Learning Python – My Personal Journey

Learning Python – My Personal Journey

by s666

I have been asked multiple times lately, by various different people, as to whether I could write a blog post about how I got from where I started (someone who had never coded before at all), to where I am now (someone who’s still firmly in the “learning” camp, but able to create a range of semi-useful code snippets).

Those asking pointed out that although it was relatively interesting and fun reading my posts while following along, replicating my code line for line and then running the script to get their output, my posts weren’t great at actually helping people develop the necessary skills and knowledge to be able to branch out and create their own mini-programs and projects. Nor did I tend to point readers in the right direction of the actual resources that I myself had used and found useful to develop as a Python programmer.

I totally take this on board, and appreciate there is a fundamental difference between just presenting my own mini-projects in blog posts and inspiring/helping others to be able to identify and create their own mini-project“wish-list”.

So with that said, here is my (first) attempt to rectify that situation and blog about slightly more “meta” topics, related to the process of learning Python, rather than Python itself.

It seems like as good a place as any to begin by recounting my own experience of the learning process, as after all I did start right at the beginning with literally zero knowledge or exposure to any kind of coding or programming, save for perhaps a few attempts at using the “Macro Recorder”in Excel and then trying to decipher the related code output in the VBA Editor.That was back around 2007.

Suffice to say those “attempts” weren’t exactly fantastically successful. I eventually managed to hack together a couple of “working”macros (and I use the term “working” rather loosely!) that automated a small number of simple, but repetitive Excel tasks I was responsible for carrying out on a daily basis.

Looking back, the actual code that made up the macros was absolutely horrific, and really would have made any programmer worth his salt despair – but to me it seemed like magic!!! I have to admit I spent an embarrassing amount of time resetting and replaying my macro, just to see it work that “magic”again and again – “Happy with myself” was an understatement.

Well that was quite a few years ago, and it wasn’t until much later in early 2013 that circumstances lead me back toward the world of coding and programming.

I have spent the entirety of my career (about 16 years) involved in the financial markets, with the vast majority of that time (around 15 years)spent working as a trader on various trading desks in the City of London. I won’t bore you too much with the detailed ins and outs of my career history, but I mention it to highlight the fact that in 2013 I started a new job at a London based CTA firm, which specialised in systematic/algorithmic mean-reversion trading strategies executed almost exclusively on the large, liquid index futures markets (e.g. Eurostoxx50, S&P500 etc).

Previous to joining that CTA, I had almost exclusively worked in trading environments that could be described as “discretionary”. To highlight the main difference between “systematic” trading and “discretionary”trading as a fundamental ethos the main points should be noted:

  • With discretionary trading each buy and sell decision is made subjectively by (or at the “discretion” of) the fund/portfolio manager based on their interpretation of current market conditions. This means trade logic can deviate substantially from one trade to the next.
  • With “systematic” trading strategies a set of concrete“rules” are defined and then often converted into a computer algorithm that is then fed historical pricing data to “backtest” the strategy logic in an attempt to identify a profitable set of rules. Once a satisfactory algorithm has been identified and defined, it is then followed as objectively as possible allowing the “system”to dictate trading activity to be followed as closely as possible.

So what has all this got to do with learning Python you ask?Well as soon as I saw how systematic  trading strategies could be coded up and backtested, I was completely hooked! It was like my eyes had been opened to a whole new world of trading that I had no clue really existed until then – a complete paradigm shift.

Seeing all this going on around me, I so, SO wanted to be able to design and back-test my own trading strategy – it suddenly became an all-consuming mission to get where I needed to be.

The point of all this background waffle boils down to this –you need to REALLY want to learn to code if you’re going to give yourself a decent chance of success in your journey. This stuff is hard!! Don’t believe anyone who tells you any different…There are going to be times when you just feel completely out of your depth and defeated and it’s at those times you need to be able to draw on that overwhelming desire to succeed. But I’ve yet to meet anyone who is THAT passionate about “coding” in and of itself – the passion is really to be found in the desire to use your coding skills to BUILD something or CREATE something that means something to you personally.

If I can give one piece of advice to anyone starting their journey, it is this – think about what you want to eventually use your newfound skills to create. Think until you have something in your mind that excites you enough to keep you focused through the hard/frustrating/demoralising times ahead – and those times WILL come, trust me!

It could be building your own personal web site and blog, it could be creating your own adventure game (text based or with graphics),perhaps designing and coding your own trading strategy with corresponding system to generate and display in-depth performance reports. Basically it can be anything that means something to YOU, something that gets your juices flowing just by thinking about it and imagining how you’ll feel when you finally achieve it.

I’m not a “wishy-washy, touchy-feely” kind of guy, but in this case I cannot overestimate the value of having that end goal in mind and nurturing the corresponding feelings and emotions that come along with the thought of success in that goal.

When you have chosen your desired project, please do leave a comment in the comments section below and tell us about your idea – it’s always useful to hear about other people’s plans and thought processes. Tell us what your project is, and why you chose it – why you have such a strong desire to create it and how do you plan getting from “here” to “there”. I really do urge you to leave a comment so we can help you start your journey on the right foot.If I can I will recommend some useful learning resources, tailored to your specific project!

Ok, that’s enough of the focus on emotions and feelings…probably time to get a little more practical!

So you’ve decided you want to build something, you’ve decided that you want to build that thing in Python and so you sit down at your computer screen and…well, you suddenly realise you don’t really have a clue what to do next. Don’t panic!! I know the feeling – I was right where you are when I started.

On day one, if I recall correctly I somehow landed on the codecademy.com website, and saw they offered an introductory Python course. I remember it being relatively entertaining and did a good job of hand-holding most of the time, with the odd “harder” exercise thrown in here and there that took me a day or so on occasion to solve/complete successfully. What I didn’t realise was that the whole Codecademy experience takes place in their “sandboxed”environment – they use technology which allows all the python code to be created/tested/executed within your browser, negating the need to actually download, setup and run Python on your local machine.

This is all well and good, and I understand why it is designed this way to offer ultimate ease of use and minimal barriers to entry,but for me it worked as a negative in my learning journey. I was at a stage where I didn’t know what I didn’t know – and I didn’t even realise I was trapped in their sandbox…

As soon as I closed my browser and tried to “do” Python on my own, I was even more confused than when I started. Codecademy does nothing to help you with the initial set-up stage, nothing to help you contextualise the Python environment and ecosystem and how you create, store and run “real”python files. It conveniently omits anything that would tend to lead you away from their little closed browser based environment. Combined with the fact that there seems to be almost no courses offered that are accessible without paying for the “Pro” version anymore, I would recommend giving Codecademy a pretty wide berth!!!

One of the things that I learnt over time, was that for every paid course online promising to teach you Python, there was an equally good resource available for free that offered just the same quality and depth –all you have to do it dig around a little bit (and honestly most of the time you hardly have to dig at all – there are that many quality free resources).

A great source of structured Python courses that I gravitated toward quite early on in my journey was the various MOOCs offered online by various academic institutions and universities. MOOC stands for “Massive Open Online Course” and they can be found through the main MOOC providers –namely Coursera (www.coursera.org), Udacity (www.udacity.com)and EDX (www.edx.org).

The first couple of courses I enrolled on were provided by Coursera and they were:

  1. Programming for Everybody (Getting Started with Python) – University of Michigan

(https://www.coursera.org/learn/python)

  • An Introduction to Interactive Programming in Python (Part 1) – Rice University

(https://www.coursera.org/learn/interactive-python-1)

It was a few years ago since I took them, but if my memory serves me correctly, I recall both of them being a great starting point and foundation that I was able to build upon in the forthcoming months. They both did a great job of starting right at the very basics, easing you through the Python installation and setup process, helping explain how the different moving parts (Python language itself, the IDE or “Interactive Development Environment”,the command line terminal etc) fit together to form the “coding environment” that,if used correctly, would allow you to create and run any imaginable program you could create with Python.

Some of the earlier sessions and exercises felt a bit on the easy side (especially with the Programming for Everybody course), but there was plenty to keep me busy in the latter stages of both courses. I remember battling with one of the later assignments from the Rice University course,where we had to design and code a “Rock, Paper, Scissors” game – but this time it was the “Rock, Paper, Scissors, Lizard, Spock” game. I got completely stuck on how to join up the cyclical nature of the scoring system whereby each option can always be beaten by the option to it’s left. I could get it all to work except for that issue. Looking back it’s a rather trivial problem to solve, but at the time it drove me crazy.

If anyone cares, the solution to the problem lay in the use of the “modulo” operator. I’ll leave it at that in case I risk spoiling the fun for anyone who takes the course and tries the problem for themselves…

So to quickly recap the main points so far:

  1. It is VITAL to identify and select a project you wish to eventually create – something that really means something to you and excites you when you think about it.
  2. Steer clear of Codecademy as an early Pythonresource – Most of it is now behind a paywall and the whole concept of trapping you inside their sandboxed environment can end up causing added confusion rather than helping.
  3. Consider signing up to a quality MOOC beginner Python course – my recommendations are the two listed above (I’m sure there are many other quality courses on offer out there, but those are the two I have experience with and they both did a good job of getting me from zero to “absolute beginner”.

I think I’ll leave it here for the moment, it seems like it might be best to break this blog topic into a few consecutive posts to reduce the risk of anyone dying of boredom!

In the next instalment I’ll move on through my own learning time-line with suggestions/recommendations etc thrown in here and there for good measure. I hope this post hasn’t been too “waffly” – I appreciate it’s a fine line when writing about subjective experiences and such. If anyone fancies commenting below with details of their pet project ideas and details of what they want to build and why , that would go a LONG way towards validating this post and the deviation from “coding” articles for the addition of a more subjective piece.

If people just downright hated this wall of nonsense, do also feel free to let me know – feedback is always appreciated, good of bad!

Till next time…

You may also like

5 comments

Mike January 11, 2019 - 2:06 am

Came to this site from your post on the reddit r/CFA. Thanks so much for sharing! I am in the same boat as you with absolutely no programming experience, but feel the need the learn python to become more marketable. My goal is to be able to develop an algorithm that can project various assets growth given macroeconomic indicators (through backtesting). Obviously, it is already used in practice and I know that I won’t hold a candle to anything that the pros are using, but it would be pretty fun nonetheless. I also realize that this is going to take A LOT of time, but any advice for a novice would be appreciated! I’m going to continue to read through your other blogs.

Reply
s666 January 14, 2019 - 5:16 pm

Hi Mike – thanks for the comment! My initial advice to you would be to accept (as you seem to have already) that your first steps may seem slightly removed conceptually from your end goal – but that’s ok – walk before you can run and all that.

I would suggest finding a MOOC course – perhaps one of the first two Coursera courses I mentioned in the post, and following to introduce you to the very first steps of learning to program in a formal structure that you can work through. This will take you from “day 1 I know NOTHING” to a level where you can begin to play around and create little trivial scripts to maintain your motivation and engagement.

In terms of the actual financial algorithm side of it – that is a whole other kettle of fish to get something valuable that performs.

I’ll send you an email and perhaps we can discuss that side of things more completely over time over email rather than reveal your hard work to the entire online world 😉

I believe I have your email address – I shall contact you shortly.

Reply
Mike July 12, 2019 - 3:22 am

i just stumbled upon your website from a “python for finance” google search. This whole series is great and has set me on a better path.

I have tried one of the online coding academies in an attempt to learn R, but found exactly what you did; it just doesn’t carry over well to the real world outside of their defined environment.

Thank you for writing this series.

I look forward to making your blog a regular read.

Reply
s666 July 12, 2019 - 4:46 am

My pleasure, glad to have you here and hope you enjoy the content! 😉

Reply
Aaron Fox August 7, 2019 - 8:59 am

Thank you for your posts. I think you did a great job of balancing the details of your ‘subjective experiences’ with very relatable and inciteful advice. I also stumbled onto your blogs by google searching for help with how to write code to backtest trading strategies in python. I have a similar background to you in that I have my CFA and was a discretionary trader working for various large institutions in NY for 9 years before moving to Australia and now trading on my own utilizing mostly systematic trend following strategies for both crypto and traditional assets. I do have some limited coding background from learning the basics of object oriented programming in university to recording/modifying VBA-macros for excel during my institutional years and, more recently, scripting strategies in tradingview.com’s native language. Because of some of the limitations to tradingview along its rather manual process for updating and backtesting strategy parameters, I’d like to convert the code to python. Like you mentioned in your post, I have also struggled to find the resources that “contextualise the Python environment and ecosystem and how you create, store and run ‘real’ python files.” Very well said! Given my prior experience and the great resource that the internet is, I figured that, once I got the basics of the ecosystem understood, I’d be able to convert my strategies’ code to python, upload some pricing data files, and begin structuring some basic strategy backtesting analysis. Unfortunately, I still remain at the starting line and I’ll take your advice on learning the basics through the coursera offerings you mentioned. Thanks again for your blogs and please don’t hesitate to reach out if you’re interested in discussing trading strategies any further. Regards, Aaron

Reply

Leave a Reply

%d bloggers like this: