(34,'数值结果超出范围')正在使用scipy计算年百分比率

p3rjfoxz  于 2022-11-10  发布在  其他
关注(0)|答案(1)|浏览(174)

我尝试用Python使用scipy库和牛顿方法来求解年百分比率。在某个点上,Python达到了最大Python浮点数范围,求解下面的方程:

下面是一个示例代码,其中的数据失败了。有没有什么我可以使用的(间隔等),能够解决这个方程?

from scipy.optimize import newton

class ARP:
    def __init__(self):
        self.year_days = 365
        self.table = [[0, 416.0, '2022-04-01', 0, 0, 0, 0, 0], [1, 75.92, '2022-04-02', 1, 1, 0, 0, 0], [2, 75.92, '2022-05-02', 30, 1, 0, 1, 0], [3, 90.92, '2022-06-02', 31, 1, 0, 2, 0], [4, 75.92, '2022-07-02', 30, 1, 0, 3, 0], [5, 75.92, '2022-08-02', 31, 1, 0, 4, 0], [6, 90.92, '2022-09-02', 31, 1, 0, 5, 0], [7, 75.92, '2022-10-02', 30, 1, 0, 6, 0], [8, 90.92, '2022-11-02', 31, 1, 0, 7, 0], [9, 75.92, '2022-12-02', 30, 1, 0, 8, 0], [10, 75.92, '2023-01-02', 31, 1, 0, 9, 0], [11, 90.92, '2023-02-02', 31, 1, 0, 10, 0], [12, 75.92, '2023-03-02', 28, 1, 0, 11, 0], [13, 90.92, '2023-04-02', 31, 1, 0, 12, 0], [14, 782.9, '2023-05-02', 30, 1, 0, 13, 0], [15, 732.9, '2023-06-02', 31, 1, 0, 14, 0], [16, 732.9, '2023-07-02', 30, 1, 0, 15, 0], [17, 732.9, '2023-08-02', 31, 1, 0, 16, 0], [18, 732.9, '2023-09-02', 31, 1, 0, 17, 0], [19, 732.9, '2023-10-02', 30, 1, 0, 18, 0], [20, 732.9, '2023-11-02', 31, 1, 0, 19, 0], [21, 732.9, '2023-12-02', 30, 1, 0, 20, 0], [22, 732.9, '2024-01-02', 31, 1, 0, 21, 0], [23, 732.9, '2024-02-02', 31, 1, 0, 22, 0], [24, 732.9, '2024-03-02', 29, 1, 0, 23, 0], [25, 732.9, '2024-04-02', 31, 1, 0, 24, 0], [26, 782.9, '2024-05-02', 30, 1, 0, 25, 0], [27, 732.9, '2024-06-02', 31, 1, 0, 26, 0], [28, 732.9, '2024-07-02', 30, 1, 0, 27, 0], [29, 732.9, '2024-08-02', 31, 1, 0, 28, 0], [30, 732.9, '2024-09-02', 31, 1, 0, 29, 0], [31, 732.9, '2024-10-02', 30, 1, 0, 30, 0], [32, 732.9, '2024-11-02', 31, 1, 0, 31, 0], [33, 732.9, '2024-12-02', 30, 1, 0, 32, 0], [34, 732.9, '2025-01-02', 31, 1, 0, 33, 0], [35, 732.9, '2025-02-02', 31, 1, 0, 34, 0], [36, 732.9, '2025-03-02', 28, 1, 0, 35, 0], [37, 732.9, '2025-04-02', 31, 1, 0, 36, 0], [38, 782.9, '2025-05-02', 30, 1, 0, 37, 0], [39, 732.9, '2025-06-02', 31, 1, 0, 38, 0], [40, 732.9, '2025-07-02', 30, 1, 0, 39, 0], [41, 732.9, '2025-08-02', 31, 1, 0, 40, 0], [42, 732.9, '2025-09-02', 31, 1, 0, 41, 0], [43, 732.9, '2025-10-02', 30, 1, 0, 42, 0], [44, 732.9, '2025-11-02', 31, 1, 0, 43, 0], [45, 732.9, '2025-12-02', 30, 1, 0, 44, 0], [46, 732.9, '2026-01-02', 31, 1, 0, 45, 0], [47, 732.9, '2026-02-02', 31, 1, 0, 46, 0], [48, 732.9, '2026-03-02', 28, 1, 0, 47, 0], [49, 732.9, '2026-04-02', 31, 1, 0, 48, 0], [50, 782.9, '2026-05-02', 30, 1, 0, 49, 0], [51, 732.9, '2026-06-02', 31, 1, 0, 50, 0], [52, 732.9, '2026-07-02', 30, 1, 0, 51, 0], [53, 732.9, '2026-08-02', 31, 1, 0, 52, 0], [54, 732.9, '2026-09-02', 31, 1, 0, 53, 0], [55, 732.9, '2026-10-02', 30, 1, 0, 54, 0], [56, 732.9, '2026-11-02', 31, 1, 0, 55, 0], [57, 732.9, '2026-12-02', 30, 1, 0, 56, 0], [58, 732.9, '2027-01-02', 31, 1, 0, 57, 0], [59, 732.9, '2027-02-02', 31, 1, 0, 58, 0], [60, 732.9, '2027-03-02', 28, 1, 0, 59, 0], [61, 732.9, '2027-04-02', 31, 1, 0, 60, 0], [62, 782.9, '2027-05-02', 30, 1, 0, 61, 0], [63, 732.9, '2027-06-02', 31, 1, 0, 62, 0], [64, 732.9, '2027-07-02', 30, 1, 0, 63, 0], [65, 732.9, '2027-08-02', 31, 1, 0, 64, 0], [66, 732.9, '2027-09-02', 31, 1, 0, 65, 0], [67, 732.9, '2027-10-02', 30, 1, 0, 66, 0], [68, 732.9, '2027-11-02', 31, 1, 0, 67, 0], [69, 732.9, '2027-12-02', 30, 1, 0, 68, 0], [70, 732.9, '2028-01-02', 31, 1, 0, 69, 0], [71, 732.9, '2028-02-02', 31, 1, 0, 70, 0], [72, 732.9, '2028-03-02', 29, 1, 0, 71, 0], [73, 732.9, '2028-04-02', 31, 1, 0, 72, 0], [74, 782.9, '2028-05-02', 30, 1, 0, 73, 0], [75, 732.9, '2028-06-02', 31, 1, 0, 74, 0], [76, 732.9, '2028-07-02', 30, 1, 0, 75, 0], [77, 732.9, '2028-08-02', 31, 1, 0, 76, 0], [78, 732.9, '2028-09-02', 31, 1, 0, 77, 0], [79, 732.9, '2028-10-02', 30, 1, 0, 78, 0], [80, 732.9, '2028-11-02', 31, 1, 0, 79, 0], [81, 732.9, '2028-12-02', 30, 1, 0, 80, 0], [82, 732.9, '2029-01-02', 31, 1, 0, 81, 0], [83, 732.9, '2029-02-02', 31, 1, 0, 82, 0], [84, 732.9, '2029-03-02', 28, 1, 0, 83, 0], [85, 732.9, '2029-04-02', 31, 1, 0, 84, 0], [86, 782.9, '2029-05-02', 30, 1, 0, 85, 0], [87, 732.9, '2029-06-02', 31, 1, 0, 86, 0], [88, 732.9, '2029-07-02', 30, 1, 0, 87, 0], [89, 732.9, '2029-08-02', 31, 1, 0, 88, 0], [90, 732.9, '2029-09-02', 31, 1, 0, 89, 0], [91, 732.9, '2029-10-02', 30, 1, 0, 90, 0], [92, 732.9, '2029-11-02', 31, 1, 0, 91, 0], [93, 732.9, '2029-12-02', 30, 1, 0, 92, 0], [94, 732.9, '2030-01-02', 31, 1, 0, 93, 0], [95, 732.9, '2030-02-02', 31, 1, 0, 94, 0], [96, 732.9, '2030-03-02', 28, 1, 0, 95, 0], [97, 732.9, '2030-04-02', 31, 1, 0, 96, 0], [98, 782.9, '2030-05-02', 30, 1, 0, 97, 0], [99, 732.9, '2030-06-02', 31, 1, 0, 98, 0], [100, 732.9, '2030-07-02', 30, 1, 0, 99, 0], [101, 732.9, '2030-08-02', 31, 1, 0, 100, 0], [102, 732.9, '2030-09-02', 31, 1, 0, 101, 0], [103, 732.9, '2030-10-02', 30, 1, 0, 102, 0], [104, 732.9, '2030-11-02', 31, 1, 0, 103, 0], [105, 732.9, '2030-12-02', 30, 1, 0, 104, 0], [106, 732.9, '2031-01-02', 31, 1, 0, 105, 0], [107, 732.9, '2031-02-02', 31, 1, 0, 106, 0], [108, 732.9, '2031-03-02', 28, 1, 0, 107, 0], [109, 732.9, '2031-04-02', 31, 1, 0, 108, 0], [110, 782.9, '2031-05-02', 30, 1, 0, 109, 0], [111, 732.9, '2031-06-02', 31, 1, 0, 110, 0], [112, 732.9, '2031-07-02', 30, 1, 0, 111, 0], [113, 732.9, '2031-08-02', 31, 1, 0, 112, 0], [114, 732.9, '2031-09-02', 31, 1, 0, 113, 0], [115, 732.9, '2031-10-02', 30, 1, 0, 114, 0], [116, 732.9, '2031-11-02', 31, 1, 0, 115, 0], [117, 732.9, '2031-12-02', 30, 1, 0, 116, 0], [118, 732.9, '2032-01-02', 31, 1, 0, 117, 0], [119, 732.9, '2032-02-02', 31, 1, 0, 118, 0], [120, 732.9, '2032-03-02', 29, 1, 0, 119, 0], [121, 732.9, '2032-04-02', 31, 1, 0, 120, 0], [122, 782.9, '2032-05-02', 30, 1, 0, 121, 0], [123, 732.9, '2032-06-02', 31, 1, 0, 122, 0], [124, 732.9, '2032-07-02', 30, 1, 0, 123, 0], [125, 732.9, '2032-08-02', 31, 1, 0, 124, 0], [126, 732.9, '2032-09-02', 31, 1, 0, 125, 0], [127, 732.9, '2032-10-02', 30, 1, 0, 126, 0], [128, 732.9, '2032-11-02', 31, 1, 0, 127, 0], [129, 732.9, '2032-12-02', 30, 1, 0, 128, 0], [130, 732.9, '2033-01-02', 31, 1, 0, 129, 0], [131, 732.9, '2033-02-02', 31, 1, 0, 130, 0], [132, 732.9, '2033-03-02', 28, 1, 0, 131, 0], [133, 732.9, '2033-04-02', 31, 1, 0, 132, 0], [134, 782.9, '2033-05-02', 30, 1, 0, 133, 0], [135, 732.9, '2033-06-02', 31, 1, 0, 134, 0], [136, 732.9, '2033-07-02', 30, 1, 0, 135, 0], [137, 732.9, '2033-08-02', 31, 1, 0, 136, 0], [138, 732.9, '2033-09-02', 31, 1, 0, 137, 0], [139, 732.9, '2033-10-02', 30, 1, 0, 138, 0], [140, 732.9, '2033-11-02', 31, 1, 0, 139, 0], [141, 732.9, '2033-12-02', 30, 1, 0, 140, 0], [142, 732.9, '2034-01-02', 31, 1, 0, 141, 0], [143, 732.9, '2034-02-02', 31, 1, 0, 142, 0], [144, 732.9, '2034-03-02', 28, 1, 0, 143, 0], [145, 732.9, '2034-04-02', 31, 1, 0, 144, 0], [146, 782.9, '2034-05-02', 30, 1, 0, 145, 0], [147, 732.9, '2034-06-02', 31, 1, 0, 146, 0], [148, 732.9, '2034-07-02', 30, 1, 0, 147, 0], [149, 732.9, '2034-08-02', 31, 1, 0, 148, 0], [150, 732.9, '2034-09-02', 31, 1, 0, 149, 0], [151, 732.9, '2034-10-02', 30, 1, 0, 150, 0], [152, 732.9, '2034-11-02', 31, 1, 0, 151, 0], [153, 732.9, '2034-12-02', 30, 1, 0, 152, 0], [154, 732.9, '2035-01-02', 31, 1, 0, 153, 0], [155, 732.9, '2035-02-02', 31, 1, 0, 154, 0], [156, 732.9, '2035-03-02', 28, 1, 0, 155, 0], [157, 732.9, '2035-04-02', 31, 1, 0, 156, 0], [158, 782.9, '2035-05-02', 30, 1, 0, 157, 0], [159, 732.9, '2035-06-02', 31, 1, 0, 158, 0], [160, 732.9, '2035-07-02', 30, 1, 0, 159, 0], [161, 732.9, '2035-08-02', 31, 1, 0, 160, 0], [162, 732.9, '2035-09-02', 31, 1, 0, 161, 0], [163, 732.9, '2035-10-02', 30, 1, 0, 162, 0], [164, 732.9, '2035-11-02', 31, 1, 0, 163, 0], [165, 732.9, '2035-12-02', 30, 1, 0, 164, 0], [166, 732.9, '2036-01-02', 31, 1, 0, 165, 0], [167, 732.9, '2036-02-02', 31, 1, 0, 166, 0], [168, 732.9, '2036-03-02', 29, 1, 0, 167, 0], [169, 732.9, '2036-04-02', 31, 1, 0, 168, 0], [170, 782.9, '2036-05-02', 30, 1, 0, 169, 0], [171, 732.9, '2036-06-02', 31, 1, 0, 170, 0], [172, 732.9, '2036-07-02', 30, 1, 0, 171, 0], [173, 732.9, '2036-08-02', 31, 1, 0, 172, 0], [174, 732.9, '2036-09-02', 31, 1, 0, 173, 0], [175, 732.9, '2036-10-02', 30, 1, 0, 174, 0], [176, 732.9, '2036-11-02', 31, 1, 0, 175, 0], [177, 732.9, '2036-12-02', 30, 1, 0, 176, 0], [178, 732.9, '2037-01-02', 31, 1, 0, 177, 0], [179, 732.9, '2037-02-02', 31, 1, 0, 178, 0], [180, 732.9, '2037-03-02', 28, 1, 0, 179, 0], [181, 732.9, '2037-04-02', 31, 1, 0, 180, 0], [182, 782.9, '2037-05-02', 30, 1, 0, 181, 0], [183, 732.9, '2037-06-02', 31, 1, 0, 182, 0], [184, 732.9, '2037-07-02', 30, 1, 0, 183, 0], [185, 732.9, '2037-08-02', 31, 1, 0, 184, 0], [186, 732.9, '2037-09-02', 31, 1, 0, 185, 0], [187, 732.9, '2037-10-02', 30, 1, 0, 186, 0], [188, 732.9, '2037-11-02', 31, 1, 0, 187, 0], [189, 732.9, '2037-12-02', 30, 1, 0, 188, 0], [190, 732.9, '2038-01-02', 31, 1, 0, 189, 0], [191, 732.9, '2038-02-02', 31, 1, 0, 190, 0], [192, 732.9, '2038-03-02', 28, 1, 0, 191, 0], [193, 732.9, '2038-04-02', 31, 1, 0, 192, 0], [194, 782.9, '2038-05-02', 30, 1, 0, 193, 0], [195, 732.9, '2038-06-02', 31, 1, 0, 194, 0], [196, 732.9, '2038-07-02', 30, 1, 0, 195, 0], [197, 732.9, '2038-08-02', 31, 1, 0, 196, 0], [198, 732.9, '2038-09-02', 31, 1, 0, 197, 0], [199, 732.9, '2038-10-02', 30, 1, 0, 198, 0], [200, 732.9, '2038-11-02', 31, 1, 0, 199, 0], [201, 732.9, '2038-12-02', 30, 1, 0, 200, 0], [202, 732.9, '2039-01-02', 31, 1, 0, 201, 0], [203, 732.9, '2039-02-02', 31, 1, 0, 202, 0], [204, 732.9, '2039-03-02', 28, 1, 0, 203, 0], [205, 732.9, '2039-04-02', 31, 1, 0, 204, 0], [206, 782.9, '2039-05-02', 30, 1, 0, 205, 0], [207, 732.9, '2039-06-02', 31, 1, 0, 206, 0], [208, 732.9, '2039-07-02', 30, 1, 0, 207, 0], [209, 732.9, '2039-08-02', 31, 1, 0, 208, 0], [210, 732.9, '2039-09-02', 31, 1, 0, 209, 0], [211, 732.9, '2039-10-02', 30, 1, 0, 210, 0], [212, 732.9, '2039-11-02', 31, 1, 0, 211, 0], [213, 732.9, '2039-12-02', 30, 1, 0, 212, 0], [214, 732.9, '2040-01-02', 31, 1, 0, 213, 0], [215, 732.9, '2040-02-02', 31, 1, 0, 214, 0], [216, 732.9, '2040-03-02', 29, 1, 0, 215, 0], [217, 732.9, '2040-04-02', 31, 1, 0, 216, 0], [218, 782.9, '2040-05-02', 30, 1, 0, 217, 0], [219, 732.9, '2040-06-02', 31, 1, 0, 218, 0], [220, 732.9, '2040-07-02', 30, 1, 0, 219, 0], [221, 732.9, '2040-08-02', 31, 1, 0, 220, 0], [222, 732.9, '2040-09-02', 31, 1, 0, 221, 0], [223, 732.9, '2040-10-02', 30, 1, 0, 222, 0], [224, 732.9, '2040-11-02', 31, 1, 0, 223, 0], [225, 732.9, '2040-12-02', 30, 1, 0, 224, 0], [226, 732.9, '2041-01-02', 31, 1, 0, 225, 0], [227, 732.9, '2041-02-02', 31, 1, 0, 226, 0], [228, 732.9, '2041-03-02', 28, 1, 0, 227, 0], [229, 732.9, '2041-04-02', 31, 1, 0, 228, 0], [230, 782.9, '2041-05-02', 30, 1, 0, 229, 0], [231, 732.9, '2041-06-02', 31, 1, 0, 230, 0], [232, 732.9, '2041-07-02', 30, 1, 0, 231, 0], [233, 732.9, '2041-08-02', 31, 1, 0, 232, 0], [234, 732.9, '2041-09-02', 31, 1, 0, 233, 0], [235, 732.9, '2041-10-02', 30, 1, 0, 234, 0], [236, 732.9, '2041-11-02', 31, 1, 0, 235, 0], [237, 732.9, '2041-12-02', 30, 1, 0, 236, 0], [238, 732.9, '2042-01-02', 31, 1, 0, 237, 0], [239, 732.9, '2042-02-02', 31, 1, 0, 238, 0], [240, 732.9, '2042-03-02', 28, 1, 0, 239, 0], [241, 732.9, '2042-04-02', 31, 1, 0, 240, 0], [242, 782.9, '2042-05-02', 30, 1, 0, 241, 0], [243, 732.9, '2042-06-02', 31, 1, 0, 242, 0], [244, 732.9, '2042-07-02', 30, 1, 0, 243, 0], [245, 732.9, '2042-08-02', 31, 1, 0, 244, 0], [246, 732.9, '2042-09-02', 31, 1, 0, 245, 0], [247, 732.9, '2042-10-02', 30, 1, 0, 246, 0], [248, 732.9, '2042-11-02', 31, 1, 0, 247, 0], [249, 732.9, '2042-12-02', 30, 1, 0, 248, 0], [250, 732.9, '2043-01-02', 31, 1, 0, 249, 0], [251, 732.9, '2043-02-02', 31, 1, 0, 250, 0], [252, 732.9, '2043-03-02', 28, 1, 0, 251, 0], [253, 732.9, '2043-04-02', 31, 1, 0, 252, 0], [254, 782.9, '2043-05-02', 30, 1, 0, 253, 0], [255, 732.9, '2043-06-02', 31, 1, 0, 254, 0], [256, 732.9, '2043-07-02', 30, 1, 0, 255, 0], [257, 732.9, '2043-08-02', 31, 1, 0, 256, 0], [258, 732.9, '2043-09-02', 31, 1, 0, 257, 0], [259, 732.9, '2043-10-02', 30, 1, 0, 258, 0], [260, 732.9, '2043-11-02', 31, 1, 0, 259, 0], [261, 732.9, '2043-12-02', 30, 1, 0, 260, 0], [262, 732.9, '2044-01-02', 31, 1, 0, 261, 0], [263, 732.9, '2044-02-02', 31, 1, 0, 262, 0], [264, 732.9, '2044-03-02', 29, 1, 0, 263, 0], [265, 732.9, '2044-04-02', 31, 1, 0, 264, 0], [266, 782.9, '2044-05-02', 30, 1, 0, 265, 0], [267, 732.9, '2044-06-02', 31, 1, 0, 266, 0], [268, 732.9, '2044-07-02', 30, 1, 0, 267, 0], [269, 732.9, '2044-08-02', 31, 1, 0, 268, 0], [270, 732.9, '2044-09-02', 31, 1, 0, 269, 0], [271, 732.9, '2044-10-02', 30, 1, 0, 270, 0], [272, 732.9, '2044-11-02', 31, 1, 0, 271, 0], [273, 732.9, '2044-12-02', 30, 1, 0, 272, 0], [274, 732.9, '2045-01-02', 31, 1, 0, 273, 0], [275, 732.9, '2045-02-02', 31, 1, 0, 274, 0], [276, 732.9, '2045-03-02', 28, 1, 0, 275, 0], [277, 732.9, '2045-04-02', 31, 1, 0, 276, 0], [278, 782.9, '2045-05-02', 30, 1, 0, 277, 0], [279, 732.9, '2045-06-02', 31, 1, 0, 278, 0], [280, 732.9, '2045-07-02', 30, 1, 0, 279, 0], [281, 732.9, '2045-08-02', 31, 1, 0, 280, 0], [282, 732.9, '2045-09-02', 31, 1, 0, 281, 0], [283, 732.9, '2045-10-02', 30, 1, 0, 282, 0], [284, 732.9, '2045-11-02', 31, 1, 0, 283, 0], [285, 732.9, '2045-12-02', 30, 1, 0, 284, 0], [286, 732.9, '2046-01-02', 31, 1, 0, 285, 0], [287, 732.9, '2046-02-02', 31, 1, 0, 286, 0], [288, 732.9, '2046-03-02', 28, 1, 0, 287, 0], [289, 732.9, '2046-04-02', 31, 1, 0, 288, 0], [290, 782.9, '2046-05-02', 30, 1, 0, 289, 0], [291, 732.9, '2046-06-02', 31, 1, 0, 290, 0], [292, 732.9, '2046-07-02', 30, 1, 0, 291, 0], [293, 732.9, '2046-08-02', 31, 1, 0, 292, 0], [294, 732.9, '2046-09-02', 31, 1, 0, 293, 0], [295, 732.9, '2046-10-02', 30, 1, 0, 294, 0], [296, 732.9, '2046-11-02', 31, 1, 0, 295, 0], [297, 732.9, '2046-12-02', 30, 1, 0, 296, 0], [298, 732.9, '2047-01-02', 31, 1, 0, 297, 0], [299, 732.9, '2047-02-02', 31, 1, 0, 298, 0], [300, 732.9, '2047-03-02', 28, 1, 0, 299, 0], [301, 732.9, '2047-04-02', 31, 1, 0, 300, 0], [302, 782.9, '2047-05-02', 30, 1, 0, 301, 0], [303, 732.9, '2047-06-02', 31, 1, 0, 302, 0], [304, 732.9, '2047-07-02', 30, 1, 0, 303, 0], [305, 732.9, '2047-08-02', 31, 1, 0, 304, 0], [306, 732.9, '2047-09-02', 31, 1, 0, 305, 0], [307, 732.9, '2047-10-02', 30, 1, 0, 306, 0], [308, 732.9, '2047-11-02', 31, 1, 0, 307, 0], [309, 732.9, '2047-12-02', 30, 1, 0, 308, 0], [310, 732.9, '2048-01-02', 31, 1, 0, 309, 0], [311, 732.9, '2048-02-02', 31, 1, 0, 310, 0], [312, 732.9, '2048-03-02', 29, 1, 0, 311, 0], [313, 732.9, '2048-04-02', 31, 1, 0, 312, 0], [314, 782.9, '2048-05-02', 30, 1, 0, 313, 0], [315, 732.9, '2048-06-02', 31, 1, 0, 314, 0], [316, 732.9, '2048-07-02', 30, 1, 0, 315, 0], [317, 732.9, '2048-08-02', 31, 1, 0, 316, 0], [318, 732.9, '2048-09-02', 31, 1, 0, 317, 0], [319, 732.9, '2048-10-02', 30, 1, 0, 318, 0], [320, 732.9, '2048-11-02', 31, 1, 0, 319, 0], [321, 732.9, '2048-12-02', 30, 1, 0, 320, 0], [322, 732.9, '2049-01-02', 31, 1, 0, 321, 0], [323, 732.9, '2049-02-02', 31, 1, 0, 322, 0], [324, 732.9, '2049-03-02', 28, 1, 0, 323, 0], [325, 732.9, '2049-04-02', 31, 1, 0, 324, 0], [326, 782.9, '2049-05-02', 30, 1, 0, 325, 0], [327, 732.9, '2049-06-02', 31, 1, 0, 326, 0], [328, 732.9, '2049-07-02', 30, 1, 0, 327, 0], [329, 732.9, '2049-08-02', 31, 1, 0, 328, 0], [330, 732.9, '2049-09-02', 31, 1, 0, 329, 0], [331, 732.9, '2049-10-02', 30, 1, 0, 330, 0], [332, 732.9, '2049-11-02', 31, 1, 0, 331, 0], [333, 732.9, '2049-12-02', 30, 1, 0, 332, 0], [334, 732.9, '2050-01-02', 31, 1, 0, 333, 0], [335, 732.9, '2050-02-02', 31, 1, 0, 334, 0], [336, 732.9, '2050-03-02', 28, 1, 0, 335, 0], [337, 732.9, '2050-04-02', 31, 1, 0, 336, 0], [338, 782.9, '2050-05-02', 30, 1, 0, 337, 0], [339, 732.9, '2050-06-02', 31, 1, 0, 338, 0], [340, 732.9, '2050-07-02', 30, 1, 0, 339, 0], [341, 732.9, '2050-08-02', 31, 1, 0, 340, 0], [342, 732.9, '2050-09-02', 31, 1, 0, 341, 0], [343, 732.9, '2050-10-02', 30, 1, 0, 342, 0], [344, 732.9, '2050-11-02', 31, 1, 0, 343, 0], [345, 732.9, '2050-12-02', 30, 1, 0, 344, 0], [346, 732.9, '2051-01-02', 31, 1, 0, 345, 0], [347, 732.9, '2051-02-02', 31, 1, 0, 346, 0], [348, 732.9, '2051-03-02', 28, 1, 0, 347, 0], [349, 732.9, '2051-04-02', 31, 1, 0, 348, 0], [350, 782.9, '2051-05-02', 30, 1, 0, 349, 0], [351, 732.9, '2051-06-02', 31, 1, 0, 350, 0], [352, 732.9, '2051-07-02', 30, 1, 0, 351, 0], [353, 732.9, '2051-08-02', 31, 1, 0, 352, 0], [354, 732.9, '2051-09-02', 31, 1, 0, 353, 0], [355, 732.9, '2051-10-02', 30, 1, 0, 354, 0], [356, 732.9, '2051-11-02', 31, 1, 0, 355, 0], [357, 732.9, '2051-12-02', 30, 1, 0, 356, 0], [358, 732.9, '2052-01-02', 31, 1, 0, 357, 0], [359, 732.9, '2052-02-02', 31, 1, 0, 358, 0], [360, 732.9, '2052-03-02', 29, 1, 0, 359, 0], [361, 732.9, '2052-04-02', 31, 1, 0, 360, 0], [362, 782.9, '2052-05-02', 30, 1, 0, 361, 0], [363, 732.9, '2052-06-02', 31, 1, 0, 362, 0], [364, 732.9, '2052-07-02', 30, 1, 0, 363, 0], [365, 732.9, '2052-08-02', 31, 1, 0, 364, 0], [366, 732.9, '2052-09-02', 31, 1, 0, 365, 0], [367, 732.9, '2052-10-02', 30, 1, 0, 366, 0], [368, 732.9, '2052-11-02', 31, 1, 0, 367, 0], [369, 732.9, '2052-12-02', 30, 1, 0, 368, 0], [370, 732.9, '2053-01-02', 31, 1, 0, 369, 0], [371, 732.9, '2053-02-02', 31, 1, 0, 370, 0], [372, 732.9, '2053-03-02', 28, 1, 0, 371, 0], [373, 732.9, '2053-04-02', 31, 1, 0, 372, 0], [374, 726.66, '2053-05-02', 30, 1, 0, 373, 0]]
        self.drawing_calendar = [[0, '50000', '2022-04-01', 0, 0, 0, 0, 0], [1, '45000', '2022-06-13', 73, 30, 0, 5, 0], [2, '45000', '2022-08-25', 73, 72, 0, 6, 0], [3, '40000', '2022-11-06', 73, 72, 0, 7, 0], [4, '40000', '2023-01-18', 73, 72, 0, 8, 0], [5, '20000', '2023-04-01', 73, 72, 0, 9, 0]]

    def calculate_arp(self):

        try:
            result = newton(self.arp_general, 0)
            print("ARP result: ", result)
        except Exception as e:
            print(f"Calculation failed! Exception: {e}")

    def arp_general(self, x):

        left_sum = 0
        right_sum = 0

        for i in range(len(self.drawing_calendar)):
            amount = float(self.table[i][1])
            day_part = float(self.table[i][4] / self.year_days)
            week_part = float(self.table[i][5] / 52)
            month_part = float((self.table[i][6]) / 12)
            year_part = self.table[i][7]

            coef_pow = year_part + month_part + week_part + day_part
            left_sum += amount / ((1 + x)**coef_pow)

        for i in range(len(self.table)):
            amount = float(self.table[i][1])
            day_part = float(self.table[i][4] / self.year_days)
            week_part = float(self.table[i][5] / 52)
            month_part = float((self.table[i][6]) / 12)
            year_part = self.table[i][7]

            coef_pow = year_part + month_part + week_part + day_part
            right_sum += amount / ((1 + x)**coef_pow)

        return left_sum - right_sum

a = ARP()
a.calculate_arp()
eivgtgni

eivgtgni1#

我在朋友的帮助下发现了一个bug。问题是left_sum使用了错误的数据。它应该使用self.drawing_calendar而不是self.table中的数据。

相关问题