====== Stock Charting ====== ===== Step 1. Install Python, VS Code, Setup Python Virtual Environment, and Run an Example ===== ==== Install Python ==== The easiest way (and with best shell integration) to install Python is to get it from Microsoft Store. The latest version is Python 3.12 ==== Install VS Code ==== VS Code (or Visual Studio Code) is also available in Microsoft Store. VS Code is one of the best IDEs for many programming languages. It manage language specific intelligences via extensions. Please install the following two extensions for better Python programming experience: * Python - A Visual Studio Code extension with rich support for the Python language (for all actively supported versions of the language: >=3.7), including features such as IntelliSense (Pylance), linting, debugging, code navigation, code formatting, refactoring, variable explorer, test explorer, and more! * Pylance - Fast, feature-rich language support for Python. Pylance is an extension that works alongside Python in Visual Studio Code to provide performant language support. If not installed, VS Code will prompt you to install these extensions when you start writing your first python code. ==== Setup Python Virtual Environment ==== Read this online resource: * https://realpython.com/python-virtual-environments-a-primer/ for answers to these questions: * How to use Python virtual environment * Why do you need virtual environment * What is Python virtual environment * How does it work * How to manage virtual environment You don't need to read all at once. ==== A Simple Example ==== Run the following simple code (from [[https://www.analyticsvidhya.com/blog/2021/10/interactive-plots-in-python-with-plotly-a-complete-guide/#Line_Plots_Using_Plotly|Credits]]) to demonstrate a simple stock charting. Notes: You will need to install plotly and pandas Python packages using pip. Reference to [[https://datatofish.com/install-package-python-using-pip|this]] if you don't know how. import plotly.express as px df = px.data.stocks() fig = px.line(df, x='date', y=["MSFT","GOOG",'FB',"AMZN"]) fig.show() ===== Step 2. Learning to Use Git ===== Watch this [[https://youtu.be/i_23KUAEtUM?si=iH7UxpvWzFsBxcgs|Official Video]] to learn how to use Git in VS Code. Note: Create a ''.gitignore'' file to exclude Python virtual environment folder. ===== Step 3. Data Extraction from Yahoo Finance ===== Try out the following simple example - getting Amazon stock price data by reading [[https://www.qmr.ai/yfinance-library-the-definitive-guide/|this resource]]. # IMPORT THE LIBRARY import yfinance as yf from datetime import datetime # CREATE TICKER INSTANCE FOR AMAZON amzn = yf.Ticker("AMZN") # GET TODAYS DATE AND CONVERT IT TO A STRING WITH YYYY-MM-DD FORMAT (YFINANCE EXPECTS THAT FORMAT) end_date = datetime.now().strftime('%Y-%m-%d') amzn_hist = amzn.history(start='2022-01-01',end=end_date) print(amzn_hist) ===== Step 4. Plot Single Stock Chart ===== Combining Step 2 and Step 3 to plot Amazon stock price and volume over the past two years. ===== Step 5. More Indicators, Plot Layout ===== * 50 day moving average * 200 day moving average * Bollinger bands ===== Step 6. UI for Taking Multiple Stock Symbols ===== ===== Step 7. Putting All Together =====