Algorithm Trading Session 1: Basics of Python and Jupyter

We have all heard about Python. It is a programming language used in algorithmic trading. Let me introduce you to Jupyter. Refer –

Previously it was known as iPython where You can write step by step code and it was executed in step by step method giving you a broad perspective on what to change or modify and more importantly, where is the mistake.

Later it spun off as Project Jupyter which now supports execution environments for few dozen languages.

Step 1: Installing Python

Head here –

Then browse around to download the latest version of Python. Note although my image currently shows How I got it, Some of you will be reading this after a couple of years too. Just browse around, Download, Install it.

Installing Python

Also, You can take the help of Google if You’re slight more novice, Just Youtube install python windows

While installing, You must make sure that Python is added to the Environment Path. For that, You need to click “tick” in the first dialog. (It is not ticked by default.) If you have already installed it, don’t worry, just reinstall it and this time make sure its “ticked”.

Step 2: Installing PIP

Now, PIP allows you to install pre-written, well packaged codes written by other users. Like Krishna Velu wrote the code for Aliceblue’s API Wrapper which you can see here –

So, PIP is a package management system.

Q. Then, How to use (install) a project like without PIP?

Most authors follow the same protocols of Python Package Index (PyPI – You can read more here while developing python projects. So, to install it manually, download the code.

package management system

Now using the command prompt of windows,

  1. Goto the place where it is downloaded and extracted. Type python
  2. If PIP was installed, the headache is less. You need to open the command prompt and type pip install alice_blue to install it.
  3. To uninstall it type pip uninstall alice_blue

Now, How to install PIP in Windows? Follow this article –

Official Instruction – (It is written in more “lawyerish” language)

Step 3: Installing Jupyter

Now that you have Python and PIP installed, All you need to do is open command prompt.

Then type pip install notebook

You have installed Jupyter Notebook! To run the notebook, run the following command at command prompt.

Type jupyter notebook
It will open your browser and show you something like this –

jupyter notebook
Click New>Python 3 Now Install my library NSEPython ( which I had coded while having the last session here, It will allow you to scrap data from NSE. Instead of doing pip install nsepython from CMD, You can do that directly from here.

Type pip install nsepython and then click on the Run button as marked here.

As it was already installed in my system, it is writing “Already exists” in the output.

Now head here –

I have practiced the first command.

from nsepython import *

And I clicked on Run.

Note 1: Make sure you have latest version of nsepython if not then

  1. Open CMD, Type pip uninstall nsepython . It will ask for confirmation once, Press Y. It will uninstall the current package.
  2. Then type pip install nsepython. It will install the latest package which I just patched.

Note 2: The DEBUG is harmless. It basically shows what is being fetched. You can remove it by doing –

import logging
logger = logging.getLogger()