Stock Analysis with Wolfram Mathematica – Part 2

Written by on August 19, 2025 in Mathematica, Programming with 0 Comments

In the previous article, I had explained how to get started using Wolfram Mathematica’s stock analysis features. The focus was on working with the exchanges supported by Mathematica, for example BSE India.

What if we have stock data from a different source and want to analyze it in Mathematica? In my case, I use TradingView platform and there is an option to download the data in CSV format. Besides, I use NSE instead of BSE. In this article, I will show how to use the data from TradingView.

For our discussion, I have downloaded HDFC Life Insurance Co (HDFCLIFE) data of a couple of years from TradingView in CSV format. This contains Open-High-Low-Close-Volume (OHLCV) data. The Time is saved in Unix format.

Here is a function that reads this file and prepares the data for subsequent steps:

Loading the CSV Data

Function to Load CSV File

Let us load our HDFCLIFE data using this function.

Loading the Data

Loading the Data

We see that we have slightly over 2 years of data in the file.

Next, we need to convert this data to the format that is compatible with TradingChart[] function. The following two functions do the job. For convenience, one returns just the OHLC data, while the other returns Volume as well.

Coverting the Data To Proper Format

Converting the Data To Proper Format

We are now ready to use the TradingChart[] function:

Rendering the Chart

Rendering the Chart

How about adding BollingerBands to the chart? Quite easy.

Adding Bollinger Bands

Adding Bollinger Bands

For convenience, let us write a wrapper function that loads the data and also displays it:

Wrapper Function

Wrapper Function

Here is how we can use it:

Using the Wrapper Function

Using the Wrapper Function

Makes sense, right? 

Working with our own data set is a major advantage. Instead of merely rendering the chart, we can optionally take advantage of the advanced numerical and predictive capabilities built into Mathematica.

You can download the CSV data and the source file here.

Have a great week!

Tags: ,

About the Author

About the Author: .

Subscribe

If you enjoyed this article, subscribe now to receive more just like it.

Subscribe via RSS Feed

Leave a Reply

Your email address will not be published. Required fields are marked *

Top