Skip to content

Commit ca435c2

Browse files
author
Silvio
committed
code cleaning and documentation
1 parent 1e86d92 commit ca435c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1074
-925
lines changed

docs/source/Functions.rst

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Functions
2+
=========
3+
4+
.. toctree::
5+
:glob:
6+
:maxdepth: 2
7+
:caption: Contents:
8+
9+
algos

docs/source/Module.rst

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ Module
77
:caption: Contents:
88

99
Probabilistic
10+
Neural Network

docs/source/Neural Network.rst

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
Neural Network
2+
==============
3+
4+
MLP
5+
----------
6+
7+
.. automodule:: stockpy.neural_network._mlp
8+
:members:
9+
:undoc-members:
10+
:show-inheritance:
11+
12+
LSTM
13+
-----------
14+
15+
.. automodule:: stockpy.neural_network._lstm
16+
:members:
17+
:undoc-members:
18+
:show-inheritance:
19+
20+
21+
GRU
22+
---------------
23+
24+
.. automodule:: stockpy.neural_network._gru
25+
:members:
26+
:undoc-members:
27+
:show-inheritance:
28+
29+
BiLSTM
30+
---------------
31+
32+
.. automodule:: stockpy.neural_network._bilstm
33+
:members:
34+
:undoc-members:
35+
:show-inheritance:
36+
37+
BiGRU
38+
---------------
39+
40+
.. automodule:: stockpy.neural_network._bigru
41+
:members:
42+
:undoc-members:
43+
:show-inheritance:

docs/source/algos.rst

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Base
2+
====
3+
4+
.. automodule:: stockpy.base
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
8+

docs/source/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ stockpy Documentation
1414
:caption: stockpy Core:
1515

1616
Module
17+
Functions

requirements.txt

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1-
torch>=1.9.0,
2-
pyro-ppl>=1.7.0,
3-
numpy>=1.20.0,
1+
hashlib==1.0.1
2+
torch==1.9.1
3+
pyro-ppl==1.7.0
4+
numpy==1.21.2
5+
pandas==1.3.3
6+
yfinance==0.1.63
7+
yahoofinancials==1.6
8+
pandas-datareader==0.10.0
9+
tqdm==4.62.3
10+
torch==1.9.1
11+
scikit-learn==0.24.2

results/BayesianNN.png

-655 KB
Loading

results/BiGRU.png

78.6 KB
Loading

results/BiLSTM.png

78.8 KB
Loading

results/DeepMarkovModel.png

2.21 KB
Loading

results/GRU.png

-639 KB
Loading

results/GaussianHMM.png

-16.5 KB
Loading

results/LSTM.png

-16.7 KB
Loading

results/MLP.png

-18.7 KB
Loading

setup.py

+11-148
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,7 @@
11
import setuptools
22

