| |
| |
| |
| |
| from collections import namedtuple |
| |
| |
| RedemptionRate = namedtuple("RedemptionRate", ["days", "rate"]) |
| |
| |
| def calculate_costs(P, T, F_A, M_A, S_A, T_A, R_A, M_C, S_C, T_C, R_C): |
| |
| C_A = P * F_A + P * (M_A + S_A + T_A) * (T / 365) + P * R_A(T) |
| |
| C_C = P * (M_C + S_C + T_C) * (T / 365) + P * R_C(T) |
| return C_A, C_C |
| |
| |
| def redemption_fee_A(T, redemption_rates_A): |
| for rate in redemption_rates_A: |
| if T <= rate.days: |
| return rate.rate |
| return 0 |
| |
| |
| def redemption_fee_C(T, redemption_rates_C): |
| for rate in redemption_rates_C: |
| if T <= rate.days: |
| return rate.rate |
| return 0 |
| |
| |
| |
| P = 10000 |
| |
| |
| T_values = [ |
| 7, |
| 8, |
| 30, |
| 31, |
| 60, |
| 61, |
| 90, |
| 91, |
| 180, |
| 181, |
| 365, |
| 366, |
| 730, |
| ] |
| |
| |
| F_A = 0.05 / 100 |
| M_A = 0.15 / 100 |
| T_A = 0.05 / 100 |
| S_A = 0 / 100 |
| |
| |
| M_C = 0.15 / 100 |
| T_C = 0.05 / 100 |
| S_C = 0.1 / 100 |
| |
| |
| redemption_rates_A = [ |
| RedemptionRate(days=7, rate=1.5 / 100), |
| RedemptionRate(days=30, rate=0.1 / 100), |
| ] |
| |
| |
| redemption_rates_C = [ |
| RedemptionRate(days=7, rate=1.5 / 100), |
| RedemptionRate(days=30, rate=0 / 100), |
| ] |
| |
| print( |
| f"{'持有时间(天)':<10} {'A类基金总成本':<10} {'C类基金总成本':<10} {'更便宜的基金':<10}" |
| ) |
| print("=" * 65) |
| |
| recommendation_threshold = None |
| |
| for T in T_values: |
| C_A, C_C = calculate_costs( |
| P, |
| T, |
| F_A, |
| M_A, |
| S_A, |
| T_A, |
| lambda T: redemption_fee_A(T, redemption_rates_A), |
| M_C, |
| S_C, |
| T_C, |
| lambda T: redemption_fee_C(T, redemption_rates_C), |
| ) |
| cheaper_fund = "A类" if C_A < C_C else "C类" |
| print(f"{T:<15} {C_A:<20.2f} {C_C:<20.2f} {cheaper_fund:<15}") |
| if recommendation_threshold is None and C_A < C_C: |
| recommendation_threshold = T |
| |
| if recommendation_threshold is None: |
| recommendation_threshold = "所有持有时间均推荐C类" |
| else: |
| |
| for T in range( |
| max(recommendation_threshold - 30, 0), recommendation_threshold + 30 |
| ): |
| C_A, C_C = calculate_costs( |
| P, |
| T, |
| F_A, |
| M_A, |
| S_A, |
| T_A, |
| lambda T: redemption_fee_A(T, redemption_rates_A), |
| M_C, |
| S_C, |
| T_C, |
| lambda T: redemption_fee_C(T, redemption_rates_C), |
| ) |
| if C_A < C_C: |
| recommendation_threshold = T |
| break |
| |
| print("=" * 65) |
| if isinstance(recommendation_threshold, int): |
| print( |
| f"大于{recommendation_threshold}天推荐A类,小于等于{recommendation_threshold}天推荐C类" |
| ) |
| else: |
| print(recommendation_threshold) |
| |
输出
| 持有时间(天) A类基金总成本 C类基金总成本 更便宜的基金 |
| ================================================================= |
| 7 155.38 150.58 C类 |
| 8 15.44 0.66 C类 |
| 30 16.64 2.47 C类 |
| 31 6.70 2.55 C类 |
| 60 8.29 4.93 C类 |
| 61 8.34 5.01 C类 |
| 90 9.93 7.40 C类 |
| 91 9.99 7.48 C类 |
| 180 14.86 14.79 C类 |
| 181 14.92 14.88 C类 |
| 365 25.00 30.00 A类 |
| 366 25.05 30.08 A类 |
| 730 45.00 60.00 A类 |
| ================================================================= |
| 大于335天推荐A类,小于等于335天推荐C类 |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)