Spaces:
Sleeping
Sleeping
Download utils.py from Swobby/SellingCoveredCalls: direct link, hf CLI and curl.
- Browser
- Download file 935 Bytes
-
https://huggingface.co/spaces/Swobby/SellingCoveredCalls/resolve/main/utils.py
- Command line
-
hf download hf://spaces/Swobby/SellingCoveredCalls/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/Swobby/SellingCoveredCalls/resolve/main/utils.py
935 Bytes
| import tkinter as tk | |
| def validate_numeric_input(P): | |
| """Validate that input is a positive number or empty.""" | |
| if P == "": | |
| return True # Allow empty input | |
| try: | |
| value = float(P) | |
| return value >= 0 | |
| except ValueError: | |
| return False | |
| def format_currency(value): | |
| """Format a number as currency with two decimal places.""" | |
| return f"${value:,.2f}" | |
| def calculate_dividend_income(amount, quantity, frequency, days): | |
| """Calculate total dividend income over the given period.""" | |
| # Map frequency to number of payments per year | |
| freq_map = {"Monthly": 12, "Quarterly": 4, "Annually": 1} | |
| payments_per_year = freq_map.get(frequency, 0) | |
| if payments_per_year == 0: | |
| return 0 # Invalid frequency | |
| # Calculate the number of payments within the given days | |
| payments = (days / 365) * payments_per_year | |
| return amount * quantity * payments | |