Python for Trading: Basic
- Live Trading
- Learning Track
- Prerequisites
- Syllabus
- About author
- Testimonials
- Faqs
Apply Python for Algo Trading
- Work with different data structures such lists, tuples and dictionaries
- Use loops, conditional statements, functions and object oriented programming in the code
- Fetch stock prices from different sources
- Manage data using Python packages such as Pandas, NumPy and Matplotlib
- Paper trade and analyze the strategies and apply in live markets without any installations or downloads

Skills Covered
Data Management
- Importing the data
- Processing the data
- Visualizing the data
Financial Skills
- Interest Rate Calculation
- Compounding
- Time Value of Money
Python
- Loops, Conditional Statements, Functions
- Python Data Types
- NumPy, Pandas
- Matplotlib

learning track 1
This course is a part of the Learning Track: Algorithmic Trading for Beginners
Full Learning Track
These courses are specially curated to help you with end-to-end learning of the subject.
At QuantInsti, our mission is to make algorithmic trading knowledge and technology accessible to everyone. Our vision is to empower individuals and institutions, enabling them to harness cutting-edge technology in financial markets, fostering growth and success. We offer comprehensive learning tracks, free fintech tools, hundreds of engaging webinars, and a vast repository of over 500 insightful blogs designed to equip aspiring traders with essential skills and resources.
For over 14 years, we've actively contributed as speakers and industry experts at academic and professional forums globally, helping shape the future of algorithmic trading. This free course exemplifies our commitment to accessibility and empowerment, helping you take your first step into the ever-evolving world of algorithmic trading. We appreciate you joining us on this exciting journey. Happy Learning!
Course Features
- Community
Faculty Support on Community
- Interactive Coding Exercises
Interactive Coding Practice
- Trade & Learn Together
Trade and Learn Together
- Get Certified
Get Certified
Prerequisites for Algo Trading with Python
There are no prerequisites to this course. You can do this course if you have never coded or haven't seen a console window. The learning curve is steep since you are learning a programming language and its usage in financial markets. It is recommended that you show commitment towards learning to gain most out of the course.
Python for Algo Trading
- WelcomeThis section introduces the topic and explains the importance of Python.Introduction2m 40sIf Algo, Then How Does Python Contribute?6m 27sQuantra Features and Guidance3m 48sFAQ2m
- Hello PythonThis familiarises you with the basic components of Python like variables references, operators, modules, packages, and libraries.Python Environment2m 34sVariables, Object References and Operators3m 36sWhen X = Y, Then What?2mWhen X != Y, Then What?2mHow to Use Jupyter Notebook?2m 5sMy First Python Code10mPractice Print Statement5mLearn Modules, Packages and Libraries3m 11sFile With .py Extension2mImport Python Modules10mModules, Packages & Libraries2mImporting Module5mInstall Packages in Python10mError if the Package is Not Installed2mSyntax to Install a Package2mWhich Version of the Package is Installed?2mSyntax to Install a Version?2mTest on Python Modules16m
- ExpressionsIn this section, you will learn about an important concept of 'Time Value of Money', and the use of expressions in Python.Introduction to Time Value of Money1m 51sCalculate the Future Value2mCalculate the Present Value2mLearn Compounding in Time Value of Money2m 6sCompounding With Monthly Coupons2mCompounding With Quarterly Coupons2mPDF: TVM Applications (Optional Read)10mUse of Expressions10mPrint Future Value5mPrint Calculating Present Value5m
- Python Data StructuresThis section focuses on different Python data structures like lists, dictionaries, stacks, queues, graphs, trees, tuples and sets.What Are Lists?4m 6sSyntax for Lists2mProperties of List2mLearn to Create Lists10mCreate Lists on Your Own5mPrint pop() From Lists5mWhat Are Stacks, Queues, Graphs & Trees10mStacks & Queues2mWhat Are Dictionaries?1m 55sAccess Dictionaries2mKeys in Dictionaries2mLearn to Create and Print Dictionaries10mCreate Dictionaries5mPractice Printing Keys5mWhat Are Tuples and Sets?2m 25sWhich is Valid for Data Structures?2mTuples2mLearn to Create Tuples and Sets10mConstruct Tuple5mPrint Set Union function5mTest on Expressions and Python Data Structures14m
- Importing Data and Data VisualisationThis section demonstrates how to import and visualise financial data using Python.What is Time Series Data?3m 19sTime Series: A Collection of Observations2mCharacteristics of Longitudinal & Panel Data2mHow to Import Time series data?3m 6sFind: True/False for DataFrame2mCorrect Syntax for a DataFrame2mImport Data from Web Sources10mDownload of Historical Data5mRead Data from CSV Files10mPractice read_csv()5mHow to Plot Market Data?3m 48sGiving Title to the Graph2mFunction to Visualise the Graph2mData Visualization10mCreate 2D Plot5mPlot the Grid5m3D Plotting10mWhat are Candlesticks?4m 14sAssessment on Green Candlesticks2mAdvantage of Candlesticks2mCandlesticks (Optional Read)10mTest on Importing Data and Data Visualisation14m
- FunctionsIn this section, you will learn what Python functions are, how to define functions, what Lambda functions are and how to use them.What Are Functions?4m 30sAssessment: What Are Functions?2mSyntax to Define a Function2mFunctions10mPrint Using Function5mCall the Function5mLambda10mCreate Sum of Variables with Lamba5mMultiplication of Variables With Lambda5m
- NumpyThis section shows how you can use the NumPy library to manipulate arrays by slicing, indexing, vectorization and broadcasting.What Are NumPy Arrays?3m 51sAssessment on NumPy2mPut Syntax for Array Constructor2mIntroduction to Arrays10mUse Numpy.arange ()2mCreate Array With Linspace5mCreate 2D Array5mIndexing & Slicing Arrays10mIndexing 1D Arrays2mIndexing 2D Arrays2mSlicing 1D Arrays2mSlicing 2D Arrays2mPractice Indexing5mPractice Slicing5mVectorization & Broadcasting in Arrays10mScalar Vectorization2mArray Comparison2mPractice Using == Operator5mPractice New Axis5m
- PandasThis section illustrates how to use the Pandas library for the manipulation of DataFrames.Pandas and Data Manipulation4m 26sDropping/Deleting Columns2mDataframe Indexing2mIntroduction to Series10mAssessment on Series.apply()2mPractice Creating Series5mApply Method to a Series5mDataFrame & Basic Functionality10mPrinting Columns2mPractice Using DataFrame.head()5mCreate DataFrame5mDescriptive Statistical Function10mDataframe Manipulation2mPrint Using mean()5mPractice corr()5mIndexing & Missing Values10mloc()2miloc()5mGrouping & Reshaping10mGroupby Function5m
- Conditional Statements and LoopsIn this section, you will learn how to use conditional statements and loops in Python.What Are Conditional Statements and Loops?4m 18sAssessment on 'if' Conditional Statement2mWhat Do You Know About 'for loop'?2mIntroduction to Conditional Statements10mIf Conditional Statement5mIntroduction to Loops10mFor Loop5mGetting Out of 'for Loop'5mTest on Libraries, Functions, and Loops16m
Buy and Hold Strategy
In this section, you will learn to create a buy and hold strategy in Python.Buy and Hold Strategy10mFrequently Asked Questions10m- Live Trading on BlueshiftThis section will walk you through the steps involved in taking your trading strategy live. You will learn about backtesting and live trading platform, Blueshift. You will learn about code structure, various functions used to create a strategy and finally, paper or live trade on Blueshift.Uninterrupted Learning Journey with Quantra2mSection Overview2m 19sLive Trading Overview2m 41sVectorised vs Event Driven2mProcess in Live Trading2mReal-Time Data Source2mBlueshift Code Structure2m 57sImportant API Methods10mSchedule Strategy Logic2mFetch Historical Data2mPlace Orders2mBacktest and Live Trade on Blueshift4m 5sAdditional Reading10mBlueshift Data FAQs10m
- Live Trading TemplateBlueshift Live Trading TemplatePaper/Live Trading Buy and Hold Strategy10mSharpe Ratio5mStrategy Returns5mMaximum Drawdown5mEnding Capital5mNext Step5mPaper Trading5mInvestment Style5mRebalancing Function5mFAQs for Live Trading on Blueshift10m
- Run Codes Locally on Your MachineLearn to install the Python environment in your local machine.Python Installation Overview1m 59sFlow Diagram10mInstall Anaconda on Windows10mInstall Anaconda on Mac10mKnow your Current Environment2mTroubleshooting Anaconda Installation Problems10mCreating a Python Environment10mChanging Environments2mQuantra Environment2mTroubleshooting Tips For Setting Up Environment10mHow to Run Files in Downloadable Section?10mTroubleshooting For Running Files in Downloadable Section10m
- Course SummaryCourse Summary and Next Steps10mPython Code and Data2m
Registered Successfully!
You will receive webinar joining details on your registered email
Would you like to start learning immediately?
about author


