Setting up a Python Development Workstation (MacOs)
Thanks for popping by; please note that this article is still in construction.
Introduction
Ready to enter the world of Python, Visual Studio, and financial analysis? Let’s embark on this journey together. By the end of this guide, you’ll have your finance lab all set for dissecting market trends, optimising portfolios, and much more. Buckle up, let’s set sail! This article requires some knowledge of the terminal, installing softwares
Step 1: Install Your General Tooling
Whilst not mandatory, before looking at Python, code editors and various libraries, it’s extremely useful to check that your MacOs is ready to provide you with the best general setup. Terminal windows, bash script might look a bit obscure at first glance, but take it step by step and look at the video linked below to get more clarity on this. This is a marathon, definitely not a sprint.
1.1 Install Homebrew
Homebrew, affectionately known as brew, is the Swiss Army knife for installing software on macOS. It simplifies the process of managing software on your Mac, making it a breeze to install, uninstall, and update your applications.
To install Homebrew, open Terminal and enter:
1.2 Install iTerm2
iTerm2 is an improvement over macOS’s default terminal, offering features such as split panes, search, and customisation. Install it via brew with:
1.3 Install Oh My Zsh:
Zsh, combined with Oh My Zsh, turns the dull default terminal into a powerful and enjoyable tool, complete with themes, plugins, and a vibrant community.
Install Oh My Zsh with:
Step 2. Setting Up Visual Studio and Miniconda
2.1 Visual Studio
Visual Studio Code (VS Code) is a lightweight but powerful source code editor that supports debugging, embedded Git control, syntax highlighting, and more. Install VS Code via brew:
VS Code is a robust and versatile code editor, while Miniconda, a mini version of Anaconda, allows us to create isolated Python environments and manage packages.
Using Brew, installed above, is a breeze
Alternatively, you can download and install Visual Studio Code from the official website. Follow the prompts to complete the installation process.
2.2 Miniconda
Using Brew
Alternatively, you can download and install Miniconda from the official website. During installation, ensure that you select the option to “Add Miniconda to my PATH environment variable”. This allows you to use conda
commands directly in the VS Code terminal.
Step 3. Setting Up a Python Virtual Environment
3.1 Create the Conda environment
With our tools installed, let’s now create a virtual environment to house our finance lab. We’ll use conda to create a new environment named portfolio-geek
using Python 3.10.
Open VS Code
, then open a terminal and type the following command:
Activate the portfolio-geek
environment by typing:
3.2 Install the key packages for your coding journey
Inside portfolio-geek
, we install several vital Python libraries for our financial analysis journey:
pandas: A flexible and powerful data manipulation library, essential for handling and processing financial data.
matplotlib and seaborn: Two formidable libraries for data visualisation, because finance isn’t just about numbers—it’s about insightful charts too!
yfinance: An effective library for fetching historical stock data from Yahoo Finance.
pyportfolioopt: An advanced library designed to optimise portfolios, calculate risk and returns, and much more.
Install these libraries using the following command:
Step 4. Installing Key Visual Studio Extensions
This step is not mandatory but it will be of tremendous help on a day to day basis. VS Code shines with its extensions. Here are a few that will make your life easier:
Python: Gives you a host of Python-specific features like linting, debugging, code formatting, and more.
Prettier: A code formatter that supports many languages, including Python. Keeps your code clean and professional.
Code Spell Checker: Like a proof-reader, it catches common spelling mistakes in your code.
You can install these extensions by searching for them in the VS Code Extensions view (Ctrl + Shift + X
) and clicking on “Install”.
Step 5 Launching a Jupyter Notebook Inside Visual Studio
With our portfolio-geek
environment and VS Code set up, it’s time to dive into some coding. We’ll be using a Jupyter Notebook, a powerful tool allowing you to interweave code and text into a single document.
Create a new file with a .ipynb
extension. Upon creation, VS Code will prompt you to select a Python interpreter—choose the one corresponding to our portfolio-geek
environment.