Beispiel #1
0
    def calculate_signal(self, candle, compare_candle):
        '''
            Creates SignalSimulation object for candle provided.
        '''
        # default values for price difference
        p_default = {1: 80, 3: 0.01}

        if self.simulation_id in [1, 3]:
            calc_signal = self.calculate_signal_v1(
                candle, compare_candle, p_default[self.simulation_id])
        elif self.simulation_id == 2:
            calc_signal = self.calculate_signal_hindsight(
                candle, compare_candle.period_close)
        elif self.simulation_id == 4:
            calc_signal = self.calculate_signal_prophet(compare_candle)
        elif self.simulation_id == 5:
            calc_signal = self.calculate_signal_prophet(compare_candle)
            # Signal #5 is almost equivalent to #4 but takes into account Google Trend ratio
            if candle.search_trend:
                if candle.search_trend.trend_ratio and candle.search_trend.trend_ratio > 0.35:
                    calc_signal = "BUY"
        else:
            calc_signal = ""

        my_sim = SignalSimulation(crypto_candle=candle,
                                  simulation=self.simulation_obj,
                                  candle_compare=compare_candle,
                                  signal=calc_signal)
        my_sim.save()

        return my_sim
Beispiel #2
0
    def update_signal(self):
        '''
            Loops through candle subset to update signal and bank estimates. One-time update each time the data sources are updated.
            TODO (reminder): allow optional start/end date parameters
        '''
        # initiate variables to be used in loop
        prior_candle = None
        x = 0
        conditional_message = ''

        # Next, delete the existing simulation
        SignalSimulation.objects.filter(
            simulation=self.simulation_obj,
            crypto_candle__crypto_traded=self.currency).delete()

        # The only time we want to see the future first is when we are determining hindsight simulations.
        if self.simulation_id in [2, 4, 5]:
            loop_candles = self.candle_subset.order_by(
                '-period_start_timestamp')
            if self.simulation_id in [4, 5]:
                conditional_message += ' ' + self.predict_price()
        else:
            loop_candles = self.candle_subset.filter(
                search_trend__isnull=False).order_by('period_start_timestamp')

        for candle in loop_candles:
            # For initial candle, we will initialize the simulation and bank and do nothing else.
            if prior_candle is None:
                my_sim = SignalSimulation(crypto_candle=candle,
                                          simulation=self.simulation_obj)
                my_sim.save()

            else:
                days_diff = 0
                if candle.search_trend and prior_candle.search_trend:
                    candle_delta = candle.search_trend.date - prior_candle.search_trend.date
                    days_diff = candle_delta.days

                # below i want to make sure my delta is working along with my period interval. This will need to be updated once we introduce hourly intervals.
                if ((self.period_interval == "1d" and days_diff == 1)
                        or self.simulation_id in [2, 4, 5]):

                    sim_result = self.calculate_signal(candle, prior_candle)
                    # counting our success instances
                    if sim_result:
                        x += 1
            prior_candle = candle

        # Once we have updated all signals, we can model transaction history.
        transaction_sim = BankTransaction(self.candle_subset,
                                          self.simulation_obj, self.currency)
        transaction_sim.transaction_history()

        return f"Inserted {x} signal records on {timezone.now()}.{conditional_message}"
    def update_signal(self):
        '''
            Loops through candle subset to update signal and bank estimates. One-time update each time the data sources are updated.
            TODO (reminder): allow optional start/end date parameters
        '''
        # initiate variables to be used in loop
        prior_candle = ""
        x = 0
        # below i want to make sure my delta is working along with my period interval. This will need to be updated once we introduce hourly intervals.
        if self.period_interval == "1d":
            delta_requirement = 1

        # The only time we want to see the future first is when we are determining hindsight simulations.
        if self.simulation_id == 2:
            loop_candles = self.candle_subset.order_by(
                '-period_start_timestamp')
        else:
            loop_candles = self.candle_subset.order_by(
                'period_start_timestamp')

        for candle in loop_candles:
            # First, delete the existing simulation
            SignalSimulation.objects.filter(
                crypto_candle=candle, simulation=self.simulation_obj).delete()
            # For initial candle, we will initialize the simulation and bank and do nothing else.
            if prior_candle == "":
                my_sim = SignalSimulation(crypto_candle=candle,
                                          simulation=self.simulation_obj)
                my_sim.save()

            # Make sure we have required values to calculate signal: (1) a candle instance to compare against, (2) trend ratio to compare
            elif candle.search_trend.trend_ratio:
                candle_delta = candle.search_trend.date - prior_candle.search_trend.date
                # Make sure the two objects meet delta requirements
                if abs(candle_delta.days) == delta_requirement:

                    sim_result = self.calculate_signal(candle, prior_candle)
                    # counting our success instances
                    if sim_result:
                        x += 1
            prior_candle = candle

        # Once we have updated all signals, we can model transaction history.
        self.transaction_history()

        return f"Inserted {x} records on {timezone.now()}."
    def calculate_signal(self, candle, compare_candle):
        '''
            Creates SignalSimulation object for candle provided.
        '''
        # default values
        if self.simulation_id == 1:
            calc_signal = self.calculate_signal_v1(candle, compare_candle)
        elif self.simulation_id == 2:
            calc_signal = self.calculate_signal_actual(candle, compare_candle)
        else:
            calc_signal = ""

        my_sim = SignalSimulation(crypto_candle=candle,
                                  simulation=self.simulation_obj,
                                  candle_compare=compare_candle,
                                  signal=calc_signal)
        my_sim.save()

        return my_sim