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!
Let's walk it through. This will run overnight on a daily basis, once the previous day's EOD data is available.
- 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).
- For each strategy I have set up, run that strategy, which consists of...
- 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.
- Check if it is a trade day. Strategies can be either daily or weekly.
- Declare universe. A fancy way of saying get the symbols that are assigned to this strategy.
- 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.
- 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).
- 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.
- 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).