The library helps analysts to investigate portfolio and stock market.
Project description
WYN-PM 📈💼
Welcome to the wyn-pm
library, an official library from W.Y.N. Associates, LLC FinTech branch. This library provides tools for stock analysis, efficient portfolio generation, and training sequential neural networks for financial data.
Installation 🚀
To install the library, use the following command:
! pip install wyn-pm
Stock Analyzer: Plot Buy/Sell Signal 📊
Analyze stocks and plot buy/sell signals using the MACD indicator.
Example Usage:
from wyn_pm.stock_analyzer import *
# Initialize stock analysis for a given ticker
stock_analysis = StockAnalysis(ticker="AAPL")
# Fetch stock data
stock_analysis.fetch_data()
# Calculate MACD
stock_analysis.calculate_macd()
# Find crossovers to generate buy/sell signals
stock_analysis.find_crossovers(bullish_threshold=-2, bearish_threshold=2)
# Create and show the plot
fig = stock_analysis.create_fig()
fig.show()
Efficient Portfolio: Generate Optimal Weights 💹
Create an optimal portfolio by generating efficient weights for a list of stock tickers.
Example Usage:
from wyn_pm.efficient_portfolio import *
# Initialize portfolio with given tickers and date range
portfolio = EfficientPortfolio(tickers=["AAPL", "MSFT", "GOOGL"], start_date="2020-01-01", end_date="2022-01-01", interval="1d")
# Download stock data
stock_data = portfolio.download_stock_data()
# Calculate portfolio returns
portfolio_returns = portfolio.create_portfolio_and_calculate_returns(top_n=5)
# Calculate mean returns and covariance matrix
mean_returns = stock_data.pct_change().mean()
cov_matrix = stock_data.pct_change().cov()
# Define the number of portfolios to simulate and the risk-free rate
num_portfolios = 10000
risk_free_rate = 0.01
# Display the efficient frontier with randomly generated portfolios
fig, details = portfolio.display_simulated_ef_with_random(mean_returns.values, cov_matrix.values, num_portfolios, risk_free_rate)
fig.show()
# Print details of the max Sharpe and min volatility portfolios
print(details)
Training Sequential Neural Networks: Stock Prediction 🤖📈
Train various neural network models on stock data and perform Monte Carlo simulations.
Example Usage:
from wyn_pm.trainer import *
# Initialize StockModeling
stock_modeling = StockModeling()
# Get the current year
current_year = stock_modeling.current_year()
# Download stock data
data = stock_modeling.download_data('AAPL', '2020-01-01', '2021-01-01')
# Prepare the data
scaled_data, scaler = stock_modeling.prepare_data(data['Close'])
# Create datasets
X, y = stock_modeling.create_datasets(scaled_data)
# Split the data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
# Create and train RNN model
rnn_model = stock_modeling.create_rnn_model((X_train.shape[1], 1))
rnn_model.fit(X_train, y_train, epochs=10, batch_size=32, verbose=0)
y_train_pred = rnn_model.predict(X_train)
y_test_pred = rnn_model.predict(X_test)
# Calculate mean return and standard deviation for Monte Carlo simulations
daily_returns = np.diff(y_test_pred.flatten()) / y_test_pred[:-1].flatten()
mean_return = daily_returns.mean()
std_dev = daily_returns.std()
# Plot Monte Carlo forecasts
fig = stock_modeling.plot_monte_carlo_forecasts(data, 365, 1000, mean_return, std_dev)
fig.show()
Enjoy analyzing stocks, creating efficient portfolios, and training neural networks with wyn-pm
! If you have any questions, feel free to reach out.
Happy coding! 🖥️✨
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.