Example usage

Here we will demonstrate how to use pystockwatch in a project to calculate profit percent and volume change of stocks and plot the results.

import pystockwatch

print(pystockwatch.__version__)
0.3.4

Imports

from pystockwatch.pystockwatch import percent_change
from pystockwatch.pystockwatch import profit_viz
from pystockwatch.pystockwatch import volume_change
from pystockwatch.pystockwatch import volume_viz
import altair as alt
alt.renderers.enable('html')
RendererRegistry.enable('html')

To check the Profit percent of the stock

We ll use the percent_change() function created to calculate the profit percent of the stock ticker for the date range given below

percent_change('AAPL', '2017-01-01', '2019-01-10')
[*********************100%***********************]  1 of 1 completed

Price Change Percentage(%)
Date
2017-01-03 0.000
2017-01-04 -0.112
2017-01-05 0.396
2017-01-06 1.515
2017-01-09 2.445
... ...
2019-01-03 22.419
2019-01-04 27.645
2019-01-07 27.361
2019-01-08 29.789
2019-01-09 31.993

508 rows × 1 columns

To Visualize the profit percentage change trend of a stock against market benchmark

We ll now plot the change in the profit percent of the stock ticker for the date range given below and compare it against the benchmark ticker

profit_viz('AAPL', '2017-01-01', '2019-01-10', 'MSFT')
[*********************100%***********************]  1 of 1 completed

[*********************100%***********************]  1 of 1 completed

To check daily trading volume change of a stock

We can calculate the daily trading volume change of a stock , whether it increases or decreases compared to the previous day using volume_change function below:

volume_change('AAPL', '2017-01-01', '2019-01-10')
Date Volume Price_change
0 2017-01-03 115127600.0 nan
1 2017-01-04 84472400.0 Decrease
2 2017-01-05 88774400.0 Increase
3 2017-01-06 127007600.0 Increase
4 2017-01-09 134247600.0 Increase
... ... ... ...
504 2019-01-04 234428400.0 Increase
505 2019-01-07 219111200.0 Decrease
506 2019-01-08 164101200.0 Increase
507 2019-01-09 180396400.0 Increase
508 2019-01-10 143122800.0 Increase

509 rows × 3 columns

To Visualize the volume change trend of a stock

To plot the change in the daily change in volume of the stock ticker for the date range we use the volume_viz function

vol = volume_viz('AAPL', '2017-01-01', '2019-01-10')
vol.show()