Skip to main content

Stock information analysis package

Project description

StockInfo

StockInfo is a Python package for loading historical stock data, calculating Simple Moving Averages (SMA) and Relative Strength Index (RSI), and writing the results to CSV files.

Installation

You can install StockInfo using pip:

pip install stocklerain1001

Usage

Loading historical data:

from stocklerain1001 import StockInfo

# Create an instance of the StockInfo class
stock_info = StockInfo()

# Load historical data from a CSV file (default: "orcl.csv" in the 'data' directory)
stock_info.load_data()

# Access the loaded data
data = stock_info.Data

Calculating Simple Moving Averages (SMA):

# Calculate SMA with a specified window size (default: 5)
sma_values = stock_info.calculate_sma(window_size=10)

# Access the calculated SMA values
print(sma_values)

Calculating Relative Strength Index (RSI):

# Calculate RSI with a specified window size (default: 14)
rsi_values = stock_info.calculate_rsi(window_size=14)

# Access the calculated RSI values
print(rsi_values)

Writing Results to CSV:

# Write SMA results to a CSV file
sma_header = ['Date', 'Close', 'SMA']
sma_data = [(stock_info.Data[i]["Date"], stock_info.Data[i]['Close'], sma) for i, sma in enumerate(sma_values)]
stock_info.write_file("sma_results.csv", sma_header, sma_data)

# Write RSI results to a CSV file
rsi_header = ['Date', 'Close', 'RSI']
rsi_data = [(stock_info.Data[i]["Date"], stock_info.Data[i]['Close'], rsi) for i, rsi in enumerate(rsi_values)]
stock_info.write_file("rsi_results.csv", rsi_header, rsi_data)

Examples

Basic Usage:

from stocklerain1001 import StockInfo

# Load historical data
stock_info = StockInfo()
stock_info.load_data()

# Calculate SMA and write results to CSV
sma_values = stock_info.calculate_sma(window_size=5)
sma_header = ['Date', 'Close', 'SMA']
sma_data = [(stock_info.Data[i]["Date"], stock_info.Data[i]['Close'], sma) for i, sma in enumerate(sma_values)]
stock_info.write_file("sma_results.csv", sma_header, sma_data)

# Calculate RSI and write results to CSV
rsi_values = stock_info.calculate_rsi(window_size=14)
rsi_header = ['Date', 'Close', 'RSI']
rsi_data = [(stock_info.Data[i]["Date"], stock_info.Data[i]['Close'], rsi) for i, rsi in enumerate(rsi_values)]
stock_info.write_file("rsi_results.csv", rsi_header, rsi_data)

Custom Data File and Output Directory:

from stocklerain1001 import StockInfo

# Load historical data
stock_info = StockInfo()
stock_info.load_data()

# Calculate SMA and write results to CSV
sma_values = stock_info.calculate_sma(window_size=5)
sma_header = ['Date', 'Close', 'SMA']
sma_data = [(stock_info.Data[i]["Date"], stock_info.Data[i]['Close'], sma) for i, sma in enumerate(sma_values)]
stock_info.write_file("sma_results.csv", sma_header, sma_data)

# Calculate RSI and write results to CSV
rsi_values = stock_info.calculate_rsi(window_size=14)
rsi_header = ['Date', 'Close', 'RSI']
rsi_data = [(stock_info.Data[i]["Date"], stock_info.Data[i]['Close'], rsi) for i, rsi in enumerate(rsi_values)]
stock_info.write_file("rsi_results.csv", rsi_header, rsi_data)

Contributing

Contributions are welcome! If you encounter any issues or have suggestions for improvements, please create an issue or submit a pull request.

Licence

This project is licensed under the MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stocklerain1001-0.0.1.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

stocklerain1001-0.0.1-py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page