import pandas as pd from pandas.io.json import json_normalize # import cx_Oracle import sqlalchemy from functools import wraps import Tools.DateHelper as dh import Tools.DataBaseHelper as DB import warnings warnings.simplefilter(action="ignore", category=Warning) # conn=cx_Oracle.connect('FITRADINGSERVER/FITRADINGSERVER@FITRADE') #连接数据库 Engine = DB.getEngine('172.18.3.43', 'sa', 'tcl+nftx', 'VirtualExchange') EngineIS = DB.getEngine('172.18.3.43', 'sa', 'tcl+nftx', 'InvestSystem')
# 计算各个组合的回撤 import pandas as pd import numpy as np import Tools.DateHelper as dh import Tools.DataBaseHelper as DB import sqlalchemy import time import warnings warnings.simplefilter(action="ignore", category=Warning) Engine = DB.getEngine('10.28.7.43', 'bond', 'bond', 'Report') Engine73 = DB.getEngine('192.168.87.73', 'sa', 'tcl+nftx', 'MarketMaker') # 读取原始数据 def ReadProfitData(): Df1 = pd.read_sql( "SELECT TradeDate,InvestType,TotalProfit as NetProfit,WeightedPrinciple,WeightedMoney, sortid FROM [MarketMaker].[dbo].[FundAnalysis_Sum] order by TradeDate", Engine73) DfFF = pd.read_sql( "select * from openquery(TEST1,'select substr(t.bondcode,4,1) type, t.bondname,t.bondcode,t.issueday,t.allocationamt,b.term from ibond.DSC_BONDSALEPROFIT t inner join ibond.VIEW_DH b on t.bondcode = b.code where t.username in (''翁应良'',''姚子剑'',''郭圣雨'',''李剑波'',''张智博'') and t.category = ''金融债'' and t.allocationamt > 0 and substr(t.bondcode,4,1) in (2,3) and to_date(t.issueday,''yyyy-mm-dd'')> trunc(sysdate,''y'') order by t.id desc ')", Engine) def ff(type, term, amt): type = float(type) term = float(term) if type == 2: switch = { 1: 0.08, 2: 0.08,
import datetime import time import pandas as pd import sqlalchemy import Tools.DateHelper as dh import Tools.DataBaseHelper as DB from playsound import playsound import warnings warnings.simplefilter(action="ignore", category=Warning) Engine = DB.getEngine('10.28.7.43', 'sa', 'tcl+nftx', 'VirtualExchange') from xfTTs import * from TTS import *
import datetime import pandas as pd import numpy as np import scipy.stats as st import Tools.DateHelper as dh import Tools.DataBaseHelper as DB import sqlalchemy import warnings warnings.simplefilter(action="ignore", category=Warning) Engine = DB.getEngine('10.28.7.43', 'sa', 'tcl+nftx', 'InvestSystem') import funcs as Fn
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 计算NCD余额变动 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # import pandas as pd import Tools.DateHelper as dh import Tools.DataBaseHelper as DB import sqlalchemy import time import warnings warnings.simplefilter(action="ignore", category=Warning) Engine = DB.getEngine('10.28.7.43', 'bond', 'bond', 'InvestSystem') # 计算单日的NCD余额数据 def OneDayBalance(dateString): Df = pd.read_sql( "select * from openquery(WINDNEW,'select nvl(a.b_info_issuertype,b.b_info_issuertype) banktype,nvl(a.amt,0)-nvl(b.amt,0) netamt from (select b_info_issuertype,sum(B_ISSUE_AMOUNTACT) amt from CBONDDESCRIPTION where b_info_specialbondtype = ''同业存单'' and B_INFO_LISTDATE=''" + dateString + "'' group by b_info_issuertype) a full join (select b_info_issuertype,sum(B_ISSUE_AMOUNTACT) amt from CBONDDESCRIPTION where b_info_specialbondtype = ''同业存单'' and B_INFO_MATURITYDATE=''" + dateString + "'' group by b_info_issuertype) b on a.b_info_issuertype = b.b_info_issuertype')", Engine) if Df.shape[0] > 0: Df.NETAMT = Df.NETAMT.astype('float') bankTypeList = ['城市商业银行', '国有商业银行', '股份制商业银行', '政策性银行'] DfOld = pd.read_sql( "select BANKTYPE , NETAMT from NCDBalance where date = (select max(date) from NCDBalance where date<'" + dateString + "') and BANKTYPE !='合计'", Engine) DfOld.NETAMT = DfOld.NETAMT.astype('float')
import pandas as pd import Tools.DataBaseHelper as DB import time import pika import warnings from time import sleep warnings.simplefilter(action = "ignore", category = Warning) Engine = DB.getEngine('10.28.7.43', 'bond', 'bond', 'VirtualExchange') if __name__ == '__main__': credentials = pika.PlainCredentials('bond', 'bond') connection = pika.BlockingConnection( pika.ConnectionParameters('192.168.87.103', 5672, '/', credentials, heartbeat=0)) channel = connection.channel() channel.exchange_declare(exchange='checkpositionstatus', exchange_type='fanout', durable=True) while True: try: Df = pd.read_sql("SELECT [NotAllowAdd] FROM [InvestSystem].[dbo].[positionpsw]", Engine) channel.basic_publish(exchange='checkpositionstatus', routing_key='', body=Df.to_json(orient='records')) print('success-- '+time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))) sleep(2) except: sleep(2) print('error-- ' + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))) pass
import datetime import pandas as pd import numpy as np from pandas.io.json import json_normalize import sqlalchemy from functools import wraps import Tools.DateHelper as dh import re import Tools.DataBaseHelper as DB import warnings warnings.simplefilter(action="ignore", category=Warning) # import cx_Oracle # conn=cx_Oracle.connect('FITRADINGSERVER/FITRADINGSERVER@FITRADE') #连接数据库 # conn=cx_Oracle.connect('tmpuser/[email protected]:1521/orcl') #连接数据库 Engine = DB.getEngine('10.28.7.43', 'bond', 'bond', 'VirtualExchange') Engine73 = DB.getEngine('192.168.87.73', 'sa', 'tcl+nftx', 'MarketMaker') EngineIS = DB.getEngine('10.28.7.43', 'bond', 'bond', 'InvestSystem') Engine103 = DB.getEngine('192.168.87.103', 'sa', 'sa123', 'Invest') import Tools.MongoHelper as MG crmDb = MG._connect_mongo("10.28.7.35", 39362, "datacenter", "datacenter", "datacenter") import redis pool = redis.ConnectionPool(host='192.168.9.147', port=6379, decode_responses=True) r = redis.Redis(connection_pool=pool)
import pandas as pd import sqlalchemy import Tools.DateHelper as dh import Tools.DataBaseHelper as DB import warnings warnings.simplefilter(action = "ignore", category = Warning) Engine = DB.getEngine('172.18.3.43', 'sa', 'tcl+nftx', 'VirtualExchange') BondList = [ 170004, 170006, 170007, 170010, 170013, 170014, 170016, 170018, 170020, 170021, 170023, 170025, 170027, 180001, 180002, 180007, 180008, 180013, 180014, 180015, 180016, 180019,
import Tools.DataBaseHelper as DB import warnings warnings.simplefilter(action = "ignore", category = Warning) conn = DB.getConn('192.168.87.103', 'sa', 'sa123', 'FutureTradeTest') cursor = conn.cursor() cursor.execute("update [FutureTradeTest].[dbo].[Account] set total_profit = 0,float_profit=0,real_profit=0,enable_amount = total_amount") cursor.execute("update [FutureTrade].[dbo].[Account] set total_profit = 0,float_profit=0,real_profit=0,enable_amount = total_amount") import redis pool = redis.ConnectionPool(host='192.168.87.103', port=6379, decode_responses=True) r = redis.Redis(connection_pool=pool) r.set('positionStr','0') r.set('positionStrTest','0')