|
1 | 1 | import setuptools
|
2 | 2 |
|
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() |
149 | 5 |
|
150 | 6 | setuptools.setup(
|
151 | 7 | name='stockpy-learn',
|
|
167 | 23 | packages=setuptools.find_packages(),
|
168 | 24 | python_requires='>=3.6',
|
169 | 25 | install_requires=[
|
170 |
| - "torch>=1.9.0", |
| 26 | + "torch>=1.9.1", |
171 | 27 | "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", |
173 | 36 | ],
|
174 | 37 | )
|
0 commit comments