knowledge_base:programming:stockcharting

Stock Charting

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

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.

Read this online resource:

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.

Run the following simple code (from Credits) to demonstrate a simple stock charting.

Notes: You will need to install plotly and pandas Python packages using pip. Reference to 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()

Watch this Official Video to learn how to use Git in VS Code.

Note: Create a .gitignore file to exclude Python virtual environment folder.

Try out the following simple example - getting Amazon stock price data by reading 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)

Combining Step 2 and Step 3 to plot Amazon stock price and volume over the past two years.

  • 50 day moving average
  • 200 day moving average
  • Bollinger bands
  • Last modified: 2023/12/18 23:05
  • by Normal User