def checkRule()

in src/backend/domain/services/steps/risk_limit.py [0:0]


    def checkRule(self, acct_ccy_pnl, curr_date, datetime_index):
        # if no account currency pnl then return None
        if not acct_ccy_pnl:
            return None

        curr_value = acct_ccy_pnl[-1]

        if self.period == Period.YTD:
            period_start_date = datetime(curr_date.year, 1, 1)  # beginning of the year
        elif self.period == Period.Month:
            period_start_date = datetime(curr_date.year, curr_date.month, 1)  # beginning of the month
        elif self.period == Period.Quarter:
            quarter = (curr_date.month - 1) // 3 + 1
            period_start_date = datetime(curr_date.year, 3 * quarter - 2, 1)  # beginning of the quarter

        period_start_index = datetime_index.get_loc(period_start_date, method="nearest")
        period_start_value = acct_ccy_pnl[period_start_index]

        # if rule type is MaxLoss and loss is more than lossAmount then return action
        if self.type == Type.MaxLoss and (curr_value - period_start_value) < -self.lossAmount:
            return self.action

        # if rule type is MaxDrawDown
        if self.type == Type.MaxDrawDown:
            # get start values
            start_values = acct_ccy_pnl[period_start_index:]
            if len(start_values) > 0:
                max_drawdown = min([curr_value - start for start in start_values])
            else:
                max_drawdown = 0

            if max_drawdown < -self.lossAmount:
                return self.action

        return None