import datetime
from datetime import date
Start_Date = date(2010, 01, 01)
market = 1
Query_PNL = """SELECT rptday,extract(year from rptday),extract(month from rptday),a.botid,closetoclosepnl,
case when closetoclosepnl > 0 then 1
when closetoclosepnl < 0 then 0
END AS PNL_score
FROM RESEARCH.ADMIN.BOTSDAILYPNL a
--order by botid desc, rptday asc;
right join
(SELECT marketid,botid,modelid
FROM RESEARCH.ADMIN.BOTS
where modelid = 2018 and botname like '%BackTesting')b
on a.MARKETID = b.marketid and a.BOTID = b.botid
where a.rptday >='2010-01-01' and a.rptday <='2010-01-31' and a.MARKETID = %s and PNL_score is not null
order by rptday asc""" %(market)
print Query_PNL
1 Answer
You need to escape the % character you're using in the like operator (by doubling it), so python doesn't attempt to evaluate it:
Query_PNL = """SELECT rptday,extract(year from rptday),extract(month from rptday),a.botid,closetoclosepnl,
case when closetoclosepnl > 0 then 1
when closetoclosepnl < 0 then 0
END AS PNL_score
FROM RESEARCH.ADMIN.BOTSDAILYPNL a
--order by botid desc, rptday asc;
right join
(SELECT marketid,botid,modelid
FROM RESEARCH.ADMIN.BOTS
where modelid = 2018 and botname like '%%BackTesting')
on a.MARKETID = b.marketid and a.BOTID = b.botid
where a.rptday >='2010-01-01' and a.rptday <='2010-01-31' and a.MARKETID = %s and PNL_score is not null
order by rptday asc""" %(market)
%in the%BackTesting...