My stab at an automated trading system

Discussion in 'Journals' started by Bigchazza, Nov 13, 2020.

  1. Bigchazza

    Bigchazza

    Thanks shriekpurser. I hope myself and maybe others can learn something from it. If only what not to do!
     
    #21     Nov 21, 2020
  2. Bigchazza

    Bigchazza

    Thought I'd share some more about this. Here is a high level view of the sequence of events. Next time I'll post the architecture, as in what services do these things and what platforms and tech I am using. To remind you, this is my attempt to build a backtesting and automated trading system from scratch. For the hell of it!

    [​IMG]
    Let's walk it through. This will run overnight on a daily basis, once the previous day's EOD data is available.
    1. Call data API to refresh daily EOD bars of stocks in my strategies (using Alpha Vantage right now, which is free). That goes into "snapshot" (a database table).
    2. For each strategy I have set up, run that strategy, which consists of...
    3. Check regime. Bull or bear? I have a strategy which runs in bear markets so it's not as simple as "only run if bull market". It's a terrible strategy though so I won't be using it! Regime check is on an exchange level (US or UK), and is just a check of SPY or FTSE100 against 100 day MA.
    4. Check if it is a trade day. Strategies can be either daily or weekly.
    5. Declare universe. A fancy way of saying get the symbols that are assigned to this strategy.
    6. Get strategy parameters. In my approach strategies are just combinations of indicators and rules. E.g. MA crossover, bollinger bands, donchian channels, momentum ranking etc. Plus rules for exiting the position and risk management.
    7. Get signals. For live trading this is just looking at the data in the context of the new day's bars and seeing if anything pops up, depending on what that strategy is set up to look for. Any signals that are found, drop them in the database with the position sizing and stop loss (if applicable).
    8. Trade the signals. When (if!) this ever goes live this will mean calling the broker API and doing the order management, then recording what happened for future management (e.g. if the exit strategy is not stop loss and the system need to sell it). For backtest mode it is simulating the trades.
    9. In backtest mode the final bit is to count up the results and reports.
    All of this is built except the broker API link and anything about real trades. I'm debugging right now with a view to having a functional backtest system doing exactly what I want and queueing up backtests to run round the clock, if that's what I want to do. Right now this is all on a PC, but if I go ahead with this it will run in AWS - more on that later. It really hasn't taken long to build from scratch, less than a month, and not much actual coding - the beauty of drag and drop tools. And all using free data and open source tools. That free data bit of possibly a pitfall because there is a risk it leads me to innacurate backtest conclusions, but assume I'll retest strategies on broker data once I decide on a broker (prob Interactive Broker).
     
    #22     Nov 21, 2020
    d08, fan27, Russell Shuffle and 2 others like this.
  3. Interesting to see your high level setup.
    One thing that you may want to consider is how to run this if you are using instruments (e.g. stock) in multiple time zones (e.g. US and UK). The trading days will not be identical for all instruments. For example the step called "refresh EOD data" you have to take care that you don't include data for a trading date which is still ongoing, not yet completed. A similar consideration will be necessary for the step called "Run strategy (date)".
    On a related note: national holidays differ per country and exchange. Somehow you'll need to take that into consideration as well.
     
    #23     Nov 21, 2020
  4. fan27

    fan27

    Looks like fun! A member on this site (though I don't think he is active these days) rolled his own solution and it is open sourced here:

    https://github.com/nautechsystems/nautilus_trader

    Might be worth checking out.
     
    #24     Nov 21, 2020
    toon and Bigchazza like this.
  5. Bigchazza

    Bigchazza

    Thanks HobbyTrading. Yeah that will be a bit of schedule management I'll have to work in then. I have kept strategies exchange-specific (e.g. momentum UK, momentum US) which lends itself to this. BTW I have a calendar table that flags trading days US or UK. If I wanted to add e.g. France or Japan I'd have to add columns!
     
    #25     Nov 21, 2020
  6. I don’t think that automated trading systems are what they say. There are hardly any good reviews that I have seen for automated trading.
     
    #26     Nov 25, 2020
  7. Bigchazza

    Bigchazza

    There's a lot to unpack there wootspurser. What do automated trading systems say they are? I can only speak for what I am doing, which is to meet the requirements set out in an above post. Because I am building it from scratch it will do exactly what I say it will (I hope!)

    Regarding automated trading in general, if something can be reduced to rules, of course it can be automated. Everything is APIs. When you do a manual trade on your broker website, it is calling an API. Why not call the API yourself? Or write the code that does it for you if certain conditions are met?

    If you are talking about third party products you have seen out there that offer automated trading services, I can't speak for them.
     
    #27     Nov 25, 2020
  8. I haven’t heard of that before. Thanks for this.
     
    #28     Dec 3, 2020
  9. senumouv

    senumouv

    Many of us might find automated trading systems as an easy way of trading. But it also doesn’t guarantee a 100% profit. They can only add to profitable trades. And if you happen to find a system that guarantees 100% success, it is probably a scam.
     
    #29     Jan 12, 2021
  10. d08

    d08

    One must use a proper trading calendar for this. I'm using Pandas Market Calendars and use a layer on top of it to check whether today is a trading day or when is the next one or how many bars are needed for X amount of time based data or whether a day is a half-day.
    I used to trade Japan on top of US and the only manual interference I needed was with cron jobs during DST (Japan doesn't have it, US does). Of course this should also be automated.
    It's even useful when you need to know when to adjust data for dividends/splits. Details like this determine the difference between good and bad data as input.
     
    #30     Jan 12, 2021