Spaces:
Runtime error
Runtime error
File size: 2,341 Bytes
5913c8f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
import ollama
import numpy as np
import pandas as pd
from lightweight_charts import Chart
from transformers import AutoModelForCausalLM, AutoTokenizer
class IndicatorAnalyzer:
def __init__(self):
self.model = AutoModelForCausalLM.from_pretrained("tmm-dev/codellama-pattern-analysis")
self.tokenizer = AutoTokenizer.from_pretrained("tmm-dev/codellama-pattern-analysis")
def analyze_indicators(self, ohlcv_data):
indicator_prompt = f"""
Analyze this OHLCV data and calculate optimal indicators:
{ohlcv_data.to_json(orient='records')}
Calculate and return:
- Moving Averages (EMA, SMA with optimal periods)
- Oscillators (RSI, Stochastic, MACD)
- Volatility (Bollinger Bands, ATR)
- Volume indicators
- Custom combinations of indicators
Return the analysis in JSON format with exact values and coordinates.
"""
response = self.client.chat(
model='codellama:latest',
messages=[
{
'role': 'system',
'content': 'You are a technical analysis indicator calculation model.'
},
{
'role': 'user',
'content': indicator_prompt
}
]
)
return self.parse_indicator_analysis(response['message']['content'])
def parse_indicator_analysis(self, analysis):
try:
# Convert string response to structured data
if isinstance(analysis, str):
# Extract JSON if embedded in text
json_start = analysis.find('{')
json_end = analysis.rfind('}') + 1
if json_start >= 0 and json_end > 0:
analysis = analysis[json_start:json_end]
indicators = {
'moving_averages': {},
'oscillators': {},
'volatility': {},
'volume': {},
'custom': {}
}
# Add any custom parsing logic here
return indicators
except Exception as e:
print(f"Error parsing indicator analysis: {str(e)}")
return {}
|