pyfi-finance 0.1.1
A simple Python package for financial calculations
Requires Python: >=3.6

# PyFi Finance

A lightweight Python package for financial calculations.

## Installation

```bash
pip install pyfi-finance
```

## Features

- Core financial functions (compound interest, present value, NPV, IRR)
- Loan calculations (monthly payments, amortization schedules)
- Portfolio analysis (returns, volatility, Sharpe ratio, optimization)
- Stock technical indicators (moving averages, RSI, Bollinger Bands, MACD)
- Option pricing (Black-Scholes model)
- Command-line tools for quick financial calculations

## Usage Examples

### Basic Financial Calculations

```python
from pyfi_finance.core import compound_interest, present_value

# Calculate compound interest
final_amount = compound_interest(principal=1000, rate=0.05, time=5, periods_per_year=1)
print(f"Final amount after 5 years: ${final_amount:.2f}")

# Calculate present value
pv = present_value(future_value=1000, rate=0.05, time=5)
print(f"Present value: ${pv:.2f}")
```

### Portfolio Analysis

```python
import numpy as np
from pyfi_finance.portfolio import portfolio_return, portfolio_volatility, sharpe_ratio

# Define portfolio parameters
returns = [0.05, 0.1, 0.15]  # Expected returns
weights = [0.4, 0.3, 0.3]    # Portfolio weights
cov_matrix = np.array([
    [0.04, 0.02, 0.01],
    [0.02, 0.09, 0.03],
    [0.01, 0.03, 0.16]
])  # Covariance matrix

# Calculate portfolio metrics
expected_return = portfolio_return(returns, weights)
volatility = portfolio_volatility(returns, weights, cov_matrix)
sr = sharpe_ratio(expected_return, volatility, risk_free_rate=0.01)

print(f"Expected Return: {expected_return:.2%}")
print(f"Volatility: {volatility:.2%}")
print(f"Sharpe Ratio: {sr:.2f}")
```

### Option Pricing

```python
from pyfi_finance.options import black_scholes, option_delta

# Calculate option price using Black-Scholes
price = black_scholes(
    stock_price=100,
    strike_price=95,
    time_to_expiry=0.5,
    risk_free_rate=0.02,
    volatility=0.25,
    option_type='call'
)
print(f"Call option price: ${price:.2f}")

# Calculate option delta
delta = option_delta(
    stock_price=100,
    strike_price=95,
    time_to_expiry=0.5,
    risk_free_rate=0.02,
    volatility=0.25,
    option_type='call'
)
print(f"Call option delta: {delta:.4f}")
```

## Command-Line Tools

PyFi Finance provides the following command-line tools:

### Compound Interest Calculator

```bash
compound-interest --principal 1000 --rate 0.05 --time 5 --periods 1
```

### Option Price Calculator

```bash
option-price --stock-price 100 --strike-price 95 --time 0.5 --rate 0.02 --volatility 0.25 --type call --show-delta
```

### Portfolio Optimizer

```bash
portfolio-optimize --returns 0.05 0.1 0.15 --cov-matrix 0.04 0.02 0.01 0.02 0.09 0.03 0.01 0.03 0.16 --risk-free-rate 0.01
```

### Troubleshooting Command-Line Tools

If you encounter a "'command' is not recognized" error when trying to use the command-line tools:

1. **Make sure the package is installed correctly**:
   ```bash
   pip install pyfi-finance
   ```

2. **Verify Python's Scripts directory is in your PATH**:
   - On Windows, this is typically: `C:\Users\<username>\AppData\Local\Programs\Python\Python3xx\Scripts\`
   - On Unix/Linux/Mac: `/usr/local/bin/` or `~/.local/bin/`

3. **Open a new command prompt/terminal** after installation to refresh the PATH

4. **Use the full path to the command** if necessary:
   ```bash
   # Windows
   C:\Users\<username>\AppData\Local\Programs\Python\Python3xx\Scripts\compound-interest.exe --principal 1000 --rate 0.05 --time 5
   
   # Unix/Linux/Mac
   /usr/local/bin/compound-interest --principal 1000 --rate 0.05 --time 5
   ```

5. **Verify the scripts were installed** by checking the Scripts directory:
   ```bash
   # Windows
   dir C:\Users\<username>\AppData\Local\Programs\Python\Python3xx\Scripts\compound-interest*
   
   # Unix/Linux/Mac
   ls -la /usr/local/bin/compound-interest*
   ```

## License

MIT License