Lottery utility package
Project description
Stock Analysis Script (Lottery)
This Python script analyzes historical stock data stored in a CSV file (orcl.csv). It calculates and writes two technical indicators, the 5-day Simple Moving Averages (SMA) and the 14-day Relative Strength Index (RSI), to separate CSV files (orcl-sma.csv and orcl-rsi.csv).
Usage
-
Load Historical Data:
- The script first loads historical stock data from a CSV file (
orcl.csvin this example). The data is expected to have columns like 'Date', 'Open', 'High', 'Low', 'Close', 'Volume', etc. Make sure to adjust thecsv_file_pathvariable with the correct path to your CSV file.
csv_file_path = ' ' # Add orcl.csv file path historical_data = load_historical_data(csv_file_path)
- The script first loads historical stock data from a CSV file (
-
Run the Script:
- Execute the script to load the historical data, calculate technical indicators, and write the results to CSV files. Run the following command in the command line:
python script_name.py
Output Files
Two CSV files (orcl-sma.csv and orcl-rsi.csv) will be generated with the calculated SMA and RSI values, respectively.
Functions
-
load_historical_data(file_path):
- Loads historical stock data from the specified CSV file into a list of dictionaries.
-
calculate_sma(data, window):
- Calculates the 5-day Simple Moving Averages (SMA) for the given historical data.
-
calculate_rsi(data, window):
- Calculates the 14-day Relative Strength Index (RSI) for the given historical data using a provided formula.
-
write_to_csv(file_path, header, data):
- Writes data to a CSV file with the specified header.
The Stracture of The File:
my-python-project
│───README.md
│─── setup.py
│
│
└───Lotterry
| init.py
│ Lottery.py
Example of Usage
csv_file_path = ' ' # Add orcl.csv file path
historical_data = load_historical_data(csv_file_path)
sma_5 = calculate_sma(historical_data, window=5)
rsi_14 = calculate_rsi(historical_data, window=14)
sma_header = ['Date', 'SMA_5']
sma_data = [[row['Date'], sma] for row, sma in zip(historical_data, sma_5)]
write_to_csv('orcl-sma.csv', sma_header, sma_data)
rsi_header = ['Date', 'RSI_14']
rsi_data = [[row['Date'], rsi] for row, rsi in zip(historical_data, rsi_14)]
write_to_csv('orcl-rsi.csv', rsi_header, rsi_data)
print(historical_data[:5])
print("5-day SMA:", sma_5[:5])
print("14-day RSI:", rsi_14[:5])
print("Files 'orcl-sma.csv' and 'orcl-rsi.csv' written successfully.")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lottery_dcl-0.1.1-py3-none-any.whl.
File metadata
- Download URL: lottery_dcl-0.1.1-py3-none-any.whl
- Upload date:
- Size: 2.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60e48d0308388140e4e4b537fbb07d77f92ca4ff1c1ae6d35692720a346dbfd3
|
|
| MD5 |
7ebbcbc0e2e51ec8d3988b4857388719
|
|
| BLAKE2b-256 |
41dd17d17674dbe1f00f2ee3ffa16157864f934ebace829a328455aded6fe246
|