Algorithmic Trading Strategies
Last updated
Last updated
lgorithmic Trading aims to remove the human factor and instead follows pre-determined statistics based strategies that can be run 24/7 by computers with minimal oversight. Computers can offer multiple advantages over human traders. Firstly, they can stay active all day without sleep. They can also analyse data precisely and respond to changes in miliseconds. In short, they never factor emotions in their decisions. For this, investors have long since realised that machines can make excellent trading given that they are using the correct strategies.
Machine Learning and Artificial Intelligence stand to push Algorithmic tradings to new levels. Not only can more advanced strategies be employed and adapted in real time but also new techniques like Natural Language Processing of news articles can offer even more avenues for getting special insights into market movements.
Algorithmic Trading in Practice
A trader must follow these simple trade criteria:
Buy shares of a stock when its 30-day moving average goes above the 100-day moving average.
Sell shares of the stock when its 30-day moving average goes below the 100-day moving average.
Now , What is Moving Average?
In statistics, a moving average is a calculation used to analyze data points by creating a series of averages of different subsets of the full data set. In finance, a moving average (MA) is a stock indicator that is commonly used in technical analysis. The reason for calculating the moving average of a stock is to help smooth out the price data by creating a constantly updated average price. By calculating the moving average, the impacts of random, short-term fluctuations on the price of a stock over a specified time-frame are mitigated.
Importing the required Libraries and reading the dataset
Importing the required libraries and reading the dataset
An overview of the dataset
Coal-India Dataset
Cleaning and Visualization of the data
We take the Prev. Close Price column because it describes the data best.
Creating Moving Average window
In the above piece of code, we first created a 30-days MA window (lines 2â3) and then a 100-days MA window (lines 6â7).
Visualizing the results of Moving Average window
Our next step is to visualize the 30-days MA and 100-days MA window and the Prev. Close Price column to compare them.
We can now see the visualization:
Creating a dataframe to store the data
Here, we create a dataframe to store all the required data:
Creating a buy and sell function
Here, we will create two functions buy and sell which will determine the positions of buying and selling shares. It will simply follow the trading criteria as mentioned above.
This will simply create a signal when it is suitable for a trader to buy and sell.
Visualizing the data with signals
Our final work is to visualize where a trader must buy or sell. For this we Store Buy and Sell into a variable. Then we visualize the required plot.
Output:
The Green signals show where a trader must buy shares of Coal India and the Red signals show where a trader must sell the shares of Coal India so that the trader makes profit in the long run.
Reference : https://medium.com/the-owl/algorithmic-trading-strategies-5c3b9d6ab618