Algorithmic Trading for Fun and Profit (Red Dot Ruby Conf 2014)

Algorithmic Trading for Fun and Profit (Red Dot Ruby Conf 2014)


Sheng-Loong Su

June 27, 2014



  2. None
  3. DISCLAIMERS This talk is intended for educational purposes only This

    talk is not a demonstration of how to trade This talk is not intended as investment advice and must not be relied upon
  4. WHAT IS ALGORITHMIC TRADING? “The use of a predefined set

    of rules written into computer code to automate the process of buying or selling.” -
  5. ALGORITHMIC TRADING PROCESS 1. Formulate objective and hypothesis 2. Develop

    trading strategy 3. Backtesting with historical data 4. Measure and optimize 5. Deploy to production
  6. FEEDER Fetch financial data feed from external sources

  7. FEEDER - DATA SOURCES Free Commercial 1. Yahoo/Google Finance 2.

    Quandl 3. Twitter/StockTwits 1. DTN IQFeed 2. QuantQuote 3. EODData
  8. None
  9. None

  11. STRATEGY Take market data as input and generate trading signals

    as output based on the rules defined
  12. STRATEGY - ANALYSIS TECHNIQUES Fundamental Technical News Sentiment

  13. Red line - Fast Moving Average (15 days) Green line

    - Slow Moving Average (50 days) Technical Indicators
  14. def moving_average bars, lookback_period if bars.length < lookback_period raise "insufficient

    number of bars" end sum_of_prices = bars.last(lookback_period) .inject(0.0) { |sum, bar| sum + bar[:adj_close].to_f } sum_of_prices / lookback_period end fast_ma = moving_average bars, 15 slow_ma = moving_average bars, 50
  15. Fast MA > Slow MA = Long Signal (Uptrend) Fast

    MA < Slow MA = Short Signal (Downtrend) Moving Average Crossover
  16. None
  17. PORTFOLIO Make trading decisions based on signals generated by strategy

    Keep track of cash, market positions and holdings Assess returns and risks
  18. BROKER Execute trade by placing order in the market Notify

    Portfolio when order gets filled
  19. THE LOOPS loop do # Feeder gets next bar break

    if bar.nil? loop do # Dequeue from event queue break if event.nil? case event.type when :market # Strategy analyzes market data # Portfolio updates holdings when :signal # Portfolio places order when :order # Broker executes order when :fill # Portfolio updates holdings end end
  20. None

  22. THANK YOU <3