aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/client.py6
-rw-r--r--python/master.py22
-rw-r--r--python/tasks.py23
3 files changed, 44 insertions, 7 deletions
diff --git a/python/client.py b/python/client.py
index 5f7ec6d6..6008765c 100644
--- a/python/client.py
+++ b/python/client.py
@@ -1,8 +1,12 @@
import redis
import tasks
-from pickle import loads
+from pickle import loads, dumps
q = redis.Redis()
while True:
f, args = loads(q.blpop("tasks")[1])
getattr(tasks, f)(*args)
+ if f == "build_portfolio":
+ q.rpush("tasks", dumps(("build_scenarios", args)))
+ if f == "build_scenarios":
+ q.rpush("tasks", dumps(("generate_scenarios", args[:-1])))
diff --git a/python/master.py b/python/master.py
index e1e488d2..bc89a8aa 100644
--- a/python/master.py
+++ b/python/master.py
@@ -1,8 +1,26 @@
import redis
from pickle import dumps
import datetime
+import os
+import common
+import time
+import pdb
+cusipsfile = os.path.join(common.root, "scripts", "cusips_to_price.txt")
q = redis.Redis()
workdate = str(datetime.date.today())
-for dealname in ['ares26', 'carlg131', 'cata131']:
- q.rpush("tasks", dumps(("generate_scenarios", [workdate, dealname])))
+
+while True:
+ if os.path.exists(cusipsfile):
+ with open(cusipsfile) as fh:
+ cusip, reinvflag = zip(*[line.rstrip().split("\t") for line in fh])
+ c = common.conn.cursor()
+ sqlstr = "select * from dealname_from_cusip({0})".format(",",join(["%s"]*len(cusip)))
+ c.execute(sqlstr, params = cusip)
+ dealnames = [d[0] for d in c.fetchall()]
+
+ q.rpush("tasks", dumps(("build_portfolio", [workdate, dealname, reinvflag])))
+ os.unlink(cusipsfile)
+ time.sleep(3)
+
+common.conn.close()
diff --git a/python/tasks.py b/python/tasks.py
index e842343c..e8db6d26 100644
--- a/python/tasks.py
+++ b/python/tasks.py
@@ -1,8 +1,23 @@
import subprocess
from intex_scenarios import generate_scenarios
+import os
-def build_portfolio(dealname):
- pass
+if os.name =='nt':
+ root = "//WDsentinel/share/CorpCDOs"
+elif os.name == 'posix':
+ root = '/home/share/CorpCDOs'
-def build_scenario(dealname):
- pass
+Rpath = os.path.join(root, "code", "R")
+logpath = os.path.join(root, "logs")
+
+def build_portfolio(workdate, dealname, reinvflag):
+ args = ["Rscript", "--vanilla", os.path.join(Rpath, "build_portfolios.R"), \
+ workdate, dealname + "," + reinvflag]
+ with open(os.path.join(logpath, "build_portfolios.Rout"), "w") as fh:
+ subprocess.call(args, stderr = subprocess.STDOUT, stdout = fh)
+
+def build_scenarios(workdate, dealname, reinvflag):
+ args = ["Rscript", "--vanilla", os.path.join(Rpath, "build_scenarios.R"), \
+ workdate, dealname + "," + reinvflag]
+ with open(os.path.join(logpath, "build_scenarios.Rout"), "w") as fh:
+ subprocess.call(args, stderr = subprocess.STDOUT, stdout = fh)