def test_calculate_risk_initial(self):
     """
         Test calculate_risk_initial
     """
     calc = CalculatorFinance()
     func = Functions()
     for value in self.test_values:
         if value['i_long_bool']:
             result = calc.calculate_risk_initial(
                     func.test_conversion_to(value['i_price_buy_orig'], value['i_exchange_rate_buy']),
                     value['i_shares_buy'],
                     value['i_tax_buy'],
                     value['i_commission_buy'],
                     value['result_values']['stoploss'],
                     value['i_long_bool'])
         else:
             result = calc.calculate_risk_initial(
                     func.test_conversion_to(value['i_price_sell_orig'], value['i_exchange_rate_sell']),
                     value['i_shares_sell'],
                     value['i_tax_sell'],
                     value['i_commission_sell'],
                     value['result_values']['stoploss'],
                     value['i_long_bool'])
         print "result = ", result
         self.assertAlmostEqual(float(value['result_values']['risk_initial']), float(result), 4)
     func = None
     calc = None
 def test_calculate_percentage_of(self):
     """
         Test calculate_percentage_of
     """
     calc = CalculatorFinance()
     result = calc.calculate_percentage_of(
             Decimal('25.45'),
             Decimal('100.0'))
     self.assertAlmostEqual(float(25.45), round(float(result), 4), 2)
     calc = None
 def test_calculate_cost_other(self):
     """
         Test calculate_cost_other
     """
     calc = CalculatorFinance()
     for value in self.test_values:
         result = calc.calculate_cost_other(
                 value['result_values']['cost_total'],
                 value['result_values']['profit_loss'])
         self.assertAlmostEqual(float(value['result_values']['cost_other']), float(result), 4)
     calc = None
 def test_calculate_r_multiple(self):
     """
         Test calculate_r_multiple
     """
     calc = CalculatorFinance()
     for value in self.test_values:
         result = calc.calculate_r_multiple(
                 value['result_values']['profit_loss'],
                 value['result_values']['risk_initial'])
         self.assertAlmostEqual(float(value['result_values']['r_multiple']), float(result), 4)
     calc = None
 def test_calculate_amount_sell_simple(self):
     """
         Test calculate_amount_simpel for selling
     """
     calc = CalculatorFinance()
     func = Functions()
     for value in self.test_values:
         result = calc.calculate_amount_simple(
                 func.test_conversion_to(value['i_price_sell_orig'], value['i_exchange_rate_sell']),
                 value['i_shares_sell'])
         self.assertAlmostEqual(float(value['result_values']['amount_sell_simple']), float(result), 4)
     func = None
     calc = None
 def test_calculate_cost_total(self):
     """
         Test calculate_cost_total
     """
     calc = CalculatorFinance()
     for value in self.test_values:
         result = calc.calculate_cost_total(
                 value['i_tax_buy'],
                 value['i_commission_buy'],
                 value['i_tax_sell'],
                 value['i_commission_sell'])
         self.assertAlmostEqual(float(value['result_values']['cost_total']), float(result), 4)
     calc = None
 def test_calculate_amount_with_tax_buy(self):
     """
         Test calculate_amount_with_tax for buying
     """
     calc = CalculatorFinance()
     func = Functions()
     for value in self.test_values:
         result = calc.calculate_amount_with_tax(
                 Transaction.BUY,
                 value['i_shares_buy'],
                 func.test_conversion_to(value['i_price_buy_orig'], value['i_exchange_rate_buy']),
                 value['i_tax_buy'])
         self.assertAlmostEqual(float(value['result_values']['amount_with_tax_buy']), float(result), 4)
     func = None
     calc = None
 def test_calculate_risk_input(self):
     """
         Test calculate_risk_input
     """
     calc = CalculatorFinance()
     func = Functions()
     for value in self.test_values:
         result = calc.calculate_risk_input(
                     func.test_margin_of_pool(
                         value['i_pool'],
                         value['i_margin']),
                     value['i_risk_input'])
         self.assertAlmostEqual(float(value['result_values']['risk_input']), float(result), 4)
     func = None
     calc = None
 def test_cost_tax_sell(self):
     """
         Test cost_tax for selling
     """
     calc = CalculatorFinance()
     func = Functions()
     for value in self.test_values:
         result = calc.cost_tax(
                 Transaction.SELL,
                 value['result_values']['amount_sell'],
                 value['i_commission_sell'],
                 value['i_shares_sell'],
                 func.test_conversion_to(value['i_price_sell_orig'], value['i_exchange_rate_sell']))
         self.assertAlmostEqual(float(value['result_values']['cost_tax_sell']), float(result), 4)
     func = None
     calc = None
 def test_calculate_stoploss(self):
     """
         Test calculate_stoploss
     """
     calc = CalculatorFinance()
     func = Functions()
     for value in self.test_values:
         result = calc.calculate_stoploss(
                 func.test_conversion_to(value['i_price_sell_orig'], value['i_exchange_rate_sell']),
                 value['i_shares_sell'],
                 value['i_tax_sell'],
                 value['i_commission_sell'],
                 value['i_risk_input'],
                 func.test_margin_of_pool(value['i_pool'], value['i_margin']),
                 value['i_long_bool'])
         self.assertAlmostEqual(float(value['result_values']['stoploss']), float(result), 4)
     func = None
     calc = None