Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hatgit opened this issue Jun 16, 2023 · 0 comments

Comments

@hatgit
Copy link
Owner

hatgit commented Jun 16, 2023

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)}```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant