Just Enough Python for Tradevestors
Learn Python for Efficient Compounding
I am a data techie, I use python to quantify data and automate processes in my professional life. When I started my tradevesting journey, I started applying these skills to stock market as well. In this article, I am going to share ‘just enough python’ you need to learn, in order to exploit its features like me.
Python is simple and efficient language to quantify and automate tradevesting methodology. Let's first learn basics of Python before moving on to practically utilize it for efficient compounding.
Learning Python using Jupyter Notebook can be a highly effective way to get started for a non-techie person to programming. The interactive nature of Jupyter Notebooks allows you to see immediate results, which can be very encouraging. Here’s a step-by-step guide to help you learn Python using Jupyter Notebooks:
Step 1: Introduction to Jupyter Notebook
Objective: Understand what Jupyter Notebook is and how to use it.
1. What is Jupyter Notebook:
- Jupyter Notebook is an interactive tool for writing and running code.
- Features: easy to use, immediate feedback, great for documentation.
2. Installing Jupyter Notebook:
- Install Anaconda, which includes Jupyter Notebook, from the official website <anaconda.com>. (refer YouTube Video)
- Launch Jupyter Notebook from the Anaconda Navigator.
Step 2: Basic Navigation and Usage
Objective: Learn how to create, save, and navigate a notebook.
1. Creating a New Notebook:
- Create a new notebook by clicking “New” and selecting “Python 3”.
2. Notebook Interface:
- Notice the notebook interface: cells, toolbar, and menus.
- Learn how to save notebooks.
3. Running Cells:
- Notice the difference between code cells and markdown cells.
- Learn how to run a cell by pressing
Shift + Enter
.
Step 3: Basic Python Syntax and Operations
Objective: Learn basic Python syntax and simple operations.
1. Hello, World!:
- Start with a simple program.
print("Hello, World!")
2. Basic Arithmetic:
- Try basic arithmetic operations.
2 + 3
7 - 4
3 * 4
8 / 2
Step 4: Variables and Data Types
Objective: Understand how to use variables and different data types.
1. Variables:
- Learn what variables are and how to create them.
x = 5
y = "Hello"
2. Data Types:
- Try basic data types: integers, floats, strings, and booleans.
a = 10 # Integer
b = 3.14 # Float
c = "Python" # String
d = True # Boolean
Step 5: Basic Input and Output
Objective: Learn how to take input from the user and display output.
1. Input Function:
- Learn how to use
input()
to get user input.
name = input("Enter your name: ")
print("Hello, " + name)
Step 6: Control Flow Statements
Objective: Understand and use if-else statements and loops.
1. If-Else Statements:
- Try conditional statements with examples.
age = int(input("Enter your age: "))
if age >= 18:
print("You are an adult.")
else:
print("You are a minor.")
2. Loops:
- Learn
for
andwhile
loops with simple examples.
for i in range(5):
print(i)
count = 0
while count < 5:
print(count)
count += 1
Step 7: Functions
Objective: Learn how to create and use functions.
- Defining Functions:
- Understand what functions are and how to define them.
def greet(name):
print("Hello, " + name)
greet("Alice")
Step 8: Lists and Dictionaries
Objective: Understand lists and dictionaries and how to use them.
1. Lists:
- Try lists and basic operations.
fruits = ["apple", "banana", "cherry"]
print(fruits[0])
fruits.append("orange")
print(fruits)
2. Dictionaries:
- Learn dictionaries and basic operations.
person = {"name": "John", "age": 30}
print(person["name"])
person["age"] = 31
print(person)
Step 9: Basic File Operations
Objective: Learn how to read from and write to files.
1. Reading a File:
- Try how to open and read a file.
with open("example.txt", "r") as file:
content = file.read()
print(content)
2. Writing to a File:
- Learn how to write to a file.
with open("example.txt", "w") as file:
file.write("Hello, World!")
Step 10: Exception Handling
Objective: Learn how to handle errors gracefully using try-except blocks.
1. Basic Exception Handling:
- Understand the concept of exceptions and how to handle them.
try:
numerator = float(input("Enter the numerator: "))
denominator = float(input("Enter the denominator: "))
result = numerator / denominator
print("The result is:", result)
except ZeroDivisionError:
print("Error: Cannot divide by zero!")
except ValueError:
print("Error: Invalid input. Please enter numbers only.")
Next Step: Simple Projects
Objective: Apply learned concepts in small projects to build confidence.
1. Simple Calculator:
- Create a simple calculator that can perform basic arithmetic operations.
2. To-Do List:
- Build a simple to-do list application that can add, remove, and display tasks.
By following above steps, you’ve gained a solid foundation in Python programming using Jupyter Notebook. You’ve learned how to set up your environment, write and run Python code, understand basic concepts like variables, data types, and loops, and even handle exceptions gracefully.
With these skills, you are well on your way to becoming proficient in Python. Keep practicing and exploring more advanced topics to continue your learning journey. Remember, coding is a skill best learned by doing, so keep experimenting with new code and building your projects.
If you loved this story, please feel free to check my other articles on this topic here: https://ankit-rathi.github.io/tradevesting/
Ankit Rathi is a data techie and weekend tradevestor. His interest lies primarily in building end-to-end data applications/products and making money in stock market using Tradevesting methodology.