Floating Graphs, Numpy Functions & Python Charting for Algorithmic Trading
Algorithmic trading is revolutionizing today’s financial markets. It helps traders to implement automated strategies with accuracy. But did you know that algo trading is incomplete without charts?
Using Floating Graphs, we can visualize market trends, which is essential for any trading strategy. Today we will learn how to create different types of charts with the help of Python and Numpy.
Creating Charts in Python using Numpy and Matplotlib
We use two major libraries for data visualization in Python:
- numpy (for data generation and mathematical operations)
- matplotlib.pyplot (for creating graphs and charts)
âś… X = Y: Straight Line Chart
First, we created 100 data points ranging from -10 to 10 using numpy.linspace(). Then we created the X=Y graph which shows a straight line.
✅ Y = X²: Parabola Graph
Next, we plotted the graph of Y = X**2, which gives us a parabola. This graph shows how the square of a variable makes the graph move upward.
âś… Y = sin(X): Sine Wave
We also plotted a sine wave using the numpy.sin(X) function. It is very useful in signal processing and time series data.
âś… Y = X*log(X): Logarithmic Graph
This graph shows how the graph of a logarithmic function gradually goes up as X increases. For this, X * np.log(X) was used.
âś… Chart of Sigmoid Function
Sigmoid function is an important non-linear function used in machine learning and trading signals. Its formula:
1 / (1 + np.exp(-X))
Its graph comes in the shape of “S”.
Essential Numpy Functions for Algo Trading
np.sort() – Sort Data
This function sorts the data in ascending order.
Use on 1D Array: Simple sorting
Use on 2D Array: Use axis=0 or axis=1 for Row-wise or Column-wise sorting.
np.sort(array_name, axis=1) # Row-wise
np.sort(array_name, axis=0) # Column-wise
np.append() – Append data to an array
This function is used to add new data to the end of any NumPy array.
- 1D Array: Can add a single value
- 2D Array: To add a new row or column, axis has to be set
np.append(array, new_values, axis=1) # Column-wise append
np.concatenate() – Concatenate two arrays
This function concatenates two arrays together.
Axis=0 for row-wise append
Axis=1 for column-wise append
Algorithmic Trading Essentials for Global Traders
If you want to learn quantitative trading in countries like Singapore or USA, then this video can be a great starting point for you. Using Python and open-source tools like Freqtrade, you can create automated trading strategies in cryptocurrency or the stock market.
Watch this Day 22 video tutorial
Day 22: Plotting Charts & Special NumPy Functions
9/20