Stock Analysis
Package for making elements of technical analysis of a stock easier. This package is meant to be a starting point for you to develop your own. As such, all the instructions for installing/setup will be assuming you will continue to develop on your end.
Usage
This section will show some of the functionality of each class; however, it is by no means exhaustive.
Getting data
from stock_analysis import StockReader
reader = StockReader("2017-01-01", "2018-12-31")
# get bitcoin data in USD
bitcoin = reader.get_bitcoin_data("USD")
# get faang data
fb, aapl, amzn, nflx, goog = (
reader.get_ticker_data(ticker) for ticker in ["FB", "AAPL", "AMZN", "NFLX", "GOOG"]
)
# get S&P 500 data
sp = reader.get_index_data("S&P 500")
Grouping data
from stock_analysis import group_stocks, describe_group
faang = group_stocks(
{"Facebook": fb, "Apple": aapl, "Amazon": amzn, "Netflix": nflx, "Google": goog}
)
# describe the group
describe_group(faang)
Building a portfolio
Groups assets by date and sums columns to build a portfolio.
from stock_analysis import make_portfolio
faang_portfolio = make_portfolio(faang)
Visualizing data
Be sure to check out the other methods here for different plot types, reference lines, shaded regions, and more!
Single asset
Evolution over time:
import matplotlib.pyplot as plt
from stock_analysis import StockVisualizer
netflix_viz = StockVisualizer(nflx)
ax = netflix_viz.evolution_over_time(
"close", figsize=(10, 4), legend=False, title="Netflix closing price over time"
)
netflix_viz.add_reference_line(
ax,
x=nflx.high.idxmax(),
color="k",
linestyle=":",
label=f"highest value ({nflx.high.idxmax():%b %d})",
alpha=0.5,
)
ax.set_ylabel("price ($)")
plt.show()
After hours trades:
netflix_viz.after_hours_trades()
plt.show()
Differential in closing price versus another asset:
netflix_viz.fill_between_other(fb)
plt.show()
Candlestick plots with resampling (uses mplfinance):
netflix_viz.candlestick(
resample="2W", volume=True, xrotation=90, datetime_format="%Y-%b -"
)
Note: run help() on StockVisualizer for more visualizations
Asset groups
Correlation heatmap:
from stock_analysis import AssetGroupVisualizer
faang_viz = AssetGroupVisualizer(faang)
faang_viz.heatmap(True)
Note: run help() on AssetGroupVisualizer for more visualizations. This object has many of the visualizations of the StockVisualizer class.
Analyzing data
Below are a few of the metrics you can calculate.
Single asset
from stock_analysis import StockAnalyzer
nflx_analyzer = stock_analysis.StockAnalyzer(nflx)
nflx_analyzer.annualized_volatility()
Asset group
Methods of the StockAnalyzer class can be accessed by name with the AssetGroupAnalyzer class's analyze() method.
from stock_analysis import AssetGroupAnalyzer
faang_analyzer = AssetGroupAnalyzer(faang)
faang_analyzer.analyze("annualized_volatility")
faang_analyzer.analyze("beta")
Modeling
from stock_analysis import StockModeler
Time series decomposition
decomposition = StockModeler.decompose(nflx, 20)
fig = decomposition.plot()
plt.show()
ARIMA
Build the model:
arima_model = StockModeler.arima(nflx, 10, 1, 5)
Check the residuals:
StockModeler.plot_residuals(arima_model)
plt.show()
Plot the predictions:
arima_ax = StockModeler.arima_predictions(
arima_model, start=start, end=end, df=nflx, ax=axes[0], title="ARIMA"
)
plt.show()
Linear regression
Build the model:
X, Y, lm = StockModeler.regression(nflx)
Check the residuals:
StockModeler.plot_residuals(lm)
plt.show()
Plot the predictions:
linear_reg = StockModeler.regression_predictions(
lm, start=start, end=end, df=nflx, ax=axes[1], title="Linear Regression"
)
plt.show()
Metadata
Release files for stock-analyser 0.3.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| stock-analyser-0.3.7.tar.gz | 17.4 kB | Without provenance | Details for stock-analyser-0.3.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| stock_analyser-0.3.7-py3-none-any.whl | Python 3 | none | any | Details for stock_analyser-0.3.7-py3-none-any.whl |
Total release size: 34.9 kB
Release files / stock-analyser-0.3.7.tar.gz
| Download URL | stock-analyser-0.3.7.tar.gz |
|---|---|
| Size | 17.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a782f5147d3ef31adffd953dd3f1168fbbb556f5ee19c1e3452cf8c5757b077e
|
|
BLAKE2b-256 checksum How to use checksums |
0236adca62c367fa13c7d6944eff3096d2eee696615b836f169f5124e883ad30
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Release files / stock_analyser-0.3.7-py3-none-any.whl
| Download URL | stock_analyser-0.3.7-py3-none-any.whl |
|---|---|
| Size | 17.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e38c410aed300eab86f76b74da8c87f0621ca9c939f189b8abec6f1fb5e2f4a0
|
|
BLAKE2b-256 checksum How to use checksums |
ac2805d2c45945faafc8c343ebf020c5e7b05ceae53c41836bc560e37ee2b06b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.16
|
Security for stock-analyser 0.3.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.