| def grade_task2(action, observation): |
| """ |
| Task 2: News Sentiment Analysis with Explanation |
| Grades: Quality of reasoning, financial knowledge, clarity |
| This is your unique innovation! |
| """ |
| score = 0.0 |
| |
| |
| explanation = action.get('explanation', '') if action else '' |
| |
| |
| if len(explanation) > 100: |
| score += 0.3 |
| elif len(explanation) > 50: |
| score += 0.2 |
| elif len(explanation) > 20: |
| score += 0.1 |
| else: |
| score += 0.02 |
| |
| |
| financial_terms = [ |
| 'pe', 'p/e', 'valuation', 'earnings', |
| 'moving average', 'trend', 'momentum', 'rsi', |
| 'support', 'resistance', 'breakout', |
| 'risk', 'volatility', 'drawdown', 'sharpe', |
| 'sentiment', 'market cap', 'liquidity' |
| ] |
| terms_found = sum(1 for term in financial_terms if term in explanation.lower()) |
| score += min(0.3, terms_found * 0.05) |
| |
| |
| reasoning_words = ['because', 'therefore', 'since', 'due to', 'based on', 'as a result'] |
| if any(word in explanation.lower() for word in reasoning_words): |
| score += 0.2 |
| |
| |
| import re |
| if re.search(r'\d+', explanation): |
| score += 0.05 |
| if '%' in explanation: |
| score += 0.05 |
| |
| |
| recommendations = ['buy', 'sell', 'hold', 'accumulate', 'reduce'] |
| if any(word in explanation.lower() for word in recommendations): |
| score += 0.1 |
| |
| |
| score = max(0.01, min(0.99, score)) |
| |
| return round(score, 2) |
|
|