Indian Quant Profile picture
Dec 13, 2021 21 tweets 7 min read Read on X
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 colab.research.google.com

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 colab.research.google.com 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. Image
(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: Image
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. Image
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. Image
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. Image
Let's add one more column, 200MAdist, which is equal to distance b/w 'close' and 200 moving average. Image
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 : ImageImage
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 :
colab.research.google.com/drive/10TtpBt8…

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 stocksavvy.substack.com . The thread is inspired by his work stocksavvy.substack.com/about?utm_sour…

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Indian Quant

Indian Quant Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @indian_quant

Feb 4, 2023
I wondered how I could get the pnl statement from my Finvasia account and plot those nice equity and drawdown curves without downloading the CSV files. So, I thought writing a tutorial on automating this would help others too.
In this, we will use Selenium and requests and plot these curves.
Step 1: Import libraries and create a driver as shown here; you will need to install these libraries first. Use these links
1. pypi.org/project/seleni…
2. pypi.org/project/webdri…
Step 2: Store relevant information
Read 12 tweets
Jun 27, 2022
There is always the uncertainty that your 8-10 years tested strategy won't work next year. In terms of data, what you had observed was the data points syncing in place to give you an equity curve.
If you want to see what may happen if you weren't so lucky, just change the...
... sequence of data points and generate new equity curve. If you sample these data points in a different way you will get different equity curve, different drawdown. A common way to achieve this is to use 'Monte Carlo Simulation.'

Note: this is very crude definition of
... monte carlo method. If time permits I will write a detailed article on it' use as numerical methods and it's application in trading.
Read 4 tweets
Apr 27, 2022
Nano Course On Python For Trading
==========================
Module 5-A

In these posts, I will attempt to teach you how to host a trading strategy on the AWS cloud, use Zerodha Trading API, and run a basic algorithm. This last module is subdivided into two modules 5-A & 5-B
For a new quant trader, AWS becomes a daunting task to understand. But it is worth your time to understand and get comfortable with it. The benefit of using AWS is that it is charged per hour - as per your usage. You can get started with a free tier at zero cost.
Prerequisite: Understand what is cloud here :


If you get benefitted from such articles, you can donate to me using the Tip Jar on my Twitter Profile @indian_quant . This charity will feed me fuel to keep posting stuff on Trading and Programming. Image
Read 15 tweets
Apr 26, 2022
phoenix at 191% gross since March 1, 2021. While all my other systems struggled in the market, this system outperformed. Image
Mind the 4-5 months of medium duration drawdown 😬. If I was unlucky, it could have extended for 300+days as the simulation tells me. High performance strategy can go in longer drawdown period Image
how variable the p&l of a high-performing trading strategy really is by robot wealth robotwealth.com/what-pl-swings…
Read 5 tweets
Feb 20, 2022
Nano Course On Python For Trading
==========================
Module 3-B (Bonus)

In this Bonus Module, I will attempt to teach you how to write an algorithm to create a Stock Screener based on @markminervini 's Trend Template from his book Trade Like A Stock Market Wizard.

+
Some of the readers asked about how to create a stock screener. So, I thought before jumping to the cloud and deploying an algorithm on the cloud, I should address this. Whatever algorithm we develop in this module, we will deploy it on the cloud in Module number 4.

+
Pre-requisites:

• Read Module 2, so that you can download the historical data. A small assignment for you - write code to automate EOD data download and save it in the folder. We need to have the latest data for the screener. Hint: set end_date = date.today()

+
Read 18 tweets
Feb 19, 2022
Laymen Tech - #1
=============

What is a cloud?

If you are reading my post, chances are you live on rent in an apartment. You might also have a gym membership and not own any fitness equipment at your home. But, why do you rent them instead of buying?

+
Possible reasons:

• You can’t afford to buy land/property in Metro cities (Mumbai)
• You have a job and can switch places every year and go to another city
• You want to stay away from maintenance cost of your home/fitness equipments

+
Cloud can also be thought in the same way. You rent computer infrastructure rather than owning them.

In Laymen Tech terms, cloud companies lease out their computer servers to companies to run their software on.

Companies like AWS and Azure buy these gigantic computers and..

+
Read 8 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(