예제 #1
0
path = Path('testcase') / 'positive_far_many_cf.csv'

data = read_csv(path)

cf_data = pd.DataFrame(data[['cf and total end']])
cf_data = cf_data['cf and total end'].reset_index()
cf_data['timestamp'] = cf_data['timestamp'].astype('datetime64[ns]')
arr_cf = cf_data[['timestamp', 'cf and total end']].to_numpy()

data_rename = data[['total', 'cf']].copy()
data_rename.rename(columns={'cf': 'cashflow'}, inplace=True)
dict_data = dict(zip(data.index, data['cf']))

print('внешний xirr')
t2 = time.time()
res_xirr = create_return_xirr(data[['total', 'cf']], ['mwrr'])['mwrr']
print(f'mwrr:{res_xirr:.8f}  за {time.time() - t2:.2f} c.')
print('----------------------')

print('моя функция:')
t1 = time.time()
res = perfom.create_return(data[['total', 'cf']], ['mwrr', 'twrr'])
print(f'за {time.time() - t1:.2f} c.')
print('----------------------')

print('переписанный xirr')
t3 = time.time()
res_xirr_dict = create_return(data[['total', 'cf']], ['mwrr'])['mwrr']
print(f'mwrr:{res_xirr_dict:.8f}  за {time.time() - t3:.2f} c.')
 def negative_close_many_twrr(self):
     dt = self.test_data['negative_close_many_twrr']
     self.assertEqual(round(create_return(dt['data'], ['twrr'])['twrr'], 4), round(dt['result'],4))
 def test_xirr_negative_closely_1_cf(self):
     dt = self.test_data['negative_closely_1_cf']
     self.assertEqual(round(create_return(dt['data'], ['mwrr'])['mwrr'], 4), round(dt['result'],4))
 def test_xirr_positive_far_1_cf(self):
     dt = self.test_data['positive_far_1_cf']
     self.assertEqual(round(create_return(dt['data'], ['mwrr'])['mwrr'], 4), round(dt['result'],4))
 def test_xirr_diferent_cf(self):
     dt = self.test_data['diferent_cf']
     self.assertEqual(round(create_return(dt['data'], ['mwrr'])['mwrr'], 4), round(dt['result'],4))