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 https://t.co/EZt0agsdlV

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: https://t.co/MqMSDBaQri

Create a new Notebook at https://t.co/EZt0agsdlV 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 :
https://t.co/wuremRtH1S

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 https://t.co/EsjbNCrbvB . The thread is inspired by his work https://t.co/RhuoCTJ7T9

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: https://t.co/pciDOJXyVI

Note:
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