def __init__(self): config = GlobalConfig() path = config.getConfig('SubConfigPath', 'StressTesting_win') self.cp = configparser.ConfigParser() self.cp.read(path, encoding='utf-8-sig') td = TradingDay() self.ltd = td.getLastTradingDay()
def __init__(self, product, enddate=None): self.product = product self.enddate = enddate td = TradingDay() ltd = td.getLastTradingDay() if enddate is None: self.enddate = ltd
def setBPIH(self): BPI_table = self.getConfig('BPI_table', 'table') td = TradingDay() lastTradingDay = td.getLastTradingDay() sqls = "select * from %s where Occur_Date = '%s'" % (BPI_table, lastTradingDay) return sqls
def __init__(self, productID, EndDate=None): self.productID = productID if EndDate is None: td = TradingDay() self.EndDate = td.getLastTradingDay() else: self.EndDate = EndDate
def __init__(self): config = GlobalConfig() path = config.getConfig('SubConfigPath', 'StressTesting_win') self.cp = configparser.ConfigParser() self.cp.read(path, encoding='utf-8-sig') td = TradingDay() self.ltd = td.getLastTradingDay() print("---- %s has been initialized! ----" % self.__class__.__name__)
def __init__(self): config = GlobalConfig() path = config.getConfig('SubConfigPath', 'API_conf_win') # path = config.getConfig('SubConfigPath', 'API_conf_linux') # print(path) self.cp = configparser.ConfigParser() self.cp.read(path, encoding='utf-8-sig') td = TradingDay() self.ltd = td.getLastTradingDay()
def __init__(self): config = GlobalConfig() self.mailserver = config.getConfig('email', 'mailserver') self.from_addr = config.getConfig('email', 'from_addr') self.sender_password = config.getConfig('email', 'sender_password') self.recipient = config.getConfig('email', 'recipient') td = TradingDay() self.date_of_subject = td.getLastTradingDay() self.subject = config.getConfig('email', 'subject') + self.date_of_subject self.attachmentFilePath = config.getConfig('email', 'attachmentFilePath')
def __init__(self, productID, EndDate=None): config = GlobalConfig() path = config.getConfig('SubConfigPath', 'StressTesting_win') self.cp = configparser.ConfigParser() self.cp.read(path, encoding='utf-8-sig') td = TradingDay() self.ltd = td.getLastTradingDay() self.productID = productID self.EndDate = EndDate
def portfolioVolatility(self): td = TradingDay() tradedays = td.getDuration(self.startdate, self.enddate) df_pcntg = pd.DataFrame() df_pcntg['TRADE_DT'] = tradedays df_pcntg['portfolio'] = float(0) # print(df_pcntg) oc = OracleConnector() oracle_connection = oc.getConn() ms = MySQLConnector() mysql_connection = ms.getConn() for stock in self.stocklist: if stock[-3:] == '.SH' or stock[-3:] == '.SZ': sqls = """select TRADE_DT, S_DQ_PCTCHANGE "%s" from wind.AShareEODPrices where S_INFO_WINDCODE = '%s'and TRADE_DT >= '%s'and TRADE_DT <= '%s' order by TRADE_DT""" \ % (stock, stock, self.startdate, self.enddate) df_stock = pd.read_sql(sql=sqls, con=oracle_connection) # print(df_stock) else: sqls = """select L_DATE as TRADE_DT, round((EN_LAST_PRICE - EN_YESTERDAY_CLOSE_PRICE)/EN_YESTERDAY_CLOSE_PRICE, 4) as "%s" from O32_THISSTOCKINFO where VC_REPORT_CODE = "%s" and L_DATE >= '%s' and L_DATE <= '%s' order by L_DATE""" \ % (stock, stock, self.startdate, self.enddate) df_stock = pd.read_sql(sql=sqls, con=mysql_connection) df_stock['TRADE_DT'] = df_stock['TRADE_DT'].astype(str) df_stock[stock] = df_stock[stock] * 100 # print(df_stock) weight = self.df_input.loc[self.df_input['VC_SCDM'] == stock, 'EN_SZZJZ'].values # print(weight) df_stock[stock] = df_stock[stock].astype(float) * weight / 100 # print(type(df_stock['TRADE_DT'][0])) df_pcntg = pd.merge(df_pcntg, df_stock, how='outer', on='TRADE_DT') df_pcntg = df_pcntg.fillna(0) df_pcntg['portfolio'] += df_pcntg[stock] # print(df_pcntg) oc.closeConn() ms.closeConn() # print(list(df_pcntg['portfolio'])) # writer = pd.ExcelWriter("D:\PerformanceAnalysis/output.xlsx") # print(df_pcntg) # df_pcntg.to_excel(writer, 'Sheet2') # writer.save() vol = df_pcntg['portfolio'].std() * np.sqrt(20) print("Stock Portfolio Volatility: %.4f" % vol) return vol
def portfolioVolatility(self): td = TradingDay() tradedays = td.getDuration(self.startdate, self.enddate) df_pcntg = pd.DataFrame() df_pcntg['TRADE_DT'] = tradedays df_pcntg['portfolio'] = float(0) # print(df_pcntg) oc = OracleConnector() oracle_connection = oc.getConn() ms = MySQLConnector() mysql_connection = ms.getConn() for pb in self.purebondlist: sqls = """select TRADE_DT, b_anal_net_cnbd "%s" from wind.cbondanalysiscnbd where S_INFO_WINDCODE = '%s'and TRADE_DT >= '%s'and TRADE_DT <= '%s' order by TRADE_DT""" \ % (pb, pb, self.startdate, self.enddate) sqls_minus1day = """select TRADE_DT, b_anal_net_cnbd "%s" from wind.cbondanalysiscnbd where S_INFO_WINDCODE = '%s'and TRADE_DT >= '%s'and TRADE_DT <= '%s' order by TRADE_DT""" \ % (pb, pb, self.startdate_minus1day, self.enddate_minus1day) # print(sqls) df_pb = pd.read_sql(sql=sqls, con=oracle_connection) df_pb_minus1day = pd.read_sql(sql=sqls_minus1day, con=oracle_connection) # print(df_pb, df_pb_minus1day) df_pb[pb] = (df_pb[pb] / df_pb_minus1day[pb] - 1) * 100 # print(df_pb) weight = self.df_input.loc[self.df_input['VC_SCDM'] == pb, 'EN_SZZJZ'].values # print(weight) df_pb[pb] = df_pb[pb].astype(float) * weight / 100 # print(type(df_pb['TRADE_DT'][0])) df_pcntg = pd.merge(df_pcntg, df_pb, how='outer', on='TRADE_DT') # df_pcntg = df_pcntg.fillna(0) df_pcntg['portfolio'] += df_pcntg[pb] # print(df_pcntg) oc.closeConn() ms.closeConn() # print(list(df_pcntg['portfolio'])) # writer = pd.ExcelWriter("D:\PerformanceAnalysis/output.xlsx") # df_pcntg.to_excel(writer, 'Sheet2') # writer.save() vol = df_pcntg['portfolio'].std() * np.sqrt(20) print("PB Portfolio Volatility: %.4f" % vol) return round(vol, 4)
def __init__(self, productID, EndDate=None): m = APIS() sqls = m.setAPIS(productID, EndDate) sqls_stock = m.stock(productID, EndDate) sqls_purebond = m.pureBond(productID, EndDate) sqls_convertablebond = m.convertableBond(productID, EndDate) ms = MySQLConnector() connection = ms.getConn() self.df = pd.read_sql(sql=sqls, con=connection) self.df_stock = pd.read_sql(sql=sqls_stock, con=connection) self.df_purebond = pd.read_sql(sql=sqls_purebond, con=connection) self.df_convertablebond = pd.read_sql(sql=sqls_convertablebond, con=connection) ms.closeConn() # print(self.df) td = TradingDay() self.checker_naturaldays = td.getProductNaturalDayCounts( productID, EndDate) self.checker_tradedays = td.getProductTradingDayCounts( productID, EndDate)
def portfolioVolatility(self): td = TradingDay() tradedays = td.getDuration(self.startdate, self.enddate) df_pcntg = pd.DataFrame() df_pcntg['TRADE_DT'] = tradedays df_pcntg['portfolio'] = float(0) # print(df_pcntg) oc = OracleConnector() oracle_connection = oc.getConn() ms = MySQLConnector() mysql_connection = ms.getConn() for cb in self.cblist: sqls = """select TRADE_DT, S_DQ_PCTCHANGE "%s" from wind.CBondEODPrices where S_INFO_WINDCODE = '%s'and TRADE_DT >= '%s'and TRADE_DT <= '%s' order by TRADE_DT""" \ % (cb, cb, self.startdate, self.enddate) # print(sqls) df_cb = pd.read_sql(sql=sqls, con=oracle_connection) weight = self.df_input.loc[self.df_input['VC_SCDM'] == cb, 'EN_SZZJZ'].values # print(weight) df_cb[cb] = df_cb[cb].astype(float) * weight / 100 # print(type(df_cb['TRADE_DT'][0])) df_pcntg = pd.merge(df_pcntg, df_cb, how='outer', on='TRADE_DT') df_pcntg = df_pcntg.fillna(0) df_pcntg['portfolio'] += df_pcntg[cb] # print(df_pcntg) oc.closeConn() ms.closeConn() # print(df_pcntg) # print(list(df_pcntg['portfolio'])) # writer = pd.ExcelWriter("D:\PerformanceAnalysis/output.xlsx") # df_pcntg.to_excel(writer, 'Sheet2') # writer.save() vol = df_pcntg['portfolio'].std() * np.sqrt(20) print("CB Portfolio Volatility: %.4f" % vol) return round(vol, 4)
from Common.GlobalConfig import GlobalConfig from Common.TradingDay import TradingDay from StressTesting.DailyGenerate_StressScenarioCal import DGSSC # Get product list fromm config.ini gc = GlobalConfig() product_list_tmp = gc.getConfig('product', 'list') product_list = product_list_tmp.split(", ") print(product_list) # Get last trade day td = TradingDay() date = td.getLastTradingDay() # tradeday = "%s-%s-%s" % (lastTradingDay[:4], lastTradingDay[4:6], lastTradingDay[-2:]) # date = "20190211" # Use product id and trade day to generate basic info and finish import to Basic Performance Info table for p in product_list: dgssc = DGSSC(p, date) dgssc.Data_Insert()
def __init__(self): td = TradingDay() self.ltd = td.getLastTradingDay() ss = StressScenario() self.scenario = ss.ScenarioDataRetrieve('ScenarioList_Stock')
from Common.GlobalConfig import GlobalConfig from Common.TradingDay import TradingDay from PerformanceAnalysis.DailyGenerate_BasicPerformanceInfo import DGBPI # ---------- Batch BPI data generate and import to MySQL ------------ # Get product list fromm config.ini gc = GlobalConfig() product_list_tmp = gc.getConfig('product', 'list') product_list = product_list_tmp.split(", ") print(product_list) # Get tradedays since product founded td = TradingDay() for p in product_list: tradedays = td.getProductDurationSinceFounded(p) for tradeday in tradedays: t = "%s-%s-%s" % (tradeday[:4], tradeday[4:6], tradeday[-2:]) dgbpi = DGBPI() dgbpi.composeArray(p, t) dgbpi.insertArray()
from Common.GlobalConfig import GlobalConfig from Common.TradingDay import TradingDay from PerformanceAnalysis.DailyGenerate_BasicPerformanceInfo import DGBPI # ---------- Daily BPI data generate and import to MySQL ------------ # Get product list fromm config.ini gc = GlobalConfig() product_list_tmp = gc.getConfig('product', 'list') product_list = product_list_tmp.split(", ") print(product_list) # Get last trade day td = TradingDay() lastTradingDay = td.getLastTradingDay() tradeday = "%s-%s-%s" % (lastTradingDay[:4], lastTradingDay[4:6], lastTradingDay[-2:]) print(tradeday) # Import by designated day, use only when amend history data # td = "2018-10-15" # Use product id and trade day to generate basic info and finish import to Basic Performance Info table for p in product_list: dgbpi = DGBPI() dgbpi.composeArray(p, tradeday) dgbpi.insertArray()