Skip to content
Browse files

Merged. Fixed paths issue for weka

  • Loading branch information...
2 parents cb40c22 + ac05690 commit bbeb9969d6305943b38e5fb9ae6038a6dd13f243 root committed Apr 20, 2012
Showing with 33 additions and 11 deletions.
  1. +6 −3 ai/ann/predict_company.py
  2. +3 −1 ai/ann/weka.py
  3. +2 −0 ai/bayes/nohup.out
  4. +2 −1 ai/bayes/update_technical_analysis_calculation.rb
  5. +20 −6 mine/mine.py
View
9 ai/ann/predict_company.py
@@ -7,7 +7,8 @@
def write_to_file(filename, data, name):
f = open(filename, 'w')
f.write(
-"""@RELATION %s
+"""%%
+@RELATION '%s'
@ATTRIBUTE date DATE yyyy-MM-dd
@ATTRIBUTE short_ema NUMERIC
@ATTRIBUTE long_ema NUMERIC
@@ -30,6 +31,7 @@ def get_company(symbol):
conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='', db='limitless')
cur = conn.cursor()
cur.execute('SELECT date, short_ema, long_ema, histogram FROM company_%(symbol)s ORDER BY date DESC LIMIT 500' %{'symbol': upper(symbol) })
+# cur.execute('SELECT date, volume, high_price, low_price, open_price, close_price, close_adjusted, price_change, short_ema, long_ema, macd, signal_line, histogram FROM company_%(symbol)s ORDER BY date' %{'symbol': upper(symbol) })
days = datetime.timedelta(22)
train_data = []
@@ -48,8 +50,9 @@ def get_company(symbol):
filename2 = "arff/" + symbol + ".test.arff"
write_to_file(filename, train_data, symbol)
write_to_file(filename2, test_data, symbol)
-
- execs = '/usr/bin/jython weka.py arff/' + symbol + '.train.arff arff/' + symbol + '.test.arff'
+
+ execs = 'jython -D/usr/share/java/weka.jar weka.py arff/' + symbol + '.train.arff arff/' + symbol + '.test.arff'
+ execs = 'jython weka.py arff/' + symbol + '.train.arff arff/' + symbol + '.test.arff'
os.system(execs);
return dates;
View
4 ai/ann/weka.py
@@ -3,6 +3,8 @@
import java.lang.StringBuffer as StringBuffer
import java.lang.Boolean as Boolean
+sys.path.append('/usr/share/java/weka.jar')
+
import weka.core.Instances as Instances
import weka.classifiers.trees.J48 as J48
import weka.classifiers.Evaluation as Evaluation
@@ -12,7 +14,7 @@
# check commandline parameters
if (not (len(sys.argv) == 3)):
- print "Usage: UsingJ48Ext.py <ARFF-file>"
+ print "Usage: weka.py <ARFF-file>"
sys.exit()
file = FileReader(sys.argv[1])
View
2 ai/bayes/nohup.out
@@ -4565049,3 +4565049,5 @@ YES 2009-11-17: 7 2009-11-16: 6.42
160218.0
160218.0
160218.0
+update_technical_analysis_calculation.rb:54: syntax error, unexpected '}', expecting kEND
+update_technical_analysis_calculation.rb:57: syntax error, unexpected $end, expecting kEND
View
3 ai/bayes/update_technical_analysis_calculation.rb
@@ -51,7 +51,8 @@ def calcHistogram(macd, signal)
tech = con.query("UPDATE #{table} set short_ema=#{sema}, long_ema=#{lema}, macd=#{macd}, signal_line=#{signal}, histogram=#{hist} WHERE date='#{row}'")
# puts "#{table} #{row} short ema: #{sema} long ema: #{lema} macd: #{macd} signal line: #{signal} histogram: #{hist}"
}
- }
+ end
+ }
con.close
View
26 mine/mine.py
@@ -26,7 +26,9 @@ def get_industries(sector):
if len(industry) == 2:
industry['id'] = int(industry['id'])
industry['name'] = industry['name'].encode('ascii', errors='ignore')
- cur.execute('INSERT INTO industries (yahoo_id, name) VALUES(%(num)i, "%(name)s")' %{'num': industry['id'], 'name': industry['name']})
+ industry_count = cur.execute('SELECT name FROM industries WHERE name LIKE %s' %(industry['name']))
+ if (industry_count == 0)
+ cur.execute('INSERT INTO industries (yahoo_id, name) VALUES(%(num)i, "%(name)s")' %{'num': industry['id'], 'name': industry['name']})
get_companies(industry['id'], cur)
cur.close()
@@ -51,17 +53,31 @@ def get_companies(industry, cur):
company['name'] = company['name'].encode('ascii', errors='ignore')
print company['name']
company['symbol'] = company['symbol'].replace('.', '_')
- cur.execute('INSERT INTO companies (name, symbol) VALUES (%s, %s)', (company['name'], company['symbol']))
+
+ company_count = cur.execute('SELECT name FROM industries WHERE name LIKE %s' %(industry['name']))
+ if (company_count == 0)
+ cur.execute('INSERT INTO companies (name, symbol) VALUES (%s, %s)', (company['name'], company['symbol']))
+
get_historical_prices(company['symbol'], cur, startdate.replace('-', ''), str(enddate)[:10].replace('-', ''))
-#TODO: I think i'm requesting too much data from YQL. That's the only thing that would explain why i get None results. Will switch back to old URL
+#I think i'm requesting too much data from YQL. That's the only thing that would explain why i get None results. Will switch back to old URL
def get_historical_prices(symbol, cur, start_date, end_date):
"""
Get historical prices for the given ticker symbol.
Date format is 'YYYYMMDD'
Returns a nested list.
"""
+ rowcount = cur.execute('SELECT date FROM company_%s ORDER BY date DESC LIMIT 1' %(symbol)) # %(symbol))
+ rowcount = cur.execute('SELECT date FROM company_%s ORDER BY date DESC LIMIT 1' %(symbol)) # %(symbol))
+ if (rowcount == 1):
+ dates = cur.fetchall()
+ start_date = dates[0][0].isoformat()[:10].replace('-', '')
+ else:
+ file = open("db_scripts/create_company.template.sql");
+ cur.execute(file.read() %{'symbol': symbol})
+ file.close()
+
url = 'http://ichart.yahoo.com/table.csv?s=%s&' % symbol + \
'd=%s&' % str(int(end_date[4:6]) - 1) + \
'e=%s&' % str(int(end_date[6:8])) + \
@@ -71,13 +87,11 @@ def get_historical_prices(symbol, cur, start_date, end_date):
'b=%s&' % str(int(start_date[6:8])) + \
'c=%s&' % str(int(start_date[0:4])) + \
'ignore=.csv'
+ sys.exit(0)
days = urllib.urlopen(url).readlines()
data = [day[:-2].split(',') for day in days]
- file = open("db_scripts/create_company.template.sql");
- cur.execute(file.read() %{'symbol': symbol})
- file.close()
for stock in data[1:]:
if len(stock) == 7:

0 comments on commit bbeb996

Please sign in to comment.
Something went wrong with that request. Please try again.