/
dimaWebexplorer
/
investmentAssistant
Обзор
Документация
Войти
/
dimaWebexplorer
/
investmentAssistant
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
llmcode
ml/passive.py
83 строки
4 KB
Дима
added repo
24 окт 2025, 15:01
24 окт 2025, 15:01
789bb2d
Код
Авторство
О чём код?
def calculate_deposit_and_schedule(future_value, annual_rate, years, frequency=12): """ Рассчитывает сумму регулярного внесения и график накопления. Args: future_value (float): Будущая стоимость (цена товара в будущем, FV). annual_rate (float): Годовая ставка доходности инвестиционного портфеля (i) в виде десятичной дроби. years (int): Количество лет до достижения цели (n). frequency (int, optional): Количество внесений в год (по умолчанию 12 для ежемесячных). Returns: tuple: (regular_deposit, schedule_list) - regular_deposit (float): Сумма регулярного внесения за период. - schedule_list (list): Список кортежей (год, накопленная_сумма_на_конец_года). """ rate_per_period = annual_rate / frequency total_periods = years * frequency # Проверка на нулевую ставку, чтобы избежать деления на ноль if rate_per_period == 0: regular_deposit = future_value / total_periods # Для нулевой ставки график простой: сумма = внесение * количество_периодов_в_году * год schedule = [] for year in range(1, years + 1): periods_this_year = year * frequency accumulated = regular_deposit * periods_this_year schedule.append((year, accumulated)) return regular_deposit, schedule # Применяем формулу: R = FV * i / ((1 + i)^n - 1) # где i - ставка за период, n - количество периодов numerator = future_value * rate_per_period denominator = (1 + rate_per_period) ** total_periods - 1 regular_deposit = numerator / denominator # Рассчитываем график накопления schedule = [] for year in range(1, years + 1): periods_up_to_year = year * frequency # FV_year = R * [ ( (1 + i)^n_year - 1 ) / i ] accumulated_up_to_year = regular_deposit * ( ( (1 + rate_per_period) ** periods_up_to_year - 1 ) / rate_per_period ) schedule.append((year, accumulated_up_to_year)) return regular_deposit, schedule # --- Пример использования --- # Данные из листа "пассивный доход" (второй лист) capital_needed = 3_100_891 # FV (G7) required_rate = 0.1612 # i (G5) years_to_save = 5 # n (G4) # Рассчитываем ежемесячное внесение и график monthly_deposit, accumulation_schedule = calculate_deposit_and_schedule( capital_needed, required_rate, years_to_save, frequency=12 ) print(f"Цель накопления: {capital_needed:,}") print(f"Годовая ставка: {required_rate*100:.2f}%") print(f"Количество лет: {years_to_save}") print(f"Ежемесячный взнос: {monthly_deposit:.2f}") print("\nГрафик накопления (в конце каждого года):") for year, amount in accumulation_schedule: print(f"Год {year}: {amount:.2f}") print("\n---" * 10) # Данные из листа "накопления" (первый лист) savings_goal = 3_100_891 # FV savings_rate = 0.1612 # i (16.09%) savings_years = 5 # n monthly_deposit2, accumulation_schedule2 = calculate_deposit_and_schedule( savings_goal, savings_rate, savings_years, frequency=12 ) print(f"Цель накопления: {savings_goal:,}") print(f"Годовая ставка: {savings_rate*100:.2f}%") print(f"Количество лет: {savings_years}") print(f"Ежемесячный взнос: {monthly_deposit2:.2f}") print("\nГрафик накопления (в конце каждого года):") for year, amount in accumulation_schedule2: print(f"Год {year}: {amount:.2f}")