AUTHOR:
Overview
In today's rapidly evolving financial landscape, staying ahead of the curve requires access to real-time data and powerful visualization tools. As I can see the importance of equipping individual traders with cutting-edge solutions. In this article, we'll explore the seamless integration of Microsoft Power BI with the LSEG Data Library for Python, enabling you to effortlessly visualize financial data. By the end of this article, you'll be able to create captivating visualizations that empower you to make data-driven decisions and gain a competitive edge.
Plus, this article also includes how to use Python script to retrive the data into Power BI with Conda environment.
We're going to create a visualization board to visualize the financial data retrieved from the Data Library, the two panels below are used to demonstrate.
- The first one is the simple one, we're going to retrieve the ESG Score and yield data with the TRBC (Thomson Reuters Business Classification) Economic Sector name using pie charts and clustered column chart
- The second one is retrieving the Yield by the TRBC Economic Sector name as a pie chart and table, and the histogram of summarize of yield and net income growth percentage, broken down by instrument.
Let's get to know the tools used here, which are LSEG Data Library, Microsoft Power BI, and Conda
LSEG Data Library for Python
The LSEG Data Library for Python provides a set of ease-of-use interfaces offering coders uniform access to the breadth and depth of financial data and services available on the LSEG Data Platform. We're using desktop session in this article, where the data doesn’t leave the desktop, the Desktop access point allows user to access LSEG data more flexibly. (if you want more than that, i.e. beyond single applications on one desktop, or you want data to leave your desktop, the Platform session is the right solution for you. Please talk with your LSEG account representative regarding the license type.)
To get started, All you need is LSEG Workspace account and application. Simply follow the Quick Start instructions
Microsoft Power BI
Microsoft Power BI is a user-friendly and powerful tool for visualizing data and gaining insights. It helps to make sense of complex information by turning it into interactive reports and visually appealing dashboards. With Power BI, you can connect to different data sources (in this article, we'll retrieve the data from the Data Library using Python code) then transform data into meaningful formats and create the visualizations without needing advanced coding skills. Whether you're a business analyst, data enthusiast, or individual trader, Power BI makes it easy to explore data, spot patterns, and make informed decisions. It's enabling anyone to unlock the value of their data and uncover valuable insights.
Conda
Conda is a powerful command line tool for package and environment management for multiple programming languages including Python. It allows you to install, manage, and update packages from different languages, ensuring consistent package installations and dependencies across your projects.
Prerequisite
This example requires the following dependencies software and libraries.
- LSEG Workspace application with Workspace account
- Python environment in Conda with LSEG Data Library for Python (Python version 3.10.11 and LSEG Data Library for Python 2.0.1 are used here)
- Microsoft Power BI Application
- Internet connection.
Please contact your LSEG account representative to help you to access LSEG Workspace credentials. You can generate/manage the AppKey by following the steps in the LSEG Data Library for Python Quick Start page.
Use Python Script in Power BI with Conda environments
To let Power BI use specific Conda environment that have required libraries installed, we need to follow these steps.
1 ) Activate specific Conda environment, here I use environment named ldlib-24 with lseg-data library installed (Regarding how to set up the conda environment, you can follow Conda documentation here)
2) Launch Power BI Desktop from the activated environment. It can be run by launching Anaconda Prompt in the directory of Power BI Desktop (As I'm using Power BI Desktop application from Microsoft Store, my directory is C:\Users\<USERNAME>\AppData\Local\Microsoft\WindowsApps with the command PBIDesktopStore.exe)
3) In Power BI's toolbar, click File > Options and settings > Options. In Options window's Global bar, click Python scripting and set a Python home directory to the environment we're going to use, then click OK. As I'm using Miniconda here, the directory of my environment is C:\Users\<USERNAME>\Miniconda3\envs\ldlib-24 (the directory can be changed from Miniconda to Anaconda based on which Conda and environment you're using)
Retrieving Financial Data with Python:
Before start using the Data Library, please check Quick Start Guide and The Data Library's Configuration Process as you may need configuration file, which is lseg-data.config.json, you can modify this file depending on the access channel and connection parameters that you will use to connect to the LSEG Data Platform.
The code below is used to retrieve the data from LSEG Data Library. You can test by executing the code in your preferred code editor to make sure it works fine before putting the code in the Microsoft Power BI application to retrieve the data. In this article, we're going to do two pages of Power BI from two dataframes retrieved from the Data Library. Let's check the step for each dataframe below.
Let's get started! After having a Python code for the data retrieving and making sure that it could run properly, this code is ready to be put in the Power BI. Here we're retrieving constituents in SET 50 Index data of
- TR.TRBCEconomicSector: TRBC classifies companies wiht increasing granularity by Economic Sector, Business Sector, Industry Group, Industry, and Activity.
- TR.TRESGScore: ESG Score is an overall company score based on the self-reported information in the environmental, social, and corporate governance pillats.
- PCT1M: Percentage change of the latest price and the price of 30 calendar days ago.
- CF_YIELD: Yield.
import lseg.data as ld
from lseg.data.discovery import Chain
ld.open_session()
set50_rics = Chain(name="0#.SET50")
set50_df = ld.get_data(set50_rics, ['TR.TRBCEconomicSector','TR.TRESGScore','PCT1M','YIELD'])
ld.close_session()
Below is the result of the code execution in Jupyter Notebook.
In Microsoft Power BI, Select the Home tab > Click Get data dropdown > Click More, the Get Data Pop-up will be shown with the options that can be used to retrieve the data. Search for Python script, select it, then click Connect
The Python script Pop-up will be shown, paste the Python script here. Don't forget to have LSEG Workspace application running and logged-in on the same machine for the connection to the Data Platform, then click OK
The Power BI is getting the data with the Python script, selects the set50_df output dataframe (as named in the script), then verifies if the data is imported properly (data type is correctly defined as numeric, String, etc.) click Load to load the data into Power BI (You can click Transform Data in case the data format isn't correct)
If you click on Transform Data, the data format should be as below
First, let's make the pie chart! Click on the blank space in the working space > on the right section, Visualizations, Click on the Pie Chart > On the imported set50_df data and select the fields that you'd like to visualize, here I select ESG Score and TRBC Economic Sector Name. The Power BI is going to put selected fields into the proper Legend and Values, or you can adjust it according to your need. The generated pie chart will be shown in the working space.
Do the same with other visualization types, such as Clustered Column Chart and Table as below.
Here's the final result, including multiple visualizations that we've created. On this page, we can select specific data to see the insight of it in other charts as well. For example, Technology TRBC Economic Sector Name is selected here.
For the second page data, we're retrieving constituents in SET 100 Index data of
- TR.TRBCEconomicSector: TRBC classifies companies wiht increasing granularity by Economic Sector, Business Sector, Industry Group, Industry, and Activity.
- CF_YIELD: Yield.
- TR.NetIncomeBefExtrapctPrdtoPrd: Net Income Before Extra, % Period/Period, FY.
- TR.PE: Price / Earnings To Growth Ratio (Mean Estimate)
- CF_LAST: .The latest trade price or value
import lseg.data as ld
from lseg.data.discovery import Chain
ld.open_session()
set100_df = Chain(name="0#.SET100")
set100_df = ld.get_data('0#.SET100',['TR.TRBCEconomicSector','YIELD','TR.NetIncomeBefExtrapctPrdtoPrd','TR.PE','CF_LAST'])
ld.close_session()
Below is the result of the code execution in Jupyter Notebook.
To get data using Power BI, follow the same step as First page, ESG score data. by getting data using Python script, load them into Power BI's Data. The imported data will be shown, I rename some columns here, then if you're ok with this, click the Close & Apply button on the top-left to import the data into the Power BI workspace.
From this data, repeat the same step as the first page, I use Pie chart, Table, and Histogram charts to visualize the data. Here's the final result with the selection of Financial TRBC Economic Sector Name to see the insight in all related charts.
One thing I'd love to represent is, in Power BI, you can click the Refresh button to refresh the data, Power BI is going to reload the data using the get data script and show the latest data retrieved.
Conclusion
In this article, we explored how to visualize the data retrieved from the LSEG Data Library for Python using Microsoft Power BI which can empower individual traders to visualize and analyze financial data effectively by using the power of Power BI's visualizations including pie charts, clustered column charts, histograms, tables, and others can gain valuable insights that aid in making informed investment decisions. With this knowledge, you can now easily see the trend of both overview and in-depth of financial data and unlock the potential for increased profitability and success in the dynamic world of finance.
We also learn how to launch Power BI Desktop application in the specific Conda environment, which allows us to manage environments between projects easily.
If you have any questions regarding our API usage, feel free to check our Q&A Forum or post the question there to get in touch. Hope you have fun with this article!
- Register or Log in to applaud this article
- Let the author know how much this article helped you