Visualization of stock prices using manimCE.
Project description
This repository contains code to visualize stock market prices with Manim Community Edition (manimCE).
Download Data ⬇️
manim-stock-visualization provides methods to easily download and preprocess stock data by using yfinance.
Below is an example script to download and preprocess stock data for Apple, NVIDIA and Tesla:
"""Example of downloading the stockprices of Apple, NVIDIA and Tesla."""
from manim_stock.util import download_stock_data, preprocess_stock_data
# Download stock data
df = download_stock_data(
tickers=["AAPL", "NVDA", "TSLA"],
start="2015-01-01",
end="2025-01-01",
)
# Preprocess stock data
df = preprocess_stock_data(df, column="High")
# (Optional:) Convert stock price to portfolio value given an initial cashflow
df = preprocess_portfolio_value(df, init_cash=100)
# Safe stock data as CSV file
df.to_csv("stock_data.csv", index=False)
Data Format 📝
manim-stock-visualization operates with CSV files in a specific format.
The first column represents the x-values (e.g., years), while the other columns represents the y-values (e.g., stock price), with each column corresponding to a distinct graph/bar.
An example CSV file is displayed below:
Year,AAPL,NVDA,TSLA
2015,100.0,100.0,100.0
2015,97.49899152884228,97.95918367346938,96.9758064516129
2015,96.40984267849939,97.95918367346938,95.96774193548386
2015,97.09560306575231,95.91836734693878,96.23655913978494
2015,100.64542154094393,97.95918367346938,95.76612903225805
2015,101.61355385235983,97.95918367346938,94.08602150537634
2015,101.04881000403388,97.95918367346938,91.59946236559139
2015,101.21016538926986,100.0,93.01075268817203
2015,99.15288422751108,97.95918367346938,87.43279569892472
2015,98.74949576442114,97.95918367346938,87.70161290322581
Example Videos 💻
You can watch the full example videos here.
Change the Default Settings 🛠
You can customize the default settings, such as the output filename, resolution and aspect ratio, by modifying the configuration. Below are some examples demonstrating how to override these defaults:
from manim import config
# Filename
config.output_file = "new_file_name"
# Aspect ratio (16:9) (1920x1080) (e.g. YouTube)
config.frame_width = 16
config.frame_height = 9
config.pixel_width = 1920
config.pixel_height = 1080
# Aspect ratio (9:16) (1080x1920) (e.g. TikTok)
config.frame_width = 9
config.frame_height = 16
config.pixel_width = 1080
config.pixel_height = 1920
Line Plot 📈
The line plot visualizes the stock market prices [$] of Apple, NVIDIA and Tesla from 01.01.2010 to 01.01.2025. Below is the script to create the animation and the resulting output:
from manim_stock.visualization import Lineplot
# Create animation
scene = Lineplot(
path="stock_data.csv",
background_run_time=5,
animation_run_time=10,
wait_run_time=5,
)
# Render animation
scene.render()
Growing Line Plot 📈
The growing line plot visualizes the stock market prices [$] of Apple, NVIDIA and Tesla from 01.01.2010 to 01.01.2025. Below is the script to create the animation and the resulting output.
from manim_stock.visualization import GrowingLineplot
# Create animation
scene = GrowingLineplot(
path="stock_data.csv",
background_run_time=5,
animation_run_time=10,
wait_run_time=5,
)
# Render animation
scene.render()
Bar Plot 📊
The bar plot visualizes the stock market prices [$] of Apple, NVIDIA and Tesla from 01.01.2010 to 01.01.2025. Below is the script to create the animation and the resulting output.
from manim_stock.visualization import Barplot
# Create animation
scene = Barplot(
path="stock_data.csv",
background_run_time=5,
animation_run_time=10,
wait_run_time=5,
)
# Render animation
scene.render()
Growing Bar Plot 📊
The growing bar plot visualizes the stock market prices [$] of Apple, NVIDIA and Tesla from 01.01.2010 to 01.01.2025. Below is the script to create the animation and the resulting output.
from manim_stock.visualization import GrowingBarplot
# Create animation
scene = GrowingBarplot(
path="stock_data.csv",
background_run_time=5,
animation_run_time=10,
wait_run_time=5,
)
# Render animation
scene.render()
Installation of manim-stock-visualization ⚙️
To use manim-stock-visualization, you need to install manimCE and LaTeX on your system.
Please follow the steps below to install manimCE.
For other systems, please visit the manimCE installation guide.
Linux (Debian-based)
- Update your package list and install prerequisites:
sudo apt update
sudo apt install build-essential python3-dev libcairo2-dev libpango1.0-dev
- Installing LaTeX:
sudo apt install texlive-full
- Installing manimCE:
pip install manim
- Installing manim-stock-visualization:
pip install manim-stock-visualization
Development 🔧
Contributions are welcome! Please fork the repository and submit a pull request. Make sure to follow the coding standards and write tests for any new features or bug fixes.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file manim_stock_visualization-0.0.2.tar.gz.
File metadata
- Download URL: manim_stock_visualization-0.0.2.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c063887b8652fc1fc7ee54c98f39a4b7975b46dbc1759f64ed2de97a121d8731
|
|
| MD5 |
277c8ee85580dec2aa75aab8c7c8f13c
|
|
| BLAKE2b-256 |
e907b75c6fc5b4025a6ce1ca138ad2f62cfc6c5027dd18d983c8bdf898e2c400
|
File details
Details for the file manim_stock_visualization-0.0.2-py3-none-any.whl.
File metadata
- Download URL: manim_stock_visualization-0.0.2-py3-none-any.whl
- Upload date:
- Size: 20.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd86d13ac78710c5b3fc625954173dd69380e4353f73264ceb62da18124d7057
|
|
| MD5 |
c74d4bc919342a693169c2f011518a41
|
|
| BLAKE2b-256 |
f33712a85d9d6d4a2a652b0626090a2a47355c390f530ad327b0d2b5ca9f6352
|