Nano Course On Python For Trading
Module 1

Python makes it very easy to analyze and visualize time series data when you’re a beginner. It's easier when you don't have to install python on your PC (that's why it's a nano course, you'll learn python...

... on the go). You will not be required to install python in your PC but you will be using an amazing python editor, Google Colab Visit

This course is for anyone out there who is confused, frustrated, and just wants this python/finance thing to work!
In Module 1 of this Nano course, we will learn about :

# Using Google Colab
# Importing libraries
# Making a Random Time Series of Black Field Research Stock (fictional)
# Using Google Colab

Intro link is here on YT:

Create a new Notebook at and name it AnythingOfYourChoice.ipynb

You got your notebook ready and now the game is on!
You can add code in these cells and add as many cells as you want
# Importing Libraries

Imports are pretty standard, with a few exceptions.
For the most part, you can import your libraries by running the import.
Type this in the first cell you see. You need not worry about what each of these does, we will understand it later.
(Note: I have posted a link to my own notebook used for this course at the end of the thread. You can use it for reference)

Once you have imported the packages, run the code by clicking on the play button ▶️.
# Making a Random Time Series of Black Field Research Stock (fictional)

Let's add some more code and create a fictional stock price chart of a multinational investment management firm Black Field Research (aka @BlackFieldRes ) and use it for statistics and graphs.

Exact Code:
In the next thread, I’ll show you how to import data from URLs, but that’s not the focus of this nano course.
First, make the index of our data using "date_range." I picked today’s date, 2015/01/01, as the start date, used a daily frequency, and created 2500 rows.
Then I'll make an empty DataFrame that uses the date range we created as its index. Typically, I call this variable df, but you can call it anything you want.
Let's create fake data for our stock's closing value, let's call it "Close." To make a random series, I am using a random() function from NumPy. The below steps might look complicated to you but feel free to skip the next 2 threads and just add the code in your notebook.
Steps to generate random stock price time series.
1. Idea is to will the data frame with normal redistribute random numbers for our close price
2. Its mean is 0.002 and the standard deviation is 0.02. Total 2500 entries have been made.
3. Call above array as N, Replace N by..
.. e^N .
4. Take the first row as 1, which is our stock price on day 1.

5. Finally, take the cumulative product of the columns.

It's fine if you didn't understand this. We will come on it in later posts. Let's see the output in the next post
Its output will look like this.
Next, we will calculate Moving Average. A stock can be volatile, but it's moving average is smoother and gives us an idea of the overall trend. Let's calculate 200 day moving average.
Let's add one more column, 200MAdist, which is equal to distance b/w 'close' and 200 moving average.
In order to plot multiple graphs to visualize what we did till now, we will use add_subplot() function.

Add this code and the output will look like :
Till now, we have learned about how to use google colab, generate fake data for our stock using python, and we have learned how to calculate moving averages and plot multiple plots together.
In Module 2 of this nano course, we will learn :

# Visualing Logical conditions as signals
# Simulating a trading strategy and considering slippages

I got you started with python. Meanwhile, learn about python and the terms we have used here. You can comment below with doubts.
Link to my colab notebook :

You can make a copy of it and play around with it.

Until next time.
If you have read it till now, follow @M1tchRosenthal and subscribe to his amazing blog . The thread is inspired by his work

More from Python

Nano Course On Python For Trading
Module 4

In this post, I will attempt to teach you how to write a trading strategy in Equity Segment that runs on your PC and create a Telegram bot that sends you buy/sell signals with Stop Loss.

Prerequisite: If you hadn't gone through the earlier modules, I strongly recommend you go through them all. Module 2:

If you liked my content, you can donate, tip and support me on this link (any amount you prefer)

We are going to implement below strategy:

Rules: There should be three candles -> high of candle 1 > high of candle 2 > high of candle 3 and low of candle 1 < low of candle 2 < low of candle 3, where candle 3 is T-1 day, candle 2 is T-2 day and candle 1 is of T-3 Day, T = today.

If on today(day=T), the stock crosses yesterday high(candle 3), then send a buy signal to your telegram handle with candle 3 low as SL.

Before we get started with code, let's create a telegram bot using BotFather.

Step 1: Search BotFather in the telegram.
Step 2: type /newbot and then give the name to your bot. Refer to the second image as an example

You May Also Like

कुंडली में 12 भाव होते हैं। कैसे ज्योतिष द्वारा रोग के आंकलन करते समय कुंडली के विभिन्न भावों से गणना करते हैं आज इस पर चर्चा करेंगे।
कुण्डली को कालपुरुष की संज्ञा देकर इसमें शरीर के अंगों को स्थापित कर उनसे रोग, रोगेश, रोग को बढ़ाने घटाने वाले ग्रह

रोग की स्थिति में उत्प्रेरक का कार्य करने वाले ग्रह, आयुर्वेदिक/ऐलोपैथी/होमियोपैथी में से कौन कारगर होगा इसका आँकलन, रक्त विकार, रक्त और आपरेशन की स्थिति, कौन सा आंतरिक या बाहरी अंग प्रभावित होगा इत्यादि गणना करने में कुंडली का प्रयोग किया जाता है।

मेडिकल ज्योतिष में आज के समय में Dr. K. S. Charak का नाम निर्विवाद रूप से प्रथम स्थान रखता है। उनकी लिखी कई पुस्तकें आज इस क्षेत्र में नए ज्योतिषों का मार्गदर्शन कर रही हैं।
प्रथम भाव -
इस भाव से हम व्यक्ति की रोगप्रतिरोधक क्षमता, सिर, मष्तिस्क का विचार करते हैं।

द्वितीय भाव-
दाहिना नेत्र, मुख, वाणी, नाक, गर्दन व गले के ऊपरी भाग का विचार होता है।
तृतीय भाव-
अस्थि, गला,कान, हाथ, कंधे व छाती के आंतरिक अंगों का शुरुआती भाग इत्यादि।

चतुर्थ भाव- छाती व इसके आंतरिक अंग, जातक की मानसिक स्थिति/प्रकृति, स्तन आदि की गणना की जाती है

पंचम भाव-
जातक की बुद्धि व उसकी तीव्रता,पीठ, पसलियां,पेट, हृदय की स्थिति आंकलन में प्रयोग होता है।

षष्ठ भाव-
रोग भाव कहा जाता है। कुंडली मे इसके तत्कालिक भाव स्वामी, कालपुरुष कुंडली के स्वामी, दृष्टि संबंध, रोगेश की स्थिति, रोगेश के नक्षत्र औऱ रोगेश व भाव की डिग्री इत्यादि।