<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def update_holder(self, holder):
 """Udpate the Holder state according to the occurrence. This implementation is a example of how a Occurrence object can update the Holder state; this method should be overriden by classes that inherit from the Occurrence class. This sample implementation simply update the quantity and the average price of the Subject in the Holder's possession every time objects from this class are passed to Holder.trade(). This sample implementation considers the following signature for the Holder.state dict: .. code:: python { "SUBJECT SYMBOL": { "quantity": 0, "value": 0 } } And the following signature for the Occurrance.details dict: .. code:: python { "quantity": 0, "value": 0 } """


        subject_symbol = self.subject.symbol

        # If the Holder already have a state regarding this Subject,
        # update that state
        if subject_symbol in holder.state:

            # If the Holder have zero units of this subject, the average
            # value paid/received for the subject is the value of the trade itself
            if not holder.state[subject_symbol]['quantity']:
                holder.state[subject_symbol]['value'] = self.details['value']

            # If the Holder owns units of this subject then the average value
            # paid/received for the subject may need to be updated with
            # this occurrence details

            # If the occurrence have the same sign as the quantity in the Holder
            # state, a new average value needs to be calculated for the subject
            elif same_sign(
                    holder.state[subject_symbol]['quantity'],
                    self.details['quantity']):
                holder.state[subject_symbol]['value'] = average_price(
                    holder.state[subject_symbol]['quantity'],
                    holder.state[subject_symbol]['value'],
                    self.details['quantity'],
                    self.details['value']
                )

            # If the occurrence does not have the same sign of the quantity in the
            # Holder state, then do other stuff.
            # A trade app would normally implement some sort of profit/loss logic
            # here.
            # This sample implementation only checks if the average value
            # of the subject needs to be updated and then update it as needed.
            else:
                if same_sign(
                        self.details['quantity'],
                        holder.state[subject_symbol]['quantity'] + self.details['quantity']):
                    holder.state[subject_symbol]['value'] = self.details['value']

            # Update the quantity of the subject in the Holder's posession
            holder.state[subject_symbol]['quantity'] += self.details['quantity']

        # If the Holder don't have a state with this occurrence's Subject,
        # then register this occurrence as the first state of the Subject
        # in the Holder's possession
        else:
            holder.state[subject_symbol] = {
                'quantity': self.details['quantity'],
                'value': self.details['value']
            }

        # If the Holder knows about this Subject but don't have any unit
        # of it, the paid value of the subject in the Holder state should
        # be zero.
        if not holder.state[subject_symbol]['quantity']:
            holder.state[subject_symbol]['value'] = 0