 It's nice to see you here. So today I will talk about algorithmic trading for fun and profit. So this is me, my name is Shen Long. I'm a developer at Shen Investor and just a bit of disclaimer just to make sure that I won't get arrested by monetary authority of Singapore. Yeah, so, okay, you have heard of different kind of terminology, you've heard of algo trading, high-frequency trading, mechanical trading, so on and so forth. But as far as this talk is concerned, I'll just stick with this definition. So algo trading is about developing a computer program that has got a predefined set of rules in it that helps you to automate the process of buying and selling in a financial market, such as stock market, but it could be forex or something else, bitcoins, for example. Just like some other scientific process, there are a few process involved. So we have the formula objective and hypothesis like how much money you wanna earn and then you develop a trading strategy. You back test your strategy with the historical data and then you measure and optimize. If it's good, you deploy to production. If it's not good, then you have to start from step two again. And if you want to build an algo trading system, the very first thing you need is actually financial data. So I call this component a feeder. So what it does is that it actually fetches financial data fit from external sources. So there are a few data sources. I'm actually a hobbyist, so I opt for the free one like Yahoo Finance. But let's say if you're a quant trader, maybe you have a little bit more money, you might want to subscribe to commercial data provider for more precise data. And this is actually how the CSV file looks like when you download it from Yahoo Finance. So this is actually the closing prizes for Apple on a daily basis. And this is actually the JSON response data that we get from Stock Twist API. So you can actually find out what people are talking about a particular stock on their social network, whether people are feeling optimistic or pessimistic about stock. And I basically use Typhus Jam because I need to download stock data for a lot of our stocks. So it's good for me to do these requests in parallel. And depending on the data format, I use CSV, JSON, or CoQ to pass the data. And after we have got the market data, we have to develop a strategy that takes in the market data as input and then we generate some trade signals as output based on the rules that we defined. So the question is, how do we define the rules? So well, there are different kind of techniques. Some people opt for fundamental technicals, news, and sentiment. It really depends on your style. But today I'm going to talk about technical analysis. So as you can see on the chart, this is actually the daily prizes of Apple for the past like two years. So I'm going to talk about this technical indicator called moving average. This is kind of like a hell over example in the technical analysis. So the red color line is actually fast moving average over 15 days. Whereas the green color line is actually slow moving average over 50 days. And it's actually not that difficult to program this in Ruby. In fact, as you can see, just a few lines. What you have to do is simply just, you know, calculate the mean of the closing data for the past X number of days. So if you're looking at simple moving average of 15 days, then you just calculate mean of stock prices over the past 15 days and allow us for the slow one. And once we have the data, what do we do? We actually have to identify the crossover. So whenever the fast moving average crosses above the slow moving average, in trading term, we say that the program can generate a long signal. So what does long signal means? It means that the curve is actually on uptrend. So on, and on the other hand, if it's a short signals, that means that the curve is actually on downtrend. And what do I mean by long? I, yeah, sorry, Aaron, I stole this from you. But I really like GobiPuff. Whenever I think of long, yeah, I thought of this. Yeah, it's pretty cool. So like, okay, so these signals actually advise portfolio in making trading decisions. So when you have a long signal, what you have got to do is that, or you think that the stock is actually bullish, you think that the price may go up in the future. So if you haven't got the stock yet, you may want to buy some. And if a signal is actually short, this indicate that the price may go down in the future. So you may want to sell it if you haven't got it, or you may want to short sell it if you haven't bought it. And portfolio actually keeps track of your cash, your market position, as well as the holding values. And most importantly, it actually helps you to assess returns and risks, because you have to know your profit and loss, as well as your risk. I mean, you can use a few matrix like sharp ratio, and you can calculate your downturn, things like that. And the last component is actually broker. It's actually a piece of code that execute trade by placing order in the market. Of course, in a back testing environment, you would want to simulate the market behavior. But in a live trading environment, you will want to invoke your broker's API to actually place the order in the actual stock exchange. And when an order gets filled, you have to notify your portfolio to update the position and holdings again. And all these components are actually wired out by using what I call the loops. There is actually an outer loop, and inside that there is actually a nested loop. And this piece of code can be represented by this diagram. I hope that it's easier to understand. So basically, you have got a feeder that gets the next bar. A bar is actually an abstraction, so it's like a trading activity over a period of time. So if you're looking at daily data, so this is the price for that day, but if you are, you can actually look at frequencies like minutes, even up to seconds. And then once you've got the data, then your strategy analyze market data, generate signals for the portfolio to place order, and then you execute the orders and up the holdings again. And for all of these, I actually created this project called HOMA, which is a proof of concept of what I say just now. And if you're interested, you can go there and follow more about it. And thank you.