Simple Trading Systems using Simple Python Code

Discussion in 'App Development' started by zenostiffler, Dec 10, 2018.

  1. A Simple Mean Reversion System

    I have back tested and traded relatively simple systems using daily data for almost 20 years now. For many years I relied on two excellent but ultimately limiting commercially available packages: Trading Blox and Mechanica.

    I then branched out into using Python since I got fed up paying licence fees and being limited by other people's architecture. I have no back ground in coding but I have been engaged in financial markets for 40 years - my entire career. Much of that trading my own book.

    For many years I traded futures using various trend following methods but for whatever reason that is no longer producing the oversized profits it once did.

    I therefore turned to looking at whatever caught my fancy and using simply Python code in Jupyter notebooks, I set out to test various ideas out on historical data.

    I recently came across a very simple version of a mean reversion system on Quantopian which was designed simply to illustrate the dangers of over fitting.

    I was much taken by the simplicity of the code and decided to play about with it. The results you will find on my gist:



    Currently there is no fixed fractional position sizing and investment is made using single shares in the relevant stock and (optionally) pyramiding the position.

    There is currently no provision made for slippage or commission.

    Both of the "disadvantages" are easily rectified and I shall probably post updates at some stage.

    https://gist.github.com/AnthonyFJGarner
     
  2. jonahern

    jonahern

    Thanks for sharing!
     
  3. Thanks for looking! Its no fun designing all this stuff unless you get some feed back and interaction. I hope to post quite a few more systems here as I go along. all comments and criticisms welcome.
     
    entropytrading likes this.
  4. guru

    guru

    The “whatever reason” is that people like you started sharing their strategies and when everyone does the same thing then it stops working. The edge is always in doing something that no one else does.
    And this applies to every business.
    Though of course I will milk your strategy till there is no milk left, so please provide all details once it works for you.
     
  5. Tell me, do you believe a trader is better letting a series of code decide entry or human entry only ?
     
  6. guru

    guru

    I’m not sure if there such a thing as “human entry only”. At least we can see that tons of traders use algos to not have to trade manually, while many big hedge funds duplicated and improved a lot of human trading. They put $billions into pretty much any strategy that was published and has/had potential to be profitable.
     
  7. Are you trading at either open or close price?
    Those prices do not exist in real life, and not including slippage or commissions is not sensible either.
    You want a trading system that back-tests profitably using very demanding market assumptions, then you can go out in the real world and check out if the results hold (usually they don't)
     
  8. The entries are made at the open following the close at which the moving average is calculated. IE the next day. Regarding commission and slippage, as I said in the opening paragraph, these provisions are easily included.
     
  9. Generating Theoretical Option Prices

    A while ago I put a lot of work and effort into looking at Black Scholes and various other option pricing models. Given that you can pay a small fortune for each option series you purchase from the CBOE, it occurred to me that you may as well back test on theoretical option prices that you generate yourself.

    The Jupyter Notebook set our below (and hosted on Jupyter NB Viewer where you will be able to see it more clearly) was the result of my efforts, with which I was fairly pleased. I then realized that I had failed to estimate the "Volatility Smile" whereby options further out of the money or in the money tend to have an implied volatility slightly different from ATM options in the real market place.

    At some stage I will revert to the notebook and attempt to model the volatility smile but at this stage I thought I may as well release the Notebook to those (few!) who may have interest.

    I have not looked at this code for quite some time. Caveat Emptor, make of it what you will. If you don't code, or are not familiar with Python and its libraries, "move on and ignore this post" would be my advice!


     
  10. Here is a simple trend following system based on simply reversing the Mean Reversion system posted previously. Provision is made for slippage and commission but position sizing is still not fixed fractional. The latter however is easily coded if desired.

     
    #10     Dec 12, 2018
    jonahern likes this.