Why quantra®?
- More in Less Time
Gain more in less time
- Expert Faculty
Get taught by practitioners
- Self-paced
Learn at your own pace
- Data & Strategy Models
Get data & strategy models to practice on your own
Faqs
- When will I have access to the course content, including videos and strategies?
You will gain access to the entire course content including videos and strategies, as soon as you complete the payment and successfully enroll in the course.
- Will I get a certificate at the completion of the course?
Yes, you will be awarded with a certification from QuantInsti after successfully completing the online learning units.
- Are there any webinars, live or classroom sessions available in the course?
No, there are no live or classroom sessions in the course. You can ask your queries on community and get responses from fellow learners and faculty members.
- Is there any support available after I purchase the course?
Yes, you can ask your queries related to the course on the community: https://quantra.quantinsti.com/community
- What are the system requirements to do this course?
Fast-speed internet connection and a browser application are required for this course. For best experience, use Chrome.
- What is the admission criteria?
There is no admission criterion. You are recommended to go through the prerequisites section and be aware of skill sets gained and required to learn most from the course.
- Is there a refund available?
We respect your time, and hence, we offer concise but effective short-term courses created under professional guidance. We try to offer the most value within the shortest time. There are a few courses on Quantra which are free of cost. Please check the price of the course before enrolling in it. Once a purchase is made, we offer complete course content. For paid courses, we follow a 'no refund' policy.
- Is the course downloadable?
Some of the course material is downloadable such as Python notebooks with strategy codes. We also guide you how to use these codes on your own system to practice further.
- Can the python strategies provided in the course be immediately used for trading?
We focus on teaching these quantitative and machine learning techniques and how learners can use them for developing their own strategies. You may or may not be able to directly use them in your own system. Please do note that we are not advising or offering any trading/investment services. The strategies are used for learning & understanding purposes and we don't take any responsibility for the performance or any profit or losses that using these techniques results in.
- I want to develop my own algorithmic trading strategy. Can I use a Quantra course notebook for the same?
Quantra environment is a zero-installation solution to get beginners to start off with coding in Python. While learning you won't have to download or install anything! However, if you wish to later implement the learning on your system, you can definitely do that. All the notebooks in the Quantra portal are available for download at the end of each course and they can be run in the local system just the same as they run in the portal. The user can modify/tweak/rework all such code files as per his need. We encourage you to implement different concepts learnt from different learning tracks into your trading strategy to make it more suited to the real-world scenario.
- If I plug in the Quantra code to my trading system, am I sure to make money?
No. We provide you guidance on how to create strategy using different techniques and indicators, but no strategy is plug and play. A lot of effort is required to backtest any strategy, after which we fine-tune the strategy parameters and see the performance on paper trading before we finally implement the live execution of trades.
- What does "lifetime access" mean?
Lifetime access means that once you enroll in the course, you will have unlimited access to all course materials, including videos, resources, readings, and other learning materials for as long as the course remains available online. There are no time limits or expiration dates on your access, allowing you to learn at your own pace and revisit the content whenever you need it, even after you've completed the course. It's important to note that "lifetime" refers to the lifetime of the course itself—if the platform or course is discontinued for any reason, we will inform you in advance. This will allow you enough time to download or access any course materials you need for future use.
- What are data structures in Python?
Data structures help with storage of data values in an organised manner, which helps the user to access the value with ease. This method also increases the efficiency of the work. Hence, the relationship between the different values in data, as well as the operations, is easily understood. Moreover, there are different kinds of data structures for making it easier for any programmer to sort out problems with different types of data values. All in all, the data structures save an immense amount of time and effort by making particular types of values accessible and thus, solvable.
- How to import data into Python?
To understand how to import the data from Python, you need to know where this data lies first. To tell you in brief, there are packages in Python and each package is a collection of Modules. Each package consists of __init.py__ file.
The main concept is, hence, a module which is a “.py” file from where the data is imported. Now, a module implies a file that consists of Python code. For example, there can be a module known as welcome.py, of which the module name is welcome. This can be imported by using:
import welcome
Modules can be functions, variables and classes and each module can be reached by using the “import” statement. This statement works by executing the code of the module to make use of the code in the input, which will bring an Output.
Conversely, if you require only a few objects from the module, then:
from scipy import mean
mean ([1,,3,)]
The Output is 3.0
Here, scipy is the package and the mean object is taken out. - How to use Python data visualization charts?
Python data visualization charts are used for plotting the financial markets data so as to achieve better visualization, and thus, better understanding. In Python data visualization, you can make use of:
1. Simple dimensional graphs such as Histogram, Scattered plot, and Line chart using matplotlib.
2. 3-Dimensional plotting using the ‘pyplot’ module of Matplotlib package. This gives a 3-dimensional figure using 3 datasets.
The Python code for such representation goes as follows:
import matplotlib.pyplot as plt
%matplotlib inline
plt.plot(infy_close)
plt.show ()
3. Candlesticks - They are arguably the most beautiful and widely used representation of the data since they provide all the aspects of stock prices. A typical candlestick gives us information about 4 things - the opening & closing prices of a day and also the day's High and Low. For example, in plotting, you plot only the closing price against time as the intraday volatility given by the high-low parameters (of the stock prices) are lost.
The Python code for Candlesticks is as follows:
# Import pandas
import pandas as pd
# Read data
df = pd.read_csv('candlestick_data.csv', index_col=0)
df.head() - What is a condition in Python?
In Python, Condition is similar to the conditions we face in life. We make use of 'if' and 'else' in life in conditions like, for instance, rain where we make the statement- 'if it rains, then I will carry an umbrella, else I will not. Similarly, in Python, there are conditional statements which help us to make decisions in programming based on conditions. Hence, we can check if a particular condition is met by the variable, or not. In this, the program responds separately for the two opposing conditions. These statements are known as ‘if’ conditional statements.
An example of 'if':
if (stock_price_ABC < 300):
print ('We will buy 500 shares of ABC')
elif (stock_price_ABC == 300):
print ('We will buy 00 shares of ABC')
elif (stock_price_ABC > 300):
print ('We will buy 150 shares of ABC')
An example of 'else': stock_price_ABC = 00
if (stock_price_ABC > 50):
print ('We will sell the stock and book the profit')
else:
print ('We will keep buying the stock') - How to loop in Python?
A loop statement allows the user to execute a statement or group of statements multiple times. Here, 'for' loop is used to help us execute a statement or a group of statements multiple numbers of times. In Python code, the following coding is done:
Close_Price_ABC = [300,305,87,98,335,300,97,300,95,310] # Our sequence
for i in Close_Price_ABC:
if i < 300:
print ('We Buy')
if i == 300:
print ('No new positions')
if i > 300:
print ('We Sell')
print ('We are now out of the loop')
Above, the entire list of Close_Price_ABC is stored in variable i.
Now, 'if < 300:' will help the user print 'We buy' statement for those variables which are less than 300. Further, whenever variable i will be equal to 300, it will give the Output 'No new positions' and thus, the same statement will be repeated as long as the variable remains equal to 300. Going ahead, whenever the variable i will be more than 300, 'if > 300:' will give the Output 'We Sell'. This also will be repeated for every variable that is more than 300. - What is NumPy in Python?
NumPy is the storage space (library) for the Python programming language. It supports high-level mathematical functions and thus, aids with multi-dimensional arrays and matrices (concepts of mathematics). Thus, it provides help to do computer programming with mathematical computing.
- What is Pandas in Python?
Pandas is a computer programming essential, which stores a collection of resources useful for the development of various software. This storage space is known as the software library. Pandas is, basically itself, a software that helps in machine learning.
- Why is Algorithmic Trading in Python recommended?
Python is used for algorithmic trading as it is relatively easier to understand and use due to its simple and intuitive syntax. It also has a large number of libraries which help you focus on performing a task faster without worrying about writing each and every line of code. Python is also open-source, making it cost-effective. Another advantage of Python is the large and active community of quant enthusiasts which makes it easy to find solutions.