Skip to content

Explore potential improvement to unlock SMA and technical analysis code block in main.py using Evals #3

Description

@hatgit

Source: https://github.com/openai/evals/blob/main/docs/custom-eval.md as well as the new functions and function_call as per OpenAI's recent announcement.

        try:
            candles = self.get_oanda_candles(instrument, from_time, granularity, price)

            if not candles:
                return "Failed to fetch candles."

            candles_percentage = self.determine_candles_to_analyze(granularity)
            num_candles = int(len(candles) * candles_percentage)
            last_candles = candles[-num_candles:]

            closing_prices = np.array([float(candle['mid']['c']) for candle in last_candles])

            sma_periods = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 25, 30, 40, 50, 100, 200]
            smas = {}
            for period in sma_periods:
                sma = np.mean(closing_prices[-period:])
                smas[period] = sma

            trailing_sma_average = np.mean(list(smas.values()))

            sentiment = 'Uncertain'  # Default sentiment

            if closing_prices[-1] > trailing_sma_average:
                if closing_prices[-1] - trailing_sma_average > 0.1 * trailing_sma_average:
                    sentiment = 'Very bullish'
                else:
                    sentiment = 'Bullish'
            elif closing_prices[-1] < trailing_sma_average:
                if trailing_sma_average - closing_prices[-1] > 0.1 * trailing_sma_average:
                    sentiment = 'Very bearish'
                else:
                    sentiment = 'Bearish'

            # Return sentiment and SMAs
            return {'sentiment': sentiment, 'smas': smas}
        except Exception as e:
            print(f"Error analyzing market: {e}")
            return {'error': str(e)}```

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions