From 1b4d588c5270907e722362ec015f82c3558b6688 Mon Sep 17 00:00:00 2001 From: Dimitar Vanguelov Date: Mon, 19 Jun 2023 20:06:49 -0400 Subject: [PATCH 1/2] add numba implementation for newton irr --- Benchmarks/irr/python/python.py | 52 ++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/Benchmarks/irr/python/python.py b/Benchmarks/irr/python/python.py index 0874bb9..d6f7f4f 100644 --- a/Benchmarks/irr/python/python.py +++ b/Benchmarks/irr/python/python.py @@ -2,17 +2,23 @@ # https://github.com/better/irr/blob/d521607024226c215e569a63346e2d6ca0ff60da/irr/__init__.py # (couldn't get it to install via package manager) import timeit + import numpy +from numba import njit setup=''' -import numpy, math +import math + +import numpy +from numba import njit MAX_LOG_RATE = 1e3 BASE_TOL = 1e-12 cfs = [-7000,11.33137357858057, 11.167072336683004, 14.73988904111101, 14.543375011974934, 14.787026189603953, 12.220165229291128, 10.62228303189419, 10.2054439968351, 12.38830768146916, 11.55662975000198, 10.328454158492287, 11.12038681607141, 10.324480820201908, 10.198382859550456, 11.622094119543757, 12.273321426327541, 13.968817009905088, 14.633381040913772, 14.653117743106158, 14.75415942102587, 11.115621653400536, 12.491301011838484, 11.081360378007831, 12.332972598070072, 10.880589146045264, 10.235136200262108, 12.505550229750812, 11.250354442977768, 13.007688935886225, 10.949658164170005, 10.327509073165091, 12.081824327395134, 11.095672179619607, 12.879864014703418, 11.686291918815805, 10.487486433970597, 10.782904021875865, 10.828899614147883, 13.740734146503733, 13.070147160401934, 11.281533610255876, 14.608845949786723, 11.101609237726503, 13.6672383716922, 11.991725804610223, 14.223338394270746, 12.54775932654576, 11.669406707832616, 11.172531062630963, 14.797739369742395, 14.742002039355507, 11.26059357755014, 10.005760731173147, 13.166395327031115, 10.953541497765157, 13.85589184547591, 11.938616564984416, 12.602780339084227, 10.190660874910725, 12.62253014530776, 13.25618155360879, 11.909328696772635, 13.645695694839475, 10.771692737595489, 10.019159704029537, 12.748198733268266, 14.949945651485546, 10.471989762364004, 11.694659010236517, 10.840097149970063, 13.81959526563658, 13.725232362048477, 14.696971575480223, 14.061440252466008, 11.894097203077104, 11.623559529246583, 11.422764616449735, 11.911568770804685, 14.257873178733874, 11.908786512287042, 11.704867143116388, 13.547102659825594, 10.231510523063077, 12.580425576504725, 10.204318593593095, 10.839329475371066, 14.06382079409852, 14.741551103697574, 14.125100696255025, 10.534750441149983, 12.047335974087941, 12.040901005285527, 13.061055670703222, 12.033900288651994, 14.64914110907408, 14.74150289957578, 14.18198082748481, 12.64569352877869, 10.795441413087191, 12.32677569400135, 14.201284184243757, 12.198731964230793, 13.829237277802761, 12.88556220895728, 13.681945290090994, 11.310817183394416, 10.642344563381029, 12.001334393089806, 13.940994758512655, 14.588579514241378, 11.784013809882609, 14.857525454933082, 11.890304205798119, 14.163978789672555, 12.802006519405316, 10.453613727321805, 10.545421710663241, 13.860350461267206, 13.011623286218281, 12.529578764153623, 12.0682203481126, 12.222973006731433, 10.782217823800455, 14.815112126486351, 14.021264432689495, 13.907504381640877, 13.263889558252384, 13.886523931472032, 14.92463305217065, 10.39804588193537, 11.717727995106285, 13.475830384363098, 13.96526870747185, 12.537688951669926, 10.713851417257366, 12.651783539839993, 14.94145019017787, 11.298228878804299, 11.238462723076646, 12.54816626881003, 12.991279893628143, 12.938650960410705, 14.509841908929733, 13.061627992570637, 13.532302333363827, 10.87538595312562, 13.401986714313082, 14.452077231881011, 10.62775390563043, 10.259969609401132, 10.630066121172158, 10.67746807962661, 14.301509125704097, 12.248186770125802, 13.529935347104352, 12.214180545525151, 13.737238621655871, 14.935337045307609, 10.715008490421852, 13.792764627232366, 11.566835806502482, 13.381623410224446, 11.759551394829062, 14.46722368188435, 14.820860467933276, 14.367067474219198, 12.785099227552985, 12.125131138279556, 13.59004374972493, 11.035277329107453, 13.552102778902684, 11.167577469887052, 12.079972349457684, 14.78489299740463, 11.117948297108185, 11.81118834164748, 13.306337834666962, 14.61353141178894, 14.277193746539648, 12.166555805663473, 11.265160163436654, 10.362543406467916, 11.17487038814809, 13.221576830876275, 11.124927016257411, 11.778833269702968, 12.884165622590684, 11.70614082816003, 13.732507964152038, 13.562497475153835, 14.365673914585269, 11.218499437025232, 14.313161434674605, 10.84553935633242, 13.892594863691276, 12.905232048487619, 14.526707951361043, 11.151370775543134, 11.202538557418025, 14.351557380104524, 14.618321803616304, 13.450749033215105, 13.971103464192872, 12.453728166838555, 11.203648664519335, 13.354317055813262, 14.559195884990523, 13.853813999405409, 10.265888555997426, 11.740493314590367, 13.565808716032713, 14.465381469251845, 11.700055034584512, 13.666543210894279, 10.05828768839079, 13.793893081997751, 11.840407775390236, 14.292054186783561, 13.327715352294016, 13.176691551807002, 14.385175692391908, 14.385014460873183, 11.407277293369141, 14.231388088664055, 12.250059232161178, 14.86235229497673, 13.77507647192779, 12.896049896482687, 10.60002301502453, 13.447070421155189, 13.358321797846632, 11.21916910048809, 13.30255271341071, 13.493253069737648, 10.948637495146045, 10.001718613821161, 13.91551521108937, 11.581689906353411, 14.977887214372007, 14.65693440845071, 14.665474268673329, 12.691023502305779, 11.636579739013367, 13.145065301442465, 14.054029882788013, 12.872698520853412, 14.603129068297749, 14.939572657418722, 11.170995199160744, 11.847096639046411, 13.883460710012764, 10.126422540987893, 13.407267339989394, 10.421297015199778, 14.793530503055097, 14.009521709723277, 10.551203664546083, 13.606121157647152, 13.893115513324952, 12.387229455207336, 10.152726271083313, 10.857363093853683, 10.553311047158111, 14.48112608836534, 12.009660541892252, 10.562740549914857, 10.185345168077752, 10.610848424790655, 12.382686150676019, 12.70009488541087, 11.751661090276412, 11.18298540002945, 10.938505981462802, 14.11088111794641, 14.40865642716125, 12.87387852504945, 11.345425461857499, 13.450458614928777, 14.558969761971529, 11.784359157402896, 11.528844481965896, 12.841302594496753, 10.516217100119583, 12.034691758196473, 10.631794257379834, 14.71733657041019, 14.820479028358028, 14.780542929577692, 13.052248672850174, 13.437337644194365, 12.7734425699407, 12.709862021282632, 10.034620588718868, 10.850848229793126, 14.536407975610807, 11.155751652337214, 12.193467364682604, 13.089842912540833, 13.093755843694804, 13.963076758897023, 10.782746529071671, 10.57634443951439, 10.585652732773541, 12.388022899491169, 11.083235905164493, 11.807420712958251, 11.670764084958904, 14.343548642031877, 14.089822252264673, 11.146774006554228, 14.83903097303459, 14.644353374427286, 13.244758181211573, 12.410509038164601, 11.643494403195634, 14.092682065844572, 14.367586298974796, 14.810106489623035, 11.945040477569586, 14.401686777111255, 11.887093935272377, 14.462898789116835, 10.226154690178888, 13.016393381958249, 13.453915585803575, 13.578554072849135, 14.335352027320045, 12.265010406231234, 10.757058969921816, 11.876531697073972, 12.0491828922183, 11.092453908216743, 12.109105293560898, 12.938024069917983, 14.208843596502678, 11.466720564074699, 12.308443242742026, 13.1609372489227, 11.65441215195797, 13.728800043792663, 13.847762282971136, 14.87752275142158, 11.149184723288272, 13.640462888204215, 14.237264786466763, 13.405122090695556, 12.80566689508301, 14.483299214044472, 11.767922175746978, 13.53510927127212, 13.684872748818286, 12.553957482155372, 11.004089018712035, 14.520634498250335, 13.83809738781293, 10.672326920794527, 11.419480324115304, 14.460878992784673, 11.511794268770446, 14.47105838704902, 14.935713252855354, 13.024901111795435, 12.111956580271531, 10.646741917366109, 14.072054873809176, 12.094227297375376, 13.981650144730342, 10.648895767446431, 11.571433949013413, 14.661395278086946, 11.868831686617465, 12.875727107393082, 10.771518408030383, 13.631011657679027, 13.11336224401068, 12.145472806863014, 11.991080661902533, 12.130009173958825, 13.515256179224657, 11.513137707370925, 13.754468506719768, 14.913179336936315, 13.58791955747601, 10.134569430875423, 13.134677899479813, 12.183005498224883, 14.656674018446617, 13.657413280225123, 11.142466962252714, 11.105613647573488, 10.890935137974486, 13.660316392058583, 11.992634871732069, 14.039474798844504, 10.10273673903627, 12.512433682080895, 14.791392396799488, 13.952028496884394, 10.68072002921823, 14.148714257563924, 14.160473668158666, 10.990107339106551, 10.34171121730688, 13.669669138346311, 12.290862020072826, 10.272777155525883, 14.966454869056701, 10.300288608313576, 10.737680728398, 10.630967159879477, 13.809878958904225, 14.447266368588924, 14.456981802538502, 10.906800282148177, 13.631250425690478, 10.65625820412889, 12.765564689360023, 13.229159965330654, 11.490266136800688, 13.964187960877286, 13.923896694765084, 13.29754185129391, 13.337423023172482, 10.920180637381083, 14.69321208846982, 12.737081695738025, 12.086001267790907, 14.63420753638875, 12.995937177677611, 14.845264104376177, 13.172941798235495, 14.00450081411807, 14.486240101939611, 12.575356268048141, 10.572728182169437, 11.817972894521603, 11.020289503530373, 12.33588646221233, 14.38354993054751, 12.48657836304595, 14.045752344056417, 14.291881431404809, 11.449852919176939, 12.285269949280199, 13.329686561081914, 12.392607450843016, 11.421898690830588, 13.033623164214463, 13.740312988118928, 14.86808204262957, 14.052280858899593, 11.857022479258601, 13.344298820910902, 12.815321121685948, 12.542919644519769, 10.221542848537679, 12.825606712087758, 13.80917375726888, 11.873087750288265, 13.192060469426856, 10.513049332061176, 13.71129267069243, 10.669450949394452, 14.380201616255327, 13.516014153886436, 10.239185746011342, 14.183752673275308, 11.003573730151318, 10.824874699517318, 14.3140211605076, 10.735839396867446, 11.829061949174482, 12.444084226653683, 11.660344546867854, 14.613122657676357, 11.117541787276522, 13.71389482775391, 11.844802667361172, 13.809064011020476, 12.545980413077045, 10.37221231321253, 11.099185606018425, 12.069367607148795, 14.753997650830298, 14.860064867206237, 11.451965081962701, 12.408066998699887, 10.09219363945688, 14.804046243343, 14.462425372901544, 10.396509478003066, 13.465502211253604, 12.193256544832277, 10.419849455572237, 12.335938167870554, 14.077332364067836, 12.04238111937329, 11.219586684431405, 11.191981905319334, 13.990789915195073, 13.321355746701418, 13.867997027534281, 11.34094094573737, 11.894860840187725, 10.014643905455108, 13.9450805524248, 11.369872605476774, 13.823701043903593, 11.632450588220253, 14.402129467913422, 10.851529252537635, 13.446334384773026, 12.881948367117989, 14.301072054230792, 13.901034543377902, 14.702417172046475, 13.483519738663922, 12.257856089368287, 12.736794695148546, 11.151630919820665, 11.870685024867045, 13.667266606426, 12.666123528665413, 10.58046880567575, 12.669966690049995, 12.850748247740196, 11.685094024655385, 10.84736035947657, 10.879550786172686, 14.583912720522537, 11.556576292636521, 14.446763862373635, 12.2747770021459, 12.397640643976004, 10.138635782380568, 10.19699771111878, 14.33115980578789, 13.069369589587058, 11.654396130820546, 14.32588536103658, 11.234253581651313, 10.886330102178094, 13.905356191291201, 11.31211292200017, 14.591797165769588, 11.57906280643942, 12.687157601724977, 14.231068598718757, 11.533307917760986, 11.00278786406948, 11.791374923466336, 12.355367201523464, 13.412638962511421, 14.059784911142893, 14.929574141464332, 13.985148455547298, 13.478658632335467, 12.088803020571913, 11.076902880948095, 14.85282953089796, 13.557554489783813, 14.09449869180156, 11.058526150649634, 11.871607439321343, 13.416916873614177, 11.896264445342519, 12.140871542725174, 13.967040028548759, 13.92387024388108, 12.557100140784577, 13.709689153237505, 11.455617154148374, 11.983798170601936, 12.593738595063888, 10.852961452174824, 10.891042640728921, 11.018980720091063, 10.661661557734767, 11.968388540103959, 14.575380826864798, 10.310664116233681, 10.79793225618651, 13.175129120149073, 11.868037287978872, 12.428601245011638, 12.297281024758835, 11.75532988335384, 11.935023303980994, 11.445578716193893, 11.635791018694775, 12.229231977915058, 14.947200554894952, 10.584576916849892, 13.543547215152838, 10.948422942905365, 10.085858606874586, 11.40453743267752, 14.389263873891274, 14.270628905078073, 10.31802746298273, 11.057013004827654, 12.128662408389431, 13.19152229812298, 11.84574262866243, 12.066273890508961, 12.7038048452766, 10.95981080906325, 10.588705330230361, 12.890457480879702, 14.110412467286706, 14.63310013295482, 13.421448571071592, 11.873600277480264, 11.823406873514843, 14.649020650603521, 11.535855502475416, 14.986616581388084, 10.854693292973192, 11.738250952256035, 14.731546956588033, 10.867566954581275, 12.862704113181548, 11.185985864878273, 12.661047000348495, 10.959402002641353, 13.85593485994154, 12.727773370880131, 13.270188110208368, 12.155893411161436, 11.251995770990543, 10.734028201769819, 13.341862536135448, 12.56663295008742, 14.829248071219354, 12.63146009202443, 12.087984402629713, 12.687332073795645, 13.024881500305945, 14.636625631024831, 14.330939418774697, 14.489727988032627, 10.894975953362461, 14.063442584619581, 13.335748722823846, 14.54081960859539, 13.094259093921789, 13.25815397434542, 11.534888981037271, 11.52402384179464, 14.566248514539671, 14.896673567000065, 11.976985722167944, 10.091588801010063, 13.181522254786389, 14.03106487342248, 12.406847857913657, 12.528017683354857, 11.269268754233366, 12.577593443628423, 14.062655963542348, 14.364172468278504, 12.919707007699827, 14.460732124630018, 14.421854029205928, 14.342538815876301, 13.715570088998515, 11.952513510277187, 10.29676956281684, 10.149818255362092, 13.253896447552147, 14.423345225432362, 12.268963697091056, 14.286774548972177, 11.905175204077148, 13.493744141319985, 13.637722653600923, 14.541889104088948, 14.379843837582854, 11.916040077750571, 11.358478642311324, 14.07020030698621, 10.887539603342036, 14.906750067630346, 13.68689407511227, 11.578510345740794, 10.204256090759499, 12.512830804014698, 13.182658964969256, 12.784048294940208, 10.54838424521611, 13.516015586421368, 11.533499652630915, 11.455410070235674, 10.200545340237175, 13.422586005304904, 11.917659998933392, 13.338723186085131, 12.707389546708027, 13.372196887397864, 14.15110846956745] + def irr_binary_search(stream, tol=BASE_TOL): rate_lo, rate_hi = -MAX_LOG_RATE, +MAX_LOG_RATE sgn = numpy.sign(stream[0]) # f(x) is decreasing @@ -32,6 +38,7 @@ def irr_binary_search(stream, tol=BASE_TOL): rate = (rate_lo + rate_hi) / 2 return math.exp(rate) - 1 + def irr_newton(stream, tol=BASE_TOL): rate = 0.0 for steps in range(50): @@ -47,30 +54,59 @@ def irr_newton(stream, tol=BASE_TOL): rate = rate + numpy.clip(t / u, -1.0, 1.0) return math.exp(rate) - 1 + + +@njit +def irr_newton_numba(stream, tol=BASE_TOL): + rate = 0.0 + r = np.arange(len(stream)) + for _ in range(50): + rate_vector = -rate * r + m = np.max(rate_vector) + f = np.exp(rate_vector - m) + t = np.dot(f, stream) + if np.abs(t) < tol * np.exp(-m): + break + u = np.dot(f * r, stream) + rate += max(min(t / u, 1.0), -1.0) + + return np.exp(rate) - 1 ''' + + benchmark = '''irr_binary_search(cfs)''' n = 1000 -time = timeit.timeit(stmt=benchmark,setup=setup,number = n) /n +time = timeit.timeit(stmt=benchmark, setup=setup, number=n) /n print() print(f'better irr binary: {time} seconds') + benchmark = '''irr_newton(cfs)''' n = 1000 -time = timeit.timeit(stmt=benchmark,setup=setup,number = n) /n +time = timeit.timeit(stmt=benchmark, setup=setup, number=n) /n print() print(f'better irr newtown: {time} seconds') -import timeit -import numpy + +benchmark = '''irr_newton_numba(cfs)''' +n = 1000 +time = timeit.timeit(stmt=benchmark, setup=setup, number=n) /n +print() +print(f'better irr newtown (numba): {time} seconds') + + setup=''' -import numpy_financial, math +import math + +import numpy_financial MAX_LOG_RATE = 1e3 BASE_TOL = 1e-12 cfs = [-7000,11.33137357858057, 11.167072336683004, 14.73988904111101, 14.543375011974934, 14.787026189603953, 12.220165229291128, 10.62228303189419, 10.2054439968351, 12.38830768146916, 11.55662975000198, 10.328454158492287, 11.12038681607141, 10.324480820201908, 10.198382859550456, 11.622094119543757, 12.273321426327541, 13.968817009905088, 14.633381040913772, 14.653117743106158, 14.75415942102587, 11.115621653400536, 12.491301011838484, 11.081360378007831, 12.332972598070072, 10.880589146045264, 10.235136200262108, 12.505550229750812, 11.250354442977768, 13.007688935886225, 10.949658164170005, 10.327509073165091, 12.081824327395134, 11.095672179619607, 12.879864014703418, 11.686291918815805, 10.487486433970597, 10.782904021875865, 10.828899614147883, 13.740734146503733, 13.070147160401934, 11.281533610255876, 14.608845949786723, 11.101609237726503, 13.6672383716922, 11.991725804610223, 14.223338394270746, 12.54775932654576, 11.669406707832616, 11.172531062630963, 14.797739369742395, 14.742002039355507, 11.26059357755014, 10.005760731173147, 13.166395327031115, 10.953541497765157, 13.85589184547591, 11.938616564984416, 12.602780339084227, 10.190660874910725, 12.62253014530776, 13.25618155360879, 11.909328696772635, 13.645695694839475, 10.771692737595489, 10.019159704029537, 12.748198733268266, 14.949945651485546, 10.471989762364004, 11.694659010236517, 10.840097149970063, 13.81959526563658, 13.725232362048477, 14.696971575480223, 14.061440252466008, 11.894097203077104, 11.623559529246583, 11.422764616449735, 11.911568770804685, 14.257873178733874, 11.908786512287042, 11.704867143116388, 13.547102659825594, 10.231510523063077, 12.580425576504725, 10.204318593593095, 10.839329475371066, 14.06382079409852, 14.741551103697574, 14.125100696255025, 10.534750441149983, 12.047335974087941, 12.040901005285527, 13.061055670703222, 12.033900288651994, 14.64914110907408, 14.74150289957578, 14.18198082748481, 12.64569352877869, 10.795441413087191, 12.32677569400135, 14.201284184243757, 12.198731964230793, 13.829237277802761, 12.88556220895728, 13.681945290090994, 11.310817183394416, 10.642344563381029, 12.001334393089806, 13.940994758512655, 14.588579514241378, 11.784013809882609, 14.857525454933082, 11.890304205798119, 14.163978789672555, 12.802006519405316, 10.453613727321805, 10.545421710663241, 13.860350461267206, 13.011623286218281, 12.529578764153623, 12.0682203481126, 12.222973006731433, 10.782217823800455, 14.815112126486351, 14.021264432689495, 13.907504381640877, 13.263889558252384, 13.886523931472032, 14.92463305217065, 10.39804588193537, 11.717727995106285, 13.475830384363098, 13.96526870747185, 12.537688951669926, 10.713851417257366, 12.651783539839993, 14.94145019017787, 11.298228878804299, 11.238462723076646, 12.54816626881003, 12.991279893628143, 12.938650960410705, 14.509841908929733, 13.061627992570637, 13.532302333363827, 10.87538595312562, 13.401986714313082, 14.452077231881011, 10.62775390563043, 10.259969609401132, 10.630066121172158, 10.67746807962661, 14.301509125704097, 12.248186770125802, 13.529935347104352, 12.214180545525151, 13.737238621655871, 14.935337045307609, 10.715008490421852, 13.792764627232366, 11.566835806502482, 13.381623410224446, 11.759551394829062, 14.46722368188435, 14.820860467933276, 14.367067474219198, 12.785099227552985, 12.125131138279556, 13.59004374972493, 11.035277329107453, 13.552102778902684, 11.167577469887052, 12.079972349457684, 14.78489299740463, 11.117948297108185, 11.81118834164748, 13.306337834666962, 14.61353141178894, 14.277193746539648, 12.166555805663473, 11.265160163436654, 10.362543406467916, 11.17487038814809, 13.221576830876275, 11.124927016257411, 11.778833269702968, 12.884165622590684, 11.70614082816003, 13.732507964152038, 13.562497475153835, 14.365673914585269, 11.218499437025232, 14.313161434674605, 10.84553935633242, 13.892594863691276, 12.905232048487619, 14.526707951361043, 11.151370775543134, 11.202538557418025, 14.351557380104524, 14.618321803616304, 13.450749033215105, 13.971103464192872, 12.453728166838555, 11.203648664519335, 13.354317055813262, 14.559195884990523, 13.853813999405409, 10.265888555997426, 11.740493314590367, 13.565808716032713, 14.465381469251845, 11.700055034584512, 13.666543210894279, 10.05828768839079, 13.793893081997751, 11.840407775390236, 14.292054186783561, 13.327715352294016, 13.176691551807002, 14.385175692391908, 14.385014460873183, 11.407277293369141, 14.231388088664055, 12.250059232161178, 14.86235229497673, 13.77507647192779, 12.896049896482687, 10.60002301502453, 13.447070421155189, 13.358321797846632, 11.21916910048809, 13.30255271341071, 13.493253069737648, 10.948637495146045, 10.001718613821161, 13.91551521108937, 11.581689906353411, 14.977887214372007, 14.65693440845071, 14.665474268673329, 12.691023502305779, 11.636579739013367, 13.145065301442465, 14.054029882788013, 12.872698520853412, 14.603129068297749, 14.939572657418722, 11.170995199160744, 11.847096639046411, 13.883460710012764, 10.126422540987893, 13.407267339989394, 10.421297015199778, 14.793530503055097, 14.009521709723277, 10.551203664546083, 13.606121157647152, 13.893115513324952, 12.387229455207336, 10.152726271083313, 10.857363093853683, 10.553311047158111, 14.48112608836534, 12.009660541892252, 10.562740549914857, 10.185345168077752, 10.610848424790655, 12.382686150676019, 12.70009488541087, 11.751661090276412, 11.18298540002945, 10.938505981462802, 14.11088111794641, 14.40865642716125, 12.87387852504945, 11.345425461857499, 13.450458614928777, 14.558969761971529, 11.784359157402896, 11.528844481965896, 12.841302594496753, 10.516217100119583, 12.034691758196473, 10.631794257379834, 14.71733657041019, 14.820479028358028, 14.780542929577692, 13.052248672850174, 13.437337644194365, 12.7734425699407, 12.709862021282632, 10.034620588718868, 10.850848229793126, 14.536407975610807, 11.155751652337214, 12.193467364682604, 13.089842912540833, 13.093755843694804, 13.963076758897023, 10.782746529071671, 10.57634443951439, 10.585652732773541, 12.388022899491169, 11.083235905164493, 11.807420712958251, 11.670764084958904, 14.343548642031877, 14.089822252264673, 11.146774006554228, 14.83903097303459, 14.644353374427286, 13.244758181211573, 12.410509038164601, 11.643494403195634, 14.092682065844572, 14.367586298974796, 14.810106489623035, 11.945040477569586, 14.401686777111255, 11.887093935272377, 14.462898789116835, 10.226154690178888, 13.016393381958249, 13.453915585803575, 13.578554072849135, 14.335352027320045, 12.265010406231234, 10.757058969921816, 11.876531697073972, 12.0491828922183, 11.092453908216743, 12.109105293560898, 12.938024069917983, 14.208843596502678, 11.466720564074699, 12.308443242742026, 13.1609372489227, 11.65441215195797, 13.728800043792663, 13.847762282971136, 14.87752275142158, 11.149184723288272, 13.640462888204215, 14.237264786466763, 13.405122090695556, 12.80566689508301, 14.483299214044472, 11.767922175746978, 13.53510927127212, 13.684872748818286, 12.553957482155372, 11.004089018712035, 14.520634498250335, 13.83809738781293, 10.672326920794527, 11.419480324115304, 14.460878992784673, 11.511794268770446, 14.47105838704902, 14.935713252855354, 13.024901111795435, 12.111956580271531, 10.646741917366109, 14.072054873809176, 12.094227297375376, 13.981650144730342, 10.648895767446431, 11.571433949013413, 14.661395278086946, 11.868831686617465, 12.875727107393082, 10.771518408030383, 13.631011657679027, 13.11336224401068, 12.145472806863014, 11.991080661902533, 12.130009173958825, 13.515256179224657, 11.513137707370925, 13.754468506719768, 14.913179336936315, 13.58791955747601, 10.134569430875423, 13.134677899479813, 12.183005498224883, 14.656674018446617, 13.657413280225123, 11.142466962252714, 11.105613647573488, 10.890935137974486, 13.660316392058583, 11.992634871732069, 14.039474798844504, 10.10273673903627, 12.512433682080895, 14.791392396799488, 13.952028496884394, 10.68072002921823, 14.148714257563924, 14.160473668158666, 10.990107339106551, 10.34171121730688, 13.669669138346311, 12.290862020072826, 10.272777155525883, 14.966454869056701, 10.300288608313576, 10.737680728398, 10.630967159879477, 13.809878958904225, 14.447266368588924, 14.456981802538502, 10.906800282148177, 13.631250425690478, 10.65625820412889, 12.765564689360023, 13.229159965330654, 11.490266136800688, 13.964187960877286, 13.923896694765084, 13.29754185129391, 13.337423023172482, 10.920180637381083, 14.69321208846982, 12.737081695738025, 12.086001267790907, 14.63420753638875, 12.995937177677611, 14.845264104376177, 13.172941798235495, 14.00450081411807, 14.486240101939611, 12.575356268048141, 10.572728182169437, 11.817972894521603, 11.020289503530373, 12.33588646221233, 14.38354993054751, 12.48657836304595, 14.045752344056417, 14.291881431404809, 11.449852919176939, 12.285269949280199, 13.329686561081914, 12.392607450843016, 11.421898690830588, 13.033623164214463, 13.740312988118928, 14.86808204262957, 14.052280858899593, 11.857022479258601, 13.344298820910902, 12.815321121685948, 12.542919644519769, 10.221542848537679, 12.825606712087758, 13.80917375726888, 11.873087750288265, 13.192060469426856, 10.513049332061176, 13.71129267069243, 10.669450949394452, 14.380201616255327, 13.516014153886436, 10.239185746011342, 14.183752673275308, 11.003573730151318, 10.824874699517318, 14.3140211605076, 10.735839396867446, 11.829061949174482, 12.444084226653683, 11.660344546867854, 14.613122657676357, 11.117541787276522, 13.71389482775391, 11.844802667361172, 13.809064011020476, 12.545980413077045, 10.37221231321253, 11.099185606018425, 12.069367607148795, 14.753997650830298, 14.860064867206237, 11.451965081962701, 12.408066998699887, 10.09219363945688, 14.804046243343, 14.462425372901544, 10.396509478003066, 13.465502211253604, 12.193256544832277, 10.419849455572237, 12.335938167870554, 14.077332364067836, 12.04238111937329, 11.219586684431405, 11.191981905319334, 13.990789915195073, 13.321355746701418, 13.867997027534281, 11.34094094573737, 11.894860840187725, 10.014643905455108, 13.9450805524248, 11.369872605476774, 13.823701043903593, 11.632450588220253, 14.402129467913422, 10.851529252537635, 13.446334384773026, 12.881948367117989, 14.301072054230792, 13.901034543377902, 14.702417172046475, 13.483519738663922, 12.257856089368287, 12.736794695148546, 11.151630919820665, 11.870685024867045, 13.667266606426, 12.666123528665413, 10.58046880567575, 12.669966690049995, 12.850748247740196, 11.685094024655385, 10.84736035947657, 10.879550786172686, 14.583912720522537, 11.556576292636521, 14.446763862373635, 12.2747770021459, 12.397640643976004, 10.138635782380568, 10.19699771111878, 14.33115980578789, 13.069369589587058, 11.654396130820546, 14.32588536103658, 11.234253581651313, 10.886330102178094, 13.905356191291201, 11.31211292200017, 14.591797165769588, 11.57906280643942, 12.687157601724977, 14.231068598718757, 11.533307917760986, 11.00278786406948, 11.791374923466336, 12.355367201523464, 13.412638962511421, 14.059784911142893, 14.929574141464332, 13.985148455547298, 13.478658632335467, 12.088803020571913, 11.076902880948095, 14.85282953089796, 13.557554489783813, 14.09449869180156, 11.058526150649634, 11.871607439321343, 13.416916873614177, 11.896264445342519, 12.140871542725174, 13.967040028548759, 13.92387024388108, 12.557100140784577, 13.709689153237505, 11.455617154148374, 11.983798170601936, 12.593738595063888, 10.852961452174824, 10.891042640728921, 11.018980720091063, 10.661661557734767, 11.968388540103959, 14.575380826864798, 10.310664116233681, 10.79793225618651, 13.175129120149073, 11.868037287978872, 12.428601245011638, 12.297281024758835, 11.75532988335384, 11.935023303980994, 11.445578716193893, 11.635791018694775, 12.229231977915058, 14.947200554894952, 10.584576916849892, 13.543547215152838, 10.948422942905365, 10.085858606874586, 11.40453743267752, 14.389263873891274, 14.270628905078073, 10.31802746298273, 11.057013004827654, 12.128662408389431, 13.19152229812298, 11.84574262866243, 12.066273890508961, 12.7038048452766, 10.95981080906325, 10.588705330230361, 12.890457480879702, 14.110412467286706, 14.63310013295482, 13.421448571071592, 11.873600277480264, 11.823406873514843, 14.649020650603521, 11.535855502475416, 14.986616581388084, 10.854693292973192, 11.738250952256035, 14.731546956588033, 10.867566954581275, 12.862704113181548, 11.185985864878273, 12.661047000348495, 10.959402002641353, 13.85593485994154, 12.727773370880131, 13.270188110208368, 12.155893411161436, 11.251995770990543, 10.734028201769819, 13.341862536135448, 12.56663295008742, 14.829248071219354, 12.63146009202443, 12.087984402629713, 12.687332073795645, 13.024881500305945, 14.636625631024831, 14.330939418774697, 14.489727988032627, 10.894975953362461, 14.063442584619581, 13.335748722823846, 14.54081960859539, 13.094259093921789, 13.25815397434542, 11.534888981037271, 11.52402384179464, 14.566248514539671, 14.896673567000065, 11.976985722167944, 10.091588801010063, 13.181522254786389, 14.03106487342248, 12.406847857913657, 12.528017683354857, 11.269268754233366, 12.577593443628423, 14.062655963542348, 14.364172468278504, 12.919707007699827, 14.460732124630018, 14.421854029205928, 14.342538815876301, 13.715570088998515, 11.952513510277187, 10.29676956281684, 10.149818255362092, 13.253896447552147, 14.423345225432362, 12.268963697091056, 14.286774548972177, 11.905175204077148, 13.493744141319985, 13.637722653600923, 14.541889104088948, 14.379843837582854, 11.916040077750571, 11.358478642311324, 14.07020030698621, 10.887539603342036, 14.906750067630346, 13.68689407511227, 11.578510345740794, 10.204256090759499, 12.512830804014698, 13.182658964969256, 12.784048294940208, 10.54838424521611, 13.516015586421368, 11.533499652630915, 11.455410070235674, 10.200545340237175, 13.422586005304904, 11.917659998933392, 13.338723186085131, 12.707389546708027, 13.372196887397864, 14.15110846956745] ''' + benchmark = '''numpy_financial.irr(cfs)''' n = 50 -time = timeit.timeit(stmt=benchmark,setup=setup,number = n) /n -print(f'numpy: {time} seconds') \ No newline at end of file +time = timeit.timeit(stmt=benchmark, setup=setup, number=n) /n +print(f'numpy: {time} seconds') From e3d654e57b2ba3d3677cee6952d57094f0ef5e7f Mon Sep 17 00:00:00 2001 From: Dimitar Vanguelov Date: Mon, 19 Jun 2023 20:23:15 -0400 Subject: [PATCH 2/2] convert cfs array to numpy for numba to work --- Benchmarks/irr/python/python.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Benchmarks/irr/python/python.py b/Benchmarks/irr/python/python.py index d6f7f4f..2be0e7b 100644 --- a/Benchmarks/irr/python/python.py +++ b/Benchmarks/irr/python/python.py @@ -19,6 +19,10 @@ cfs = [-7000,11.33137357858057, 11.167072336683004, 14.73988904111101, 14.543375011974934, 14.787026189603953, 12.220165229291128, 10.62228303189419, 10.2054439968351, 12.38830768146916, 11.55662975000198, 10.328454158492287, 11.12038681607141, 10.324480820201908, 10.198382859550456, 11.622094119543757, 12.273321426327541, 13.968817009905088, 14.633381040913772, 14.653117743106158, 14.75415942102587, 11.115621653400536, 12.491301011838484, 11.081360378007831, 12.332972598070072, 10.880589146045264, 10.235136200262108, 12.505550229750812, 11.250354442977768, 13.007688935886225, 10.949658164170005, 10.327509073165091, 12.081824327395134, 11.095672179619607, 12.879864014703418, 11.686291918815805, 10.487486433970597, 10.782904021875865, 10.828899614147883, 13.740734146503733, 13.070147160401934, 11.281533610255876, 14.608845949786723, 11.101609237726503, 13.6672383716922, 11.991725804610223, 14.223338394270746, 12.54775932654576, 11.669406707832616, 11.172531062630963, 14.797739369742395, 14.742002039355507, 11.26059357755014, 10.005760731173147, 13.166395327031115, 10.953541497765157, 13.85589184547591, 11.938616564984416, 12.602780339084227, 10.190660874910725, 12.62253014530776, 13.25618155360879, 11.909328696772635, 13.645695694839475, 10.771692737595489, 10.019159704029537, 12.748198733268266, 14.949945651485546, 10.471989762364004, 11.694659010236517, 10.840097149970063, 13.81959526563658, 13.725232362048477, 14.696971575480223, 14.061440252466008, 11.894097203077104, 11.623559529246583, 11.422764616449735, 11.911568770804685, 14.257873178733874, 11.908786512287042, 11.704867143116388, 13.547102659825594, 10.231510523063077, 12.580425576504725, 10.204318593593095, 10.839329475371066, 14.06382079409852, 14.741551103697574, 14.125100696255025, 10.534750441149983, 12.047335974087941, 12.040901005285527, 13.061055670703222, 12.033900288651994, 14.64914110907408, 14.74150289957578, 14.18198082748481, 12.64569352877869, 10.795441413087191, 12.32677569400135, 14.201284184243757, 12.198731964230793, 13.829237277802761, 12.88556220895728, 13.681945290090994, 11.310817183394416, 10.642344563381029, 12.001334393089806, 13.940994758512655, 14.588579514241378, 11.784013809882609, 14.857525454933082, 11.890304205798119, 14.163978789672555, 12.802006519405316, 10.453613727321805, 10.545421710663241, 13.860350461267206, 13.011623286218281, 12.529578764153623, 12.0682203481126, 12.222973006731433, 10.782217823800455, 14.815112126486351, 14.021264432689495, 13.907504381640877, 13.263889558252384, 13.886523931472032, 14.92463305217065, 10.39804588193537, 11.717727995106285, 13.475830384363098, 13.96526870747185, 12.537688951669926, 10.713851417257366, 12.651783539839993, 14.94145019017787, 11.298228878804299, 11.238462723076646, 12.54816626881003, 12.991279893628143, 12.938650960410705, 14.509841908929733, 13.061627992570637, 13.532302333363827, 10.87538595312562, 13.401986714313082, 14.452077231881011, 10.62775390563043, 10.259969609401132, 10.630066121172158, 10.67746807962661, 14.301509125704097, 12.248186770125802, 13.529935347104352, 12.214180545525151, 13.737238621655871, 14.935337045307609, 10.715008490421852, 13.792764627232366, 11.566835806502482, 13.381623410224446, 11.759551394829062, 14.46722368188435, 14.820860467933276, 14.367067474219198, 12.785099227552985, 12.125131138279556, 13.59004374972493, 11.035277329107453, 13.552102778902684, 11.167577469887052, 12.079972349457684, 14.78489299740463, 11.117948297108185, 11.81118834164748, 13.306337834666962, 14.61353141178894, 14.277193746539648, 12.166555805663473, 11.265160163436654, 10.362543406467916, 11.17487038814809, 13.221576830876275, 11.124927016257411, 11.778833269702968, 12.884165622590684, 11.70614082816003, 13.732507964152038, 13.562497475153835, 14.365673914585269, 11.218499437025232, 14.313161434674605, 10.84553935633242, 13.892594863691276, 12.905232048487619, 14.526707951361043, 11.151370775543134, 11.202538557418025, 14.351557380104524, 14.618321803616304, 13.450749033215105, 13.971103464192872, 12.453728166838555, 11.203648664519335, 13.354317055813262, 14.559195884990523, 13.853813999405409, 10.265888555997426, 11.740493314590367, 13.565808716032713, 14.465381469251845, 11.700055034584512, 13.666543210894279, 10.05828768839079, 13.793893081997751, 11.840407775390236, 14.292054186783561, 13.327715352294016, 13.176691551807002, 14.385175692391908, 14.385014460873183, 11.407277293369141, 14.231388088664055, 12.250059232161178, 14.86235229497673, 13.77507647192779, 12.896049896482687, 10.60002301502453, 13.447070421155189, 13.358321797846632, 11.21916910048809, 13.30255271341071, 13.493253069737648, 10.948637495146045, 10.001718613821161, 13.91551521108937, 11.581689906353411, 14.977887214372007, 14.65693440845071, 14.665474268673329, 12.691023502305779, 11.636579739013367, 13.145065301442465, 14.054029882788013, 12.872698520853412, 14.603129068297749, 14.939572657418722, 11.170995199160744, 11.847096639046411, 13.883460710012764, 10.126422540987893, 13.407267339989394, 10.421297015199778, 14.793530503055097, 14.009521709723277, 10.551203664546083, 13.606121157647152, 13.893115513324952, 12.387229455207336, 10.152726271083313, 10.857363093853683, 10.553311047158111, 14.48112608836534, 12.009660541892252, 10.562740549914857, 10.185345168077752, 10.610848424790655, 12.382686150676019, 12.70009488541087, 11.751661090276412, 11.18298540002945, 10.938505981462802, 14.11088111794641, 14.40865642716125, 12.87387852504945, 11.345425461857499, 13.450458614928777, 14.558969761971529, 11.784359157402896, 11.528844481965896, 12.841302594496753, 10.516217100119583, 12.034691758196473, 10.631794257379834, 14.71733657041019, 14.820479028358028, 14.780542929577692, 13.052248672850174, 13.437337644194365, 12.7734425699407, 12.709862021282632, 10.034620588718868, 10.850848229793126, 14.536407975610807, 11.155751652337214, 12.193467364682604, 13.089842912540833, 13.093755843694804, 13.963076758897023, 10.782746529071671, 10.57634443951439, 10.585652732773541, 12.388022899491169, 11.083235905164493, 11.807420712958251, 11.670764084958904, 14.343548642031877, 14.089822252264673, 11.146774006554228, 14.83903097303459, 14.644353374427286, 13.244758181211573, 12.410509038164601, 11.643494403195634, 14.092682065844572, 14.367586298974796, 14.810106489623035, 11.945040477569586, 14.401686777111255, 11.887093935272377, 14.462898789116835, 10.226154690178888, 13.016393381958249, 13.453915585803575, 13.578554072849135, 14.335352027320045, 12.265010406231234, 10.757058969921816, 11.876531697073972, 12.0491828922183, 11.092453908216743, 12.109105293560898, 12.938024069917983, 14.208843596502678, 11.466720564074699, 12.308443242742026, 13.1609372489227, 11.65441215195797, 13.728800043792663, 13.847762282971136, 14.87752275142158, 11.149184723288272, 13.640462888204215, 14.237264786466763, 13.405122090695556, 12.80566689508301, 14.483299214044472, 11.767922175746978, 13.53510927127212, 13.684872748818286, 12.553957482155372, 11.004089018712035, 14.520634498250335, 13.83809738781293, 10.672326920794527, 11.419480324115304, 14.460878992784673, 11.511794268770446, 14.47105838704902, 14.935713252855354, 13.024901111795435, 12.111956580271531, 10.646741917366109, 14.072054873809176, 12.094227297375376, 13.981650144730342, 10.648895767446431, 11.571433949013413, 14.661395278086946, 11.868831686617465, 12.875727107393082, 10.771518408030383, 13.631011657679027, 13.11336224401068, 12.145472806863014, 11.991080661902533, 12.130009173958825, 13.515256179224657, 11.513137707370925, 13.754468506719768, 14.913179336936315, 13.58791955747601, 10.134569430875423, 13.134677899479813, 12.183005498224883, 14.656674018446617, 13.657413280225123, 11.142466962252714, 11.105613647573488, 10.890935137974486, 13.660316392058583, 11.992634871732069, 14.039474798844504, 10.10273673903627, 12.512433682080895, 14.791392396799488, 13.952028496884394, 10.68072002921823, 14.148714257563924, 14.160473668158666, 10.990107339106551, 10.34171121730688, 13.669669138346311, 12.290862020072826, 10.272777155525883, 14.966454869056701, 10.300288608313576, 10.737680728398, 10.630967159879477, 13.809878958904225, 14.447266368588924, 14.456981802538502, 10.906800282148177, 13.631250425690478, 10.65625820412889, 12.765564689360023, 13.229159965330654, 11.490266136800688, 13.964187960877286, 13.923896694765084, 13.29754185129391, 13.337423023172482, 10.920180637381083, 14.69321208846982, 12.737081695738025, 12.086001267790907, 14.63420753638875, 12.995937177677611, 14.845264104376177, 13.172941798235495, 14.00450081411807, 14.486240101939611, 12.575356268048141, 10.572728182169437, 11.817972894521603, 11.020289503530373, 12.33588646221233, 14.38354993054751, 12.48657836304595, 14.045752344056417, 14.291881431404809, 11.449852919176939, 12.285269949280199, 13.329686561081914, 12.392607450843016, 11.421898690830588, 13.033623164214463, 13.740312988118928, 14.86808204262957, 14.052280858899593, 11.857022479258601, 13.344298820910902, 12.815321121685948, 12.542919644519769, 10.221542848537679, 12.825606712087758, 13.80917375726888, 11.873087750288265, 13.192060469426856, 10.513049332061176, 13.71129267069243, 10.669450949394452, 14.380201616255327, 13.516014153886436, 10.239185746011342, 14.183752673275308, 11.003573730151318, 10.824874699517318, 14.3140211605076, 10.735839396867446, 11.829061949174482, 12.444084226653683, 11.660344546867854, 14.613122657676357, 11.117541787276522, 13.71389482775391, 11.844802667361172, 13.809064011020476, 12.545980413077045, 10.37221231321253, 11.099185606018425, 12.069367607148795, 14.753997650830298, 14.860064867206237, 11.451965081962701, 12.408066998699887, 10.09219363945688, 14.804046243343, 14.462425372901544, 10.396509478003066, 13.465502211253604, 12.193256544832277, 10.419849455572237, 12.335938167870554, 14.077332364067836, 12.04238111937329, 11.219586684431405, 11.191981905319334, 13.990789915195073, 13.321355746701418, 13.867997027534281, 11.34094094573737, 11.894860840187725, 10.014643905455108, 13.9450805524248, 11.369872605476774, 13.823701043903593, 11.632450588220253, 14.402129467913422, 10.851529252537635, 13.446334384773026, 12.881948367117989, 14.301072054230792, 13.901034543377902, 14.702417172046475, 13.483519738663922, 12.257856089368287, 12.736794695148546, 11.151630919820665, 11.870685024867045, 13.667266606426, 12.666123528665413, 10.58046880567575, 12.669966690049995, 12.850748247740196, 11.685094024655385, 10.84736035947657, 10.879550786172686, 14.583912720522537, 11.556576292636521, 14.446763862373635, 12.2747770021459, 12.397640643976004, 10.138635782380568, 10.19699771111878, 14.33115980578789, 13.069369589587058, 11.654396130820546, 14.32588536103658, 11.234253581651313, 10.886330102178094, 13.905356191291201, 11.31211292200017, 14.591797165769588, 11.57906280643942, 12.687157601724977, 14.231068598718757, 11.533307917760986, 11.00278786406948, 11.791374923466336, 12.355367201523464, 13.412638962511421, 14.059784911142893, 14.929574141464332, 13.985148455547298, 13.478658632335467, 12.088803020571913, 11.076902880948095, 14.85282953089796, 13.557554489783813, 14.09449869180156, 11.058526150649634, 11.871607439321343, 13.416916873614177, 11.896264445342519, 12.140871542725174, 13.967040028548759, 13.92387024388108, 12.557100140784577, 13.709689153237505, 11.455617154148374, 11.983798170601936, 12.593738595063888, 10.852961452174824, 10.891042640728921, 11.018980720091063, 10.661661557734767, 11.968388540103959, 14.575380826864798, 10.310664116233681, 10.79793225618651, 13.175129120149073, 11.868037287978872, 12.428601245011638, 12.297281024758835, 11.75532988335384, 11.935023303980994, 11.445578716193893, 11.635791018694775, 12.229231977915058, 14.947200554894952, 10.584576916849892, 13.543547215152838, 10.948422942905365, 10.085858606874586, 11.40453743267752, 14.389263873891274, 14.270628905078073, 10.31802746298273, 11.057013004827654, 12.128662408389431, 13.19152229812298, 11.84574262866243, 12.066273890508961, 12.7038048452766, 10.95981080906325, 10.588705330230361, 12.890457480879702, 14.110412467286706, 14.63310013295482, 13.421448571071592, 11.873600277480264, 11.823406873514843, 14.649020650603521, 11.535855502475416, 14.986616581388084, 10.854693292973192, 11.738250952256035, 14.731546956588033, 10.867566954581275, 12.862704113181548, 11.185985864878273, 12.661047000348495, 10.959402002641353, 13.85593485994154, 12.727773370880131, 13.270188110208368, 12.155893411161436, 11.251995770990543, 10.734028201769819, 13.341862536135448, 12.56663295008742, 14.829248071219354, 12.63146009202443, 12.087984402629713, 12.687332073795645, 13.024881500305945, 14.636625631024831, 14.330939418774697, 14.489727988032627, 10.894975953362461, 14.063442584619581, 13.335748722823846, 14.54081960859539, 13.094259093921789, 13.25815397434542, 11.534888981037271, 11.52402384179464, 14.566248514539671, 14.896673567000065, 11.976985722167944, 10.091588801010063, 13.181522254786389, 14.03106487342248, 12.406847857913657, 12.528017683354857, 11.269268754233366, 12.577593443628423, 14.062655963542348, 14.364172468278504, 12.919707007699827, 14.460732124630018, 14.421854029205928, 14.342538815876301, 13.715570088998515, 11.952513510277187, 10.29676956281684, 10.149818255362092, 13.253896447552147, 14.423345225432362, 12.268963697091056, 14.286774548972177, 11.905175204077148, 13.493744141319985, 13.637722653600923, 14.541889104088948, 14.379843837582854, 11.916040077750571, 11.358478642311324, 14.07020030698621, 10.887539603342036, 14.906750067630346, 13.68689407511227, 11.578510345740794, 10.204256090759499, 12.512830804014698, 13.182658964969256, 12.784048294940208, 10.54838424521611, 13.516015586421368, 11.533499652630915, 11.455410070235674, 10.200545340237175, 13.422586005304904, 11.917659998933392, 13.338723186085131, 12.707389546708027, 13.372196887397864, 14.15110846956745] +# need this for the numba solution to work +npcfs = np.array(cfs) + + def irr_binary_search(stream, tol=BASE_TOL): rate_lo, rate_hi = -MAX_LOG_RATE, +MAX_LOG_RATE sgn = numpy.sign(stream[0]) # f(x) is decreasing @@ -88,7 +92,7 @@ def irr_newton_numba(stream, tol=BASE_TOL): print(f'better irr newtown: {time} seconds') -benchmark = '''irr_newton_numba(cfs)''' +benchmark = '''irr_newton_numba(npcfs)''' n = 1000 time = timeit.timeit(stmt=benchmark, setup=setup, number=n) /n print()