Beispiel #1
0
    def __init__(self, main=None):
    
        if not main:
            raise ValueError("No value provided for main")
            
        self.main = main
        self.canvas = tk.Canvas(
            self.main.root,
            background='#FFFFFF',
            **constants.canvas_dimensions)
        self.axes = Axes(
            canvas=self.canvas,
            **constants.axes_display,
            **constants.axes_scale)
                                
        self.canvas.grid()

        for p in constants.monthly_payment_range():
            a = constants.initial_balance['default']
            i = constants.interest_rate['default']
            payoff_months = payments_to_payoff(a, i / 12, p)

            if payoff_months is None or payoff_months / 12 > constants.axes_scale['y_max']:
                point = self.axes.add_point(p, 0)
                self.axes.hide_point(point)
            else:
                self.axes.add_point(p, payoff_months / 12)
Beispiel #2
0
 def calculate_payoff_times(self):
     """Calculates payoff time data and stores the results in the database"""
     with self.database.transaction():
         current_id = 0
         for Bo in constants.initial_balance_range():
             for r in constants.interest_rate_range():
                 for p in constants.monthly_payment_range():
                     print("Calculating for initial balance {0}, rate {1}, monthly payment {2}".format(Bo, r, p))
                     t = time_until_zero_balance(r, Bo, p)
                     if t is not None:
                         database.create_point(current_id, Bo, r, p, t)
                     current_id += 1
Beispiel #3
0
    def update_axes(self, a, i):
        """Updates the points on the axes to reflect the new values of a and i.

        Args:
            a (numeric): The initial balance of the loan
            i (numeric): The interest rate per payment period (NOT per year) in decimal form
        """
        for p in constants.monthly_payment_range():
            try:
                payoff_months = payments_to_payoff(a, i / 12, p)
            except AssertionError:
                # payments_to_payoff failed preconditions
                continue

            point = self.axes.get_point_by_x(p)
            if payoff_months is None or payoff_months / 12 > constants.axes_scale['y_max']:
                self.axes.hide_point(point)
            else:
                self.axes.show_point(point)
                self.axes.move_point(point, p, payoff_months / 12)