aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--R/build_portfolios.R5
-rw-r--r--python/monitor.py28
2 files changed, 31 insertions, 2 deletions
diff --git a/R/build_portfolios.R b/R/build_portfolios.R
index c50ceebb..01b689d7 100644
--- a/R/build_portfolios.R
+++ b/R/build_portfolios.R
@@ -104,7 +104,7 @@ for(deal.name in dealnames){
}
save(deal.portfolio, A, S, deal.weights, deal.dates, deal.spread5y,
deal.spreadatmaturity, deal.data, file=file.path(save.dir, paste0(deal.name, ".RData")))
- cat(deal.name, "... done\n")
+ cat(deal.name, "... done\n", file = stderr())
dealupdatedate <- currdealnames$updatedate[currdealnames$dealname %in% deal.name]
if(length(dealupdatedate) && dealupdatedate == workdate){
sqlstring <- sprintf(
@@ -140,5 +140,6 @@ for(deal.name in dealnames){
if(length(args)<1){
write.table(data.frame(dealnames, as.integer(!disablereinvflags)),
- file = file.path(root.dir, "scripts", "scenarios.txt"), row.names = F, col.names = F)
+ file = file.path(root.dir, "scripts", "scenarios.txt"),
+ row.names = F, col.names = F, quote = F)
}
diff --git a/python/monitor.py b/python/monitor.py
new file mode 100644
index 00000000..1929cb35
--- /dev/null
+++ b/python/monitor.py
@@ -0,0 +1,28 @@
+import os
+import time
+import subprocess
+import common
+import datetime
+from intex_scenarios import generate_scenarios
+
+Rpath = os.path.join(common.root, "code", "R")
+logpath = os.path.join(common.root, "logs")
+cusipsfile = os.path.join(common.root, "scripts", "cusips_to_price.txt")
+scenariosfile = os.path.join(common.root, "scripts", "scenarios.txt")
+args1 = ["Rscript", "--vanilla", os.path.join(Rpath, "build_portfolios.R")]
+args2 = ["Rscript", "--vanilla", os.path.join(Rpath, "build_scenarios.R")]
+while True:
+ workdate = str(datetime.date.today())
+ if os.path.exists(cusipsfile):
+ with open(os.path.join(logpath, "build_portfolios.Rout"), "w") as fh:
+ p = subprocess.Popen(args1, stderr = fh)
+ if os.path.exists(scenariosfile):
+ with open(scenariosfile) as fh:
+ dealnames = [line.split("\t")[0] for line in fh.readline()]
+ with open(os.path.join(logpath, "build_scenarios.Rout"), "w") as fh:
+ p = subprocess.(args2, stderr = fh)
+ p.wait()
+ generate_scenarios(workdate, dealnames, common.conn.common.cursor)
+ time.sleep(3)
+common.cursor.close()
+common.conn.close()