3-
long_description="""
4-
## Table of contents
5-
* [Description](#description)
6-
* [Documentation](#documentation)
7-
* [Data Downloader](#data-downloader)
8-
* [License](#license)
9-
10-
## Description
11-
**stockpy** is a Python Machine Learning library designed to facilitate stock market data analysis and predictions. It currently supports the following algorithms:
12-
13-
- Long Short Term Memory (LSTM)
14-
- Bidirectional Long Short Term Memory (BiLSTM)
15-
- Gated Recurrent Unit (GRU)
16-
- Bidirectional Gated Recurrent Unit (BiGRU)
17-
- Multilayer Perceptron (MLP)
18-
- Gaussian Hidden Markov Models (GaussianHMM)
19-
- Bayesian Neural Networks (BayesianNN)
20-
- Deep Markov Model (DeepMarkovModel)
21-
22-
**stockpy** can be used to perform a range of tasks such as detecting relevant trading patterns, making predictions and generating trading signals.
23-
24-
## Usage
25-
To use **stockpy** and perform predictions on stock market data, start by importing the relevant models from the `stockpy.neural_network` and `stockpy.probabilistic` modules. The library can be used with various types of input data, such as CSV files, pandas dataframes and numpy arrays.
26-
27-
To demonstrate the usage of stockpy, we can perform the following code to read a CSV file containing stock market data for Apple (AAPL), split the data into training and testing sets, fit an LSTM model to the training data, and use the model to make predictions on the test data:
28-
```Python
29-
from sklearn.model_selection import train_test_split
30-
import pandas as pd
31-
from stockpy.neural_network import LSTM
32-
33-
# read CSV file and drop missing values
34-
df = pd.read_csv('AAPL.csv', parse_dates=True, index_col='Date').dropna(how="any")
35-
36-
# split data into training and testing sets
37-
X_train, X_test = train_test_split(df, test_size=0.1, shuffle=False)
38-
39-
# create LSTM model instance and fit to training data
40-
predictor = LSTM()
41-
predictor.fit(X_train, batch_size=24, epochs=10)
42-
43-
# use LSTM model to make predictions on test data
44-
y_pred = predictor.predict(X_test)
45-
```
46-
The above code can be applied to all models in the library, just make sure to import from the correct location, either `stockpy.neural_network` or `stockpy.probabilistic`.
47-
48-
## Dependencies and installation
49-
**stockpy** requires the modules `numpy, torch, pyro-ppl`. The code is tested for _Python 3_. It can be installed using `pip` or directly from the source cod.
50-
51-
### Installing via pip
52-
53-
To install the package:
54-
```bash
55-
> pip install stockpy-learn
56-
```
57-
To uninstall the package:
58-
```bash
59-
> pip uninstall stockpy-learn
60-
```
61-
### Installing from source
62-
63-
You can clone this repository on your local machines using:
64-
65-
```bash
66-
> git clone https://github.com/SilvioBaratto/stockpy
67-
```
68-
69-
To install the package:
70-
71-
```bash
72-
> cd stockpy
73-
> python setup.py install
74-
```
75-
## Data downloader
76-
The data downloader is a command-line application located named `data.py`, which can be used to download and update stock market data. The downloader has been tested and verified using Ubuntu 22.04 LTS.
77-
78-
| Parameter | Explanation
79-
|-----------------|-------------------------------------|
80-
| `--download`| Download all the S&P 500 stocks. If no start and end dates are specified, the default range is between "2017-01-01" and today's date. |
81-
| `--stock`| Download a specific stock specified by the user. If no start and end dates are specified, the default range is between "2017-01-01" and today's date. |
82-
| `--update`| Update all the stocks present in the folder containing the files. It is possible to update the files to any range of dates. If a stock wasn't listed before a specific date, it will be downloaded from the day it enters the public market. |
83-
|`--update.stock`| Update a specific stock specified by the user. It is possible to update the files to any range of dates by specifying the start and end dates. |
84-
|`--start`| Specify the start date for downloading or updating data. |
85-
|`--end`| Specify the end date for downloading or updating data. |
86-
|`--delete`| Delete all files present in the files folder. |
87-
|`--delete-stock`| Delete a specific stock present in the files folder. |
88-
|`--folder`| Choose the folder where to read or download all the files. |
89-
### Usage example
90-
Below are some examples of how to use the downloader:
91-
```Python
92-
# Download all the data between "2017-01-01" and "2018-01-01"
93-
python3 data.py --download --start="2017-01-01" --end="2018-01-01"
94-
95-
# Download data for Apple (AAPL) from "2017-01-01" to today's date
96-
python3 data.py --stock="AAPL" --end="today"
97-
98-
# Update all the data between "2014-01-01" and "2020-01-01"
99-
python3 data.py --update --start="2014-01-01" --end="2020-01-01"
100-
101-
# Update a specific stock from "2014-01-01" until the last day present in the stock file
102-
python3 data.py --update-stock --stock="AAPL" --start="2014-01-01"
103-
104-
# Download all the data between "2017-01-01" and today's date,
105-
# choosing the folder where to download the files
106-
python3 data.py --download --folder="../../example"
107-
```
108-
109-
## Authors and acknowledgements
110-
**stockpy** is currently developed and mantained by **Silvio Baratto**. You can contact me at:
111-
- silvio.baratto22 at gmail.com
112-
113-
## Reporting a bug
114-
The best way to report a bug is using the
115-
[Issues](https://github.com/fAndreuzzi/BisPy/issues) section. Please, be clear,
116-
and give detailed examples on how to reproduce the bug (the best option would
117-
be the graph which triggered the error you are reporting).
118-
119-
## How to contribute
120-
121-
We are more than happy to receive contributions on tests, documentation and
122-
new features. Our [Issues](https://github.com/fAndreuzzi/BisPy/issues)
123-
section is always full of things to do.
124-
125-
Here are the guidelines to submit a patch:
126-
127-
1. Start by opening a new [issue](https://github.com/fAndreuzzi/BisPy/issues)
128-
describing the bug you want to fix, or the feature you want to introduce.
129-
This lets us keep track of what is being done at the moment, and possibly
130-
avoid writing different solutions for the same problem.
131-
132-
2. Fork the project, and setup a **new** branch to work in (_fix-issue-22_, for
133-
instance). If you do not separate your work in different branches you may
134-
have a bad time when trying to push a pull request to fix a particular
135-
issue.
136-
137-
3. Run [black](https://github.com/psf/black) before pushing
138-
your code for review.
139-
140-
4. Provide menaningful **commit messages** to help us keeping a good _git_
141-
history.
142-
143-
5. Finally you can submbit your _pull request_!
144-
145-
## License
146-
147-
See the [LICENSE](LICENSE) file for license rights and limitations (MIT).
148-
"""
3+
with open("README.md", "r", encoding="utf-8") as fh:
4+
long_description = fh.read()
1495

1506
setuptools.setup(
1517
name='stockpy-learn',
@@ -167,8 +23,15 @@
16723
packages=setuptools.find_packages(),
16824
python_requires='>=3.6',
16925
install_requires=[
170-
"torch>=1.9.0",
26+
"torch>=1.9.1",
17127
"pyro-ppl>=1.7.0",
172-
"numpy>=1.20.0",
28+
"numpy>=1.21.2",
29+
"hashlib>=1.0.1",
30+
"pandas>=1.3.3",
31+
"yfinance>=0.1.63",
32+
"yahoofinancials>=1.6",
33+
"pandas-datareader>=0.10.0",
34+
"tqdm>=4.62.3",
35+
"scikit-learn>=0.24.2",
17336
],
17437
)

stockpy/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .neural_network import _base
22
from .probabilistic import _base
33
from .utils import *
4-
from .base import ModelTrainer
4+
from .base import Base
-8 Bytes
Binary file not shown.
-11 KB
Binary file not shown.
862 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)