<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def calcAFunc(self,MaggNow,AaggNow):
        '''
        Calculate a new aggregate savings rule based on the history of the
        aggregate savings and aggregate market resources from a simulation.
        Calculates an aggregate saving rule for each macroeconomic Markov state.

        Parameters
        ----------
        MaggNow : [float]
            List of the history of the simulated  aggregate market resources for an economy.
        AaggNow : [float]
            List of the history of the simulated  aggregate savings for an economy.

        Returns
        -------
        (unnamed) : CapDynamicRule
            Object containing new saving rules for each Markov state.
        '''
        verbose = self.verbose
        discard_periods = self.T_discard # Throw out the first T periods to allow the simulation to approach the SS
        update_weight = 1. - self.DampingFac  # Proportional weight to put on new function vs old function parameters
        total_periods = len(MaggNow)

        # Trim the histories of M_t and A_t and convert them to logs
        logAagg   = np.log(AaggNow[discard_periods:total_periods])
        logMagg   = np.log(MaggNow[discard_periods-1:total_periods-1])
        MrkvHist  = self.MrkvNow_hist[discard_periods-1:total_periods-1]

        # For each Markov state, regress A_t on M_t and update the saving rule
        AFunc_list = []
        rSq_list = []
        for i in range(self.MrkvArray.shape[0]):
            these = i == MrkvHist
            slope, intercept, r_value, p_value, std_err = stats.linregress(logMagg[these],logAagg[these])
            #if verbose:
            #    plt.plot(logMagg[these],logAagg[these],'.')

            # Make a new aggregate savings rule by combining the new regression parameters
            # with the previous guess
            intercept = update_weight*intercept + (1.0-update_weight)*self.intercept_prev[i]
            slope = update_weight*slope + (1.0-update_weight)*self.slope_prev[i]
            AFunc_list.append(AggregateSavingRule(intercept,slope)) # Make a new next-period capital function
            rSq_list.append(r_value**2)

            # Save the new values as "previous" values for the next iteration
            self.intercept_prev[i] = intercept
            self.slope_prev[i] = slope

        # Plot aggregate resources vs aggregate savings for this run and print the new parameters
        if verbose:
            print('intercept=' + str(self.intercept_prev) + ', slope=' + str(self.slope_prev) + ', r-sq=' + str(rSq_list))
            #plt.show()

        return AggShocksDynamicRule(AFunc_list)