Esempio n. 1
0
 def testSimulateLossesOneYear(self):
     # Should return a list of zero or more losses that fall mostly within the
     # configured range (1, 10)
     self.s = simpleloss.SimpleLoss('L1', 'loss_name', 10, 1, 10)
     for _ in range(100):
         losses = self.s.simulate_losses_one_year()
         if len(losses) == 0:
             self.assertEqual([], losses)
         else:
             self.assertGreater(100, len(losses))
             self.assertLess(0.05 * len(losses), sum(losses))
             self.assertGreater(100 * len(losses), sum(losses))
Esempio n. 2
0
    def testContract(self):
        # Probability must be <= 1.
        try:
            simpleloss.SimpleLoss("L2", "loss2", 10, 100, 1000)  # p > 1
            self.fail("Probability <= 1. not enforced")
        except AssertionError:
            pass

        # Probability must be >= 0.
        try:
            simpleloss.SimpleLoss("L2", "loss2", -1, 100, 1000)  # p < 0
            self.fail("Probability >= 0. not enforced")
        except AssertionError:
            pass

        # High loss must exceed low loss
        try:
            simpleloss.SimpleLoss("L2", "loss2", 0.5, 1000,
                                  100)  # low_loss > high_loss
            self.fail("low_loss <= high_loss not enforced")
        except AssertionError:
            pass
Esempio n. 3
0
def csv_to_simpleloss(file):
    """Convert a csv file with parameters to SimpleModel objects

    :arg: file = Name of CSV file to read. Each row should contain rows with
                 name, probability, low_loss, high_loss

    :returns: List of SimpleLoss objects
    """

    loss_list = []
    with open(file, 'r', newline='\n') as csvfile:
        loss_reader = csv.reader(csvfile)
        for label, name, p, low_loss, high_loss in loss_reader:
            label: str
            name: str
            loss_list += [
                simpleloss.SimpleLoss(label, name, float(p), float(low_loss),
                                      float(high_loss))
            ]
    return loss_list
Esempio n. 4
0
 def testLargeFrequency(self):
     lg = simpleloss.SimpleLoss('Large', 'large_loss', 3.0, 1, 10)
     self.assertAlmostEqual(lg.annualized_loss(), 12.120038480837177)  # 30x the value above
Esempio n. 5
0
 def setUp(self):
     frequency = 0.1
     low = 1
     high = 10
     self.s = simpleloss.SimpleLoss('L1', 'loss_name', frequency, low, high)
Esempio n. 6
0
 def testHardParameters(self):
     # Test difficult-to-fit parameter values
     hard = simpleloss.SimpleLoss('H1', 'hard_loss', 0.07, 635000, 19000000)
     self.assertAlmostEqual(hard.annualized_loss(), 414589.4783457917)
Esempio n. 7
0
 def setUp(self):
     p = 0.1
     low = 1
     high = 10
     self.s = simpleloss.SimpleLoss('L1', 'loss_name', p, low, high)