hatgit / forex-gpt

ForexGPT presents Forex Rates: Advanced Natural Language Processing for Currency Markets. Gain insights, sentiment evaluation, and text completion using the power of language models.
https://forex-gpt.ai
MIT License
12 stars 4 forks source link

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

Open hatgit opened 1 year ago

hatgit commented 1 year ago

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)}```