stockpy-learn

Deep Learning Regression and Classification Library built on top of PyTorch and Pyro

https://github.com/silviobaratto/stockpy

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (18.0%) to scientific vocabulary

Keywords

classification deep-learning machine-learning pyro python pytorch regression
Last synced: 4 months ago · JSON representation ·

Repository

Deep Learning Regression and Classification Library built on top of PyTorch and Pyro

Basic Info
Statistics
  • Stars: 13
  • Watchers: 2
  • Forks: 3
  • Open Issues: 1
  • Releases: 4
Topics
classification deep-learning machine-learning pyro python pytorch regression
Created about 3 years ago · Last pushed about 2 years ago
Metadata Files
Readme License Citation

README.md

Python package GitHub license Documentation Status PyPI version

Table of Contents

Description

stockpy is a versatile Python Machine Learning library initially designed for stock market data analysis and predictions. It has now evolved to handle a wider range of datasets, supporting tasks such as regression and classification. It currently supports the following algorithms, each with regression and classification implementations:

  • Bayesian Neural Networks (BNN)
  • Long Short Term Memory (LSTM)
  • Bidirectional Long Short Term Memory (BiLSTM)
  • Gated Recurrent Unit (GRU)
  • Bidirectional Gated Recurrent Unit (BiGRU)
  • Multilayer Perceptron (MLP)
  • Neural Network Hidden Markov Models (NNHMM)
  • Deep Markov Model (DMM)

Usage

To use stockpy, 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, numpy arrays and torch arrays.

Here's an example to demonstrate the usage of stockpy for regression. In this example, we 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:

```Python from stockpy.neuralnetwork import CNNRegressor import pandas as pd from sklearn.modelselection import traintestsplit from sklearn.preprocessing import StandardScaler

Load the dataset

df = pd.readcsv('stock/AAPL.csv', parsedates=True, index_col='Date').dropna(how="any")

Define features and target

X = df[['Open', 'High', 'Low', 'Volume']] y = df['Close']

Split the dataset

Xtrain, Xtest, ytrain, ytest = traintestsplit(X, y, test_size=0.2, shuffle=False)

Scale the data

scaler = StandardScaler() Xtrain = scaler.fittransform(Xtrain) Xtest = scaler.transform(X_test)

Convert the data to torch tensors

Xtrain = torch.tensor(Xtrain, dtype=torch.float) Xtest = torch.tensor(Xtest, dtype=torch.float) ytrain = torch.tensor(ytrain.values, dtype=torch.float)

Fit the model

predictor = CNNRegressor(hidden_size=32)

predictor.fit(Xtrain, ytrain, batch_size=32, lr=0.01, optimizer=torch.optim.Adam, epochs=50) ```

Here's an example to demonstrate the usage of stockpy for classification. In this example, we read a pickle file containing labeled data, split the data into training and testing sets, fit an LSTM model to the training data, and use the model to make classification on the test data:

```Python from stockpy.neuralnetwork import LSTMClassifier from sklearn.datasets import makeclassification from sklearn.modelselection import traintest_split

X, y = makeclassification(nsamples=10000, nfeatures=20, ninformative=15, nredundant=5, nclasses=5, random_state=0)

Xtrain, Xtest, ytrain, ytest = traintestsplit(X, y, test_size=0.05, shuffle=False)

Scale the data and convert to torch tensors

from sklearn.preprocessing import MinMaxScaler scaler = MinMaxScaler() Xtrain = scaler.fittransform(Xtrain) Xtest = scaler.transform(X_test)

Xtrain = Xtrain.astype(np.float32) Xtest = Xtest.astype(np.float32) ytrain = ytrain.astype(np.int64)

predictor = LSTMClassifier()

predictor.fit(Xtrain, ytrain, batch_size=32, lr=0.01, optimizer=torch.optim.Adam, epochs=50) ```

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.

Dependencies and installation

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.

Installing via pip

To install the package: ```bash

pip install stockpy-learn To uninstall the package: bash pip uninstall stockpy-learn ```

Installing from source

You can clone this repository on your local machines using:

```bash

git clone https://github.com/SilvioBaratto/stockpy ```

To install the package:

```bash

cd stockpy pip install . ```

Data downloader

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.

| Parameter | Explanation |-----------------|-------------------------------------| | --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. | | --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. | | --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. | |--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. | |--start| Specify the start date for downloading or updating data. | |--end| Specify the end date for downloading or updating data. | |--delete| Delete all files present in the files folder. | |--delete-stock| Delete a specific stock present in the files folder. | |--folder| Choose the folder where to read or download all the files. |

Usage example

Below are some examples of how to use the downloader: ```Python

Download all the data between "2017-01-01" and "2018-01-01"

python3 data.py --download --start="2017-01-01" --end="2018-01-01"

Download data for Apple (AAPL) from "2017-01-01" to today's date

python3 data.py --stock="AAPL" --end="today"

Update all the data between "2014-01-01" and "2020-01-01"

python3 data.py --update --start="2014-01-01" --end="2020-01-01"

Update a specific stock from "2014-01-01" until the last day present in the stock file

python3 data.py --update-stock --stock="AAPL" --start="2014-01-01"

Download all the data between "2017-01-01" and today's date,

choosing the folder where to download the files

python3 data.py --download --folder="../../example" ```

TODOs

Below is a list of planned enhancements and features that are in the pipeline for stockpy. Contributions and suggestions are always welcome!

  • [ ] Implement a dedicated test directory with comprehensive unit tests to ensure reliability and facilitate continuous integration.
  • [ ] Expand the documentation to include more detailed tutorials and code explanations, aiding users in effectively utilizing stockpy.
  • [ ] Enrich the algorithmic suite by adding additional models for regression and classification, catering to a broader range of data science needs.
  • [ ] Integrate generative models into the library to provide advanced capabilities for data synthesis and pattern discovery.
  • [ ] Develop and incorporate sophisticated prediction models that can handle complex forecasting tasks with higher accuracy.

Note: A checked box (✅) indicates that the task has been completed.

Authors and acknowledgements

stockpy is currently developed and mantained by Silvio Baratto. You can contact me at: - silvio.baratto22 at gmail.com

Reporting a bug

The best way to report a bug is using the Issues section. Please, be clear, and give detailed examples on how to reproduce the bug (the best option would be the graph which triggered the error you are reporting).

How to contribute

We are more than happy to receive contributions on tests, documentation and new features. Our Issues section is always full of things to do.

Here are the guidelines to submit a patch:

  1. Start by opening a new issue describing the bug you want to fix, or the feature you want to introduce. This lets us keep track of what is being done at the moment, and possibly avoid writing different solutions for the same problem.

  2. Fork the project, and setup a new branch to work in (fix-issue-22, for instance). If you do not separate your work in different branches you may have a bad time when trying to push a pull request to fix a particular issue.

  3. Run black before pushing your code for review.

  4. Provide menaningful commit messages to help us keeping a good git history.

  5. Finally you can submbit your pull request!

License

See the LICENSE file for license rights and limitations (MIT).

stockpy Legal Disclaimer

Please read this legal disclaimer carefully before using stockpy-learn library. By using stockpy-learn library, you agree to be bound by this disclaimer.

stockpy-learn library is provided for informational and educational purposes only and is not intended as a recommendation, offer or solicitation for the purchase or sale of any financial instrument or securities. The information provided in the stockpy-learn library is not to be construed as financial, investment, legal, or tax advice, and the use of any information provided in stockpy-learn library is at your own risk.

stockpy-learn library is not a substitute for professional financial or investment advice and should not be relied upon for making investment decisions. You should consult a qualified financial or investment professional before making any investment decision.

We make no representation or warranty, express or implied, as to the accuracy, completeness, or suitability of any information provided in stockpy, and we shall not be liable for any errors or omissions in such information.

We shall not be liable for any direct, indirect, incidental, special, consequential, or exemplary damages arising from the use of stockpy library or any information provided therein.

stockpy-learn library is provided "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability, fitness for a particular purpose, or non-infringement.

We reserve the right to modify or discontinue stockpy-learn library at any time without notice. We shall not be liable for any modification, suspension, or discontinuance of stockpy-learn library.

By using stockpy-learn library, you agree to indemnify and hold us harmless from any claim or demand, including reasonable attorneys' fees, made by any third party due to or arising out of your use of stockpy-learn library, your violation of this disclaimer, or your violation of any law or regulation.

This legal disclaimer is governed by and construed in accordance with the laws of Italy, and any disputes relating to this disclaimer shall be subject to the exclusive jurisdiction of the courts of Italy.

If you have any questions about this legal disclaimer, please contact us at silvio.baratto22@gmail.com.

By using stockpy-learn library, you acknowledge that you have read and understood this legal disclaimer and agree to be bound by its terms and conditions.

Owner

  • Name: SilvioBaratto
  • Login: SilvioBaratto
  • Kind: user

Citation (CITATION.cff)

cff-version: 0.1.0
message: "If you use this software, please cite it as below."
authors:
- family-names: "Baratto"
  given-names: "Silvio"
  orcid: "https://orcid.org/0009-0002-1906-0057"
title: "stockpy: Deep Learning-Based Regression and Classification Framework built on top of PyTorch and Pyro"
version: 0.3.1
date-released: 2023-03-25
url: "https://github.com/SilvioBaratto/stockpy"

GitHub Events

Total
  • Issues event: 1
  • Watch event: 2
Last Year
  • Issues event: 1
  • Watch event: 2

Issues and Pull Requests

Last synced: 5 months ago

All Time
  • Total issues: 1
  • Total pull requests: 1
  • Average time to close issues: N/A
  • Average time to close pull requests: 1 day
  • Total issue authors: 1
  • Total pull request authors: 1
  • Average comments per issue: 0.0
  • Average comments per pull request: 1.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 1
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 1
  • Pull request authors: 0
  • Average comments per issue: 0.0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • lordzohar (1)
Pull Request Authors
  • Francesc0rtu (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 65 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 15
  • Total maintainers: 1
pypi.org: stockpy-learn

Deep Learning Regression and Classification Library built on top of PyTorch and Pyro

  • Versions: 15
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 65 Last month
Rankings
Dependent packages count: 7.0%
Downloads: 10.7%
Average: 23.7%
Dependent repos count: 30.5%
Forks count: 30.6%
Stargazers count: 39.5%
Maintainers (1)
Last synced: 5 months ago

Dependencies

.github/workflows/python-package.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite
pyproject.toml pypi
requirements.txt pypi
  • numpy >=1.21.2
  • pandas >=1.3.3
  • pyro-ppl >=1.7.0
  • safetensors >=0.4.0
  • scikit-learn >=0.24.2
  • torch >=1.9.1
  • tqdm ==4.62.3
setup.py pypi
  • numpy >=1.21.2
  • pandas >=1.3.3
  • pyro-ppl >=1.7.0
  • safetensors >=0.4.0
  • scikit-learn >=0.24.2
  • torch >=1.9.1
  • tqdm >=4.62.3