RiskQuantLib.Tool package

Submodules

RiskQuantLib.Tool.GUITool module

guiAlert(tipString)[source]

This function will alert some information.

guiConfirm(tipString, doubtfulValueString)[source]

This function will ask confirmation of some information, if rejected, it will ask user to input a new one.

guiInput(tipString)[source]

This function will receive some information by GUI.

guiSelect(tipString, doubtfulValueList)[source]

This function will give some options to user to choose.

RiskQuantLib.Tool.codeTool module

class codeBuilder(indent=0, globalIndentStep=0)[source]

Bases: object

This class is the basic class used to generate source code of any language.

addLine(line)[source]
addSection()[source]
dedent()[source]
getGlobals()[source]
indent()[source]
class codeBuilderPython(indent=0, globalIndentStep=0)[source]

Bases: codeBuilder

addSection()[source]
getGlobals(execute=False)[source]
class pythonScriptBuilder[source]

Bases: object

This class is the python source code builder, used to generate python source code automatically.

endClass()[source]

Specify the end of a class.

endFunction()[source]

Specify the end of a function.

getSource()[source]

Get source code string.

setImport(libraryName, libraryAbbr='', importSubModule=False, subModuleName='')[source]

Import a module to python source file.

Parameters

libraryNamestr

The library name you want to import.

libraryAbbrstr

If not blank, library will be imported with the form ‘import libraryName as libraryAbbr’

importSubModulebool

If True, library will be imported with the form ‘from libraryName import subModuleName as libraryAbbr’

subModuleNamestr

If not blank and importSubModule is true, library will be imported with the form ‘from libraryName import subModuleName as libraryAbbr’

Returns

None

setTitle(title='')[source]

Set python source file title, including coding method and python version.

startClass(className, parentClassName='')[source]

Start a new class. This function must be followed by endClass()

startFunction(functionName, variableName='')[source]

Start a function. This function must be followed by endFunction()

writeToFile(filePathString)[source]

Output the source code to a file, use mode ‘w+’.

RiskQuantLib.Tool.databaseTool module

class mysqlConnector(databaseName, hostAddress, port, userName, passWord, charset='utf8mb4')[source]

Bases: sqlConnector

This is the API to connect with mysql database using PyMySQL.

class neo4jConnector(hostAddress, port, userName, password)[source]

Bases: object

This is the API to connect with neo4j database.

addNodeFromDF(nodeType, df, colAsName)[source]
connectNodeByAttr(nodeTypeLeft, nodeTypeRight, attrNameLeft, attrNameRight, relationName)[source]
convertDFToNode(nodeType, df, colAsName)[source]
convertDataType(x)[source]
deleteAllNode()[source]
deleteNode(nodeObj)[source]
readCypher(cypher)[source]
replaceNode(nodeObj)[source]
replaceNodeFromDF(nodeType, df, colAsName)[source]
selectAllLabel()[source]
selectAllNode(nodeType)[source]
selectAllNodeWithCondition(nodeType, conditionString, resultVariableName='res')[source]
selectAttrFromNode(nodeType, attrList)[source]
selectAttrFromNodeWithCondition(nodeType, attrList, conditionString, resultVariableName='res')[source]
updateDFToNode(nodeList, df, colAsName)[source]
class oracleConnector(databaseName, hostAddress, port, userName, passWord)[source]

Bases: sqlConnector

This is the API to connect with oracle database. Notice that this driver (oracledb) supports only sqlalchemy>=2.0.0. If you are using 1.4.0<=sqlalchemy<2.0.0, you can fix it by adding at the beginning of your python script:

import sys, oracledb oracledb.version = “8.3.0” sys.modules[“cx_Oracle”] = oracledb

Then change the following code into:

url = URL.create(drivername=’oracle+cx_oracle’, username=userName, password=passWord, host=hostAddress, port=port, database=databaseName)

class sqlConnector(engine)[source]

Bases: object

executeSql(sql, params=None)[source]

Execute DDL or DML (like UPDATE, DELETE, CREATE).

getAllTables(*args, **kwargs)[source]

Get names of all tables. You may need to specify schema=some if you are connecting to oracle or sqlserver.

getColNames(tableName, *args, **kwargs)[source]

Get all names of columns of a table. You may need to specify schema=some if you are connecting to oracle or sqlserver.

readSql(sql, *args, **kwargs)[source]

Execute sql and return a dataframe.

writeTable(df, tableNameString, ifExists='append')[source]

Write df into database, ifExists can be ‘fail’, ‘replace’, ‘append’.

class sqlServerConnector(databaseName, hostAddress, port, userName, passWord, charset='cp936')[source]

Bases: sqlConnector

This is the API to connect with sql server database.

RiskQuantLib.Tool.dateTool module

class argentinaMerval(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Argentina Merval.

holidayRule = <QuantLib.QuantLib.Argentina; proxy of <Swig Object of type 'QuantLib::Argentina *'> >

Quick way to initialize a null calendar.

class australiaASX(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Australia ASX.

holidayRule = <QuantLib.QuantLib.Australia; proxy of <Swig Object of type 'QuantLib::Australia *'> >

Quick way to initialize a null calendar.

class australiaSettlement(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Australia Settlement.

holidayRule = <QuantLib.QuantLib.Australia; proxy of <Swig Object of type 'QuantLib::Australia *'> >

Quick way to initialize a null calendar.

class austriaExchange(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Austria Exchange.

holidayRule = <QuantLib.QuantLib.Austria; proxy of <Swig Object of type 'QuantLib::Austria *'> >

Quick way to initialize a null calendar.

class austriaSettlement(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Austria Settlement.

holidayRule = <QuantLib.QuantLib.Austria; proxy of <Swig Object of type 'QuantLib::Austria *'> >

Quick way to initialize a null calendar.

class botswana(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Botswana.

holidayRule = <QuantLib.QuantLib.Botswana; proxy of <Swig Object of type 'QuantLib::Botswana *'> >

Quick way to initialize a null calendar.

class brazilExchange(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Brazil Exchange.

holidayRule = <QuantLib.QuantLib.Brazil; proxy of <Swig Object of type 'QuantLib::Brazil *'> >

Quick way to initialize a null calendar.

class brazilSettlement(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Brazil Settlement.

holidayRule = <QuantLib.QuantLib.Brazil; proxy of <Swig Object of type 'QuantLib::Brazil *'> >

Quick way to initialize a null calendar.

class calendar(holidayRule, otherHolidays=None)[source]

Bases: object

addHolidayRule(holidayRule)[source]

Add customized holiday rule, this will overwrite current holiday settings.

Return type:

None

addHolidays(holidays)[source]

Add customized holiday.

Return type:

None

static dateToTimestamp(date)[source]
Return type:

Timestamp

isTrading(date)[source]

Return True if a day is trading day.

Return type:

bool

makeSchedule(start, end, period, forwardAdjust=True, forwardScale=True, forwardAdjustEndDay=False)[source]

Generate periodical trading dates between start and end, given period.

makeScheduleByPeriod(start, period, count, forwardAdjust=True)[source]

Generate periodical trading dates. Warnings: If the first day is not a trading day, the next trading day will be used, thus leading to duplicated elements. So make sure the given start date is a trading day.

Return type:

List[Timestamp]

numTradingDaysBetween(start, end, countStart=True, countEnd=True)[source]

Return number of trading days between two dates.

Return type:

int

numTradingDaysBetweenGrid(start, dateList, countStart=True, countEnd=True)[source]

Return number of trading days between a date and a date list.

Return type:

List[int]

offset(date, n, period=0)[source]

Return date of trading day n days before or after date.

Return type:

Timestamp

static parsePeriod(period)[source]
Return type:

(int, int)

static timestampToDate(date)[source]
Return type:

Date

tradingDaysBetween(start, end, startPoint=True, endPoint=True)[source]

Return a list of trading days between start and end. Endpoints are counted only if they are trading.

Return type:

List[Timestamp]

unitKey = ['W', 'w', 'M', 'm', 'D', 'd', 'Y', 'y']
unitMap = {'D': 0, 'M': 2, 'W': 1, 'Y': 3, 'd': 0, 'm': 2, 'w': 1, 'y': 3}
unitValue = [1, 1, 2, 2, 0, 0, 3, 3]
updateCalendar(holidayRule, otherHolidays=None)[source]

Create a custom calendar using QuantLib.

Return type:

None

class canadaSettlement(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Canada Settlement.

holidayRule = <QuantLib.QuantLib.Canada; proxy of <Swig Object of type 'QuantLib::Canada *'> >

Quick way to initialize a null calendar.

class canadaTSX(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Canada TSX.

holidayRule = <QuantLib.QuantLib.Canada; proxy of <Swig Object of type 'QuantLib::Canada *'> >

Quick way to initialize a null calendar.

class chileSSE(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Chile SSE.

holidayRule = <QuantLib.QuantLib.Chile; proxy of <Swig Object of type 'QuantLib::Chile *'> >

Quick way to initialize a null calendar.

class chinaIB(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of China IB.

holidayRule = <QuantLib.QuantLib.China; proxy of <Swig Object of type 'QuantLib::China *'> >

Quick way to initialize a null calendar.

class chinaSSE(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of China SSE.

holidayRule = <QuantLib.QuantLib.China; proxy of <Swig Object of type 'QuantLib::China *'> >

Quick way to initialize a null calendar.

class czechRepublicPSE(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of CzechRepublic PSE.

holidayRule = <QuantLib.QuantLib.CzechRepublic; proxy of <Swig Object of type 'QuantLib::CzechRepublic *'> >

Quick way to initialize a null calendar.

class denmark(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Denmark.

holidayRule = <QuantLib.QuantLib.Denmark; proxy of <Swig Object of type 'QuantLib::Denmark *'> >

Quick way to initialize a null calendar.

class finland(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Finland.

holidayRule = <QuantLib.QuantLib.Finland; proxy of <Swig Object of type 'QuantLib::Finland *'> >

Quick way to initialize a null calendar.

class franceExchange(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of France Exchange.

holidayRule = <QuantLib.QuantLib.France; proxy of <Swig Object of type 'QuantLib::France *'> >

Quick way to initialize a null calendar.

class franceSettlement(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of France Settlement.

holidayRule = <QuantLib.QuantLib.France; proxy of <Swig Object of type 'QuantLib::France *'> >

Quick way to initialize a null calendar.

generateBusinessDateList(start, end, freq='D')[source]

This function will generate a list of business day.

Parameters

startpd.Timestamp

The range start.

endpd.Timestamp

The range end

freqstr

The frequency used to generate date list.

Returns

list

generateNextNWeekday(start, count)[source]

This function will return a list, whose elements are the next n weekdays.

class germanyEurex(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Germany Eurex.

holidayRule = <QuantLib.QuantLib.Germany; proxy of <Swig Object of type 'QuantLib::Germany *'> >

Quick way to initialize a null calendar.

class germanyFrankfurtStockExchange(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Germany FrankfurtStockExchange.

holidayRule = <QuantLib.QuantLib.Germany; proxy of <Swig Object of type 'QuantLib::Germany *'> >

Quick way to initialize a null calendar.

class germanySettlement(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Germany Settlement.

holidayRule = <QuantLib.QuantLib.Germany; proxy of <Swig Object of type 'QuantLib::Germany *'> >

Quick way to initialize a null calendar.

class germanyXetra(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Germany Xetra.

holidayRule = <QuantLib.QuantLib.Germany; proxy of <Swig Object of type 'QuantLib::Germany *'> >

Quick way to initialize a null calendar.

getNthWeekday(count, weekdayCode, on)[source]

This function will return the n-th weekday of the month, which contains the given day.

Parameters

countint

The n-th weekday you want to get

weekdayCodeint

The weekday code, use int from 1 to 7

onpd.Timestamp

The standing point, calculation will be done based on this day.

Returns

result : pd.Timestamp

class hongKongHKEx(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of HongKong HKEx.

holidayRule = <QuantLib.QuantLib.HongKong; proxy of <Swig Object of type 'QuantLib::HongKong *'> >

Quick way to initialize a null calendar.

class hungary(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Hungary.

holidayRule = <QuantLib.QuantLib.Hungary; proxy of <Swig Object of type 'QuantLib::Hungary *'> >

Quick way to initialize a null calendar.

class icelandICEX(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Iceland ICEX.

holidayRule = <QuantLib.QuantLib.Iceland; proxy of <Swig Object of type 'QuantLib::Iceland *'> >

Quick way to initialize a null calendar.

class indiaNSE(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of India NSE.

holidayRule = <QuantLib.QuantLib.India; proxy of <Swig Object of type 'QuantLib::India *'> >

Quick way to initialize a null calendar.

class indonesiaBEJ(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Indonesia BEJ.

holidayRule = <QuantLib.QuantLib.Indonesia; proxy of <Swig Object of type 'QuantLib::Indonesia *'> >

Quick way to initialize a null calendar.

class indonesiaJSX(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Indonesia JSX.

holidayRule = <QuantLib.QuantLib.Indonesia; proxy of <Swig Object of type 'QuantLib::Indonesia *'> >

Quick way to initialize a null calendar.

class israelSHIR(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Israel SHIR.

holidayRule = <QuantLib.QuantLib.Israel; proxy of <Swig Object of type 'QuantLib::Israel *'> >

Quick way to initialize a null calendar.

class israelSettlement(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Israel Settlement.

holidayRule = <QuantLib.QuantLib.Israel; proxy of <Swig Object of type 'QuantLib::Israel *'> >

Quick way to initialize a null calendar.

class israelTASE(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Israel TASE.

holidayRule = <QuantLib.QuantLib.Israel; proxy of <Swig Object of type 'QuantLib::Israel *'> >

Quick way to initialize a null calendar.

class italyExchange(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Italy Exchange.

holidayRule = <QuantLib.QuantLib.Italy; proxy of <Swig Object of type 'QuantLib::Italy *'> >

Quick way to initialize a null calendar.

class italySettlement(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Italy Settlement.

holidayRule = <QuantLib.QuantLib.Italy; proxy of <Swig Object of type 'QuantLib::Italy *'> >

Quick way to initialize a null calendar.

class japan(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Japan.

holidayRule = <QuantLib.QuantLib.Japan; proxy of <Swig Object of type 'QuantLib::Japan *'> >

Quick way to initialize a null calendar.

class mexicoBMV(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Mexico BMV.

holidayRule = <QuantLib.QuantLib.Mexico; proxy of <Swig Object of type 'QuantLib::Mexico *'> >

Quick way to initialize a null calendar.

class newZealandAuckland(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of NewZealand Auckland.

holidayRule = <QuantLib.QuantLib.NewZealand; proxy of <Swig Object of type 'QuantLib::NewZealand *'> >

Quick way to initialize a null calendar.

class newZealandWellington(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of NewZealand Wellington.

holidayRule = <QuantLib.QuantLib.NewZealand; proxy of <Swig Object of type 'QuantLib::NewZealand *'> >

Quick way to initialize a null calendar.

class norway(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Norway.

holidayRule = <QuantLib.QuantLib.Norway; proxy of <Swig Object of type 'QuantLib::Norway *'> >

Quick way to initialize a null calendar.

class null(otherHolidays=None)[source]

Bases: calendar

holidayRule = <QuantLib.QuantLib.NullCalendar; proxy of <Swig Object of type 'QuantLib::NullCalendar *'> >

Quick way to initialize a null calendar.

class polandSettlement(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Poland Settlement.

holidayRule = <QuantLib.QuantLib.Poland; proxy of <Swig Object of type 'QuantLib::Poland *'> >

Quick way to initialize a null calendar.

class polandWSE(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Poland WSE.

holidayRule = <QuantLib.QuantLib.Poland; proxy of <Swig Object of type 'QuantLib::Poland *'> >

Quick way to initialize a null calendar.

class romaniaBVB(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Romania BVB.

holidayRule = <QuantLib.QuantLib.Romania; proxy of <Swig Object of type 'QuantLib::Romania *'> >

Quick way to initialize a null calendar.

class romaniaPublic(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Romania Public.

holidayRule = <QuantLib.QuantLib.Romania; proxy of <Swig Object of type 'QuantLib::Romania *'> >

Quick way to initialize a null calendar.

class russiaMOEX(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Russia MOEX.

holidayRule = <QuantLib.QuantLib.Russia; proxy of <Swig Object of type 'QuantLib::Russia *'> >

Quick way to initialize a null calendar.

class russiaSettlement(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Russia Settlement.

holidayRule = <QuantLib.QuantLib.Russia; proxy of <Swig Object of type 'QuantLib::Russia *'> >

Quick way to initialize a null calendar.

class saudiArabiaTadawul(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of SaudiArabia Tadawul.

holidayRule = <QuantLib.QuantLib.SaudiArabia; proxy of <Swig Object of type 'QuantLib::SaudiArabia *'> >

Quick way to initialize a null calendar.

class singaporeSGX(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Singapore SGX.

holidayRule = <QuantLib.QuantLib.Singapore; proxy of <Swig Object of type 'QuantLib::Singapore *'> >

Quick way to initialize a null calendar.

class slovakiaBSSE(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Slovakia BSSE.

holidayRule = <QuantLib.QuantLib.Slovakia; proxy of <Swig Object of type 'QuantLib::Slovakia *'> >

Quick way to initialize a null calendar.

class southAfrica(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of SouthAfrica.

holidayRule = <QuantLib.QuantLib.SouthAfrica; proxy of <Swig Object of type 'QuantLib::SouthAfrica *'> >

Quick way to initialize a null calendar.

class southKoreaKRX(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of SouthKorea KRX.

holidayRule = <QuantLib.QuantLib.SouthKorea; proxy of <Swig Object of type 'QuantLib::SouthKorea *'> >

Quick way to initialize a null calendar.

class southKoreaSettlement(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of SouthKorea Settlement.

holidayRule = <QuantLib.QuantLib.SouthKorea; proxy of <Swig Object of type 'QuantLib::SouthKorea *'> >

Quick way to initialize a null calendar.

class sweden(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Sweden.

holidayRule = <QuantLib.QuantLib.Sweden; proxy of <Swig Object of type 'QuantLib::Sweden *'> >

Quick way to initialize a null calendar.

class switzerland(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Switzerland.

holidayRule = <QuantLib.QuantLib.Switzerland; proxy of <Swig Object of type 'QuantLib::Switzerland *'> >

Quick way to initialize a null calendar.

class taiwanTSEC(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Taiwan TSEC.

holidayRule = <QuantLib.QuantLib.Taiwan; proxy of <Swig Object of type 'QuantLib::Taiwan *'> >

Quick way to initialize a null calendar.

class thailand(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Thailand.

holidayRule = <QuantLib.QuantLib.Thailand; proxy of <Swig Object of type 'QuantLib::Thailand *'> >

Quick way to initialize a null calendar.

class turkey(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Turkey.

holidayRule = <QuantLib.QuantLib.Turkey; proxy of <Swig Object of type 'QuantLib::Turkey *'> >

Quick way to initialize a null calendar.

class ukraineUSE(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of Ukraine USE.

holidayRule = <QuantLib.QuantLib.Ukraine; proxy of <Swig Object of type 'QuantLib::Ukraine *'> >

Quick way to initialize a null calendar.

class unitedKingdomExchange(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of UnitedKingdom Exchange.

holidayRule = <QuantLib.QuantLib.UnitedKingdom; proxy of <Swig Object of type 'QuantLib::UnitedKingdom *'> >

Quick way to initialize a null calendar.

class unitedKingdomMetals(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of UnitedKingdom Metals.

holidayRule = <QuantLib.QuantLib.UnitedKingdom; proxy of <Swig Object of type 'QuantLib::UnitedKingdom *'> >

Quick way to initialize a null calendar.

class unitedKingdomSettlement(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of UnitedKingdom Settlement.

holidayRule = <QuantLib.QuantLib.UnitedKingdom; proxy of <Swig Object of type 'QuantLib::UnitedKingdom *'> >

Quick way to initialize a null calendar.

class unitedStatesFederalReserve(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of UnitedStates FederalReserve.

holidayRule = <QuantLib.QuantLib.UnitedStates; proxy of <Swig Object of type 'QuantLib::UnitedStates *'> >

Quick way to initialize a null calendar.

class unitedStatesGovernmentBond(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of UnitedStates GovernmentBond.

holidayRule = <QuantLib.QuantLib.UnitedStates; proxy of <Swig Object of type 'QuantLib::UnitedStates *'> >

Quick way to initialize a null calendar.

class unitedStatesLiborImpact(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of UnitedStates LiborImpact.

holidayRule = <QuantLib.QuantLib.UnitedStates; proxy of <Swig Object of type 'QuantLib::UnitedStates *'> >

Quick way to initialize a null calendar.

class unitedStatesNERC(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of UnitedStates NERC.

holidayRule = <QuantLib.QuantLib.UnitedStates; proxy of <Swig Object of type 'QuantLib::UnitedStates *'> >

Quick way to initialize a null calendar.

class unitedStatesNYSE(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of UnitedStates NYSE.

holidayRule = <QuantLib.QuantLib.UnitedStates; proxy of <Swig Object of type 'QuantLib::UnitedStates *'> >

Quick way to initialize a null calendar.

class unitedStatesSOFR(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of UnitedStates SOFR.

holidayRule = <QuantLib.QuantLib.UnitedStates; proxy of <Swig Object of type 'QuantLib::UnitedStates *'> >

Quick way to initialize a null calendar.

class unitedStatesSettlement(otherHolidays=None)[source]

Bases: null

Quick way to initialize calendar of UnitedStates Settlement.

holidayRule = <QuantLib.QuantLib.UnitedStates; proxy of <Swig Object of type 'QuantLib::UnitedStates *'> >

Quick way to initialize a null calendar.

RiskQuantLib.Tool.decoratorTool module

class checker(argIndexList=None, argKeyList=None, argIterableIndexList=None, argIterableKeyList=None)[source]

Bases: object

This is a decorator which will check every parameter what is passed into a function. By default, this decorator does nothing.

class confirmer(prefix='This Is An Action That Can NOT Be Cancelled, Input Y/y To Confirm Or N/n To Deny:')[source]

Bases: object

This is a decorator which will require confirmation before calling the wrapped function. If this decorator is passed a notice, it will print it before require confirmation.

class freezer(*args, **kwargs)[source]

Bases: object

This is a decorator which will freeze all parameters except the first one.

If you have a function typed as func(x, y, z, m), you can convert it into a single-parameter function by passing y, z, m into it before x is determined. You can do this by @freezer(y=1, z=2, m=3), then just call func(43), it will be totally the same as func(x=43, y=1, z=2, m=3)

class stringTimestampConverter(argIndexList=None, argKeyList=None, argIterableIndexList=None, argIterableKeyList=None)[source]

Bases: checker

This is a decorator which will try to convert string into pandas.Timestamp. It is used when a function require a pandas.Timestamp parameter, after decorated by this, it allows to pass a string into parameter.

If a function is typed as func(x: pandas.Timestamp, y: pandas.Timestamp, z: List[pandas.Timestamp], m: List[pandas.Timestamp]), then you can decorate it by @stringTimestampConverter(argIndexList=[0,1], argKeyList=[‘x’,’y’], argIterableIndexList=[2,3], argIterableKeyList=[‘z’,’m’])

static convertStrListToTimestampList(arg=None)[source]
static convertStrToTimestamp(arg=None)[source]
class timer(prefix='None')[source]

Bases: object

This is a decorator which will count the time of a single function call. If this decorator is passed a prefix, it will print it along with running time of decorated function.

class valueAsserter(argIndexList=None, argKeyList=None, argIterableIndexList=None, argIterableKeyList=None, value=None)[source]

Bases: checker

This is a decorator which will assert that some parameter must have certain values. If passed with other values, exception will be raised. If a parameter is an iterable, then check every element.

If you want to require the value of the second parameter of a function into 1 or 2, all other values should be invalid, then decorate it by @valueAsserter(argIndexList=[1],value={1,2}).

static assertValue(arg=None, value=None, argName=None, funcName=None)[source]
static assertValueList(arg=None, value=None, argName=None, funcName=None)[source]

RiskQuantLib.Tool.excelTool module

formatExcelWithTemplate(templateExcelPathString, dataExcelPathString, savePathString)[source]

This function will use the format of templateExcel and the data of dataExcel to generate a new excel.

Parameters

templateExcelPathStringstr

The xlsx file that specify the format of output.

dataExcelPathStringstr

The xlsx file that specify the content of output.

savePathStringstr

The path where the output should be saved.

Returns

None

RiskQuantLib.Tool.fileTool module

clearCachePklFile(filePath)[source]

Delete all ‘.pkl’ files in filePath.

deleteFile(filePath)[source]

Delete a file if it exists.

deleteFileWithConfirm(filePath)[source]

Before Delete a file, ask for confirmation.

dumpDictToJson(dictVariable, filePath)[source]

Dump dict to json file.

dumpVariable(variable, filePath)[source]

Use python module pickle to dump variable.

class fileReceiver(targetFilePath)[source]

Bases: object

receiveFile()[source]
receiveFileContent(address, fileName, fileSize)[source]
receiveFileInfo()[source]
run(timeOut=100)[source]
sendIPInfo()[source]
sendOnLineInfo()[source]
class fileSender(fileName)[source]

Bases: object

receiveIPInfo()[source]
run(timeOut=100)[source]
sendFile()[source]
sendFileContent(address)[source]
sendFileInfo()[source]
sendOnLineInfo()[source]
loadCsv(filePath, index_col=0)[source]

Use pandas.read_csv to load csv file, default set the first column as index.

loadCsvDict(dirPath, index_col=0)[source]

Read all csv file in the target directory, return a dict whose keys are file names and values are pandas.DataFrames.

loadCsvTimeSeries(filePath, index_col=0, converters=None)[source]

Use pandas.read_csv to load csv file, default set the first column as index, and set its datatype as pandas.Timestamp.

loadCsvTimeSeriesDict(dirPath, index_col=0, converters=None)[source]

Read all csv file in the target directory, return a dict whose keys are file names and values are pandas.DataFrames. Default set the first column of each file as index, and set its datatype as pandas.Timestamp.

loadExcel(filePath)[source]

Use pandas.read_excel to load csv file.

loadExcelDict(dirPath)[source]

Read all excel file in the target directory, return a dict whose keys are file names and values are pandas.DataFrames.

loadVariable(filePath)[source]

Use python module pickle to load variable.

modifyDateIsToday(filePath, mode='M')[source]

This function will return a bool value, showing whether the target file is modified on today.

class systemGuardian(path, call_back_function=<function systemGuardian.<lambda>>)[source]

Bases: object

start()[source]
tryWatch()[source]
watch()[source]
class systemWatcher(monitorPath, call_back_function_on_file=<function systemWatcher.<lambda>>, call_back_function_on_dir=<function systemWatcher.<lambda>>, call_back_function_on_any_change=<function systemWatcher.<lambda>>, withFormat=False, monitorFormat={})[source]

Bases: object

createGuardian()[source]
scanMonitorPath(monitorPath)[source]
start()[source]
watch()[source]
waitForFile(filePath, fileNameKeyWord)[source]

This function will wait for the change or modification of a file.

RiskQuantLib.Tool.frameTool module

findFirstNotNanValueOfSeries(sr)[source]

Return the first not nan value of a pandas.Series object.

resetIndexByFirstNotNanValue(df, dropFirst=False, inplace=True)[source]

Reset index by the first not nan value.

RiskQuantLib.Tool.githubTool module

class Github[source]

Bases: object

This class is used to do operations of Github with github api.

For basic use of search, establish url.

downloadRepositories(repositoryIndex, targetPath)[source]

This function will download the repository specified by repositoryIndex. The downloaded file is in zip form and will be saved to targetPath.

Parameters

repositoryIndexint or str

The number of repository index. Or a string to specify the link of github web page. Or the name of a repository. Or any key word that can be used to search github.

targetPathstr

The path where zip file will be saved.

Returns

None

searchRepositories(repositoryKeyWord='', output=True)[source]

This function will send request to search Github and find all repositories that can be related to given key words. All repositories are sorted by star numbers. The first one is the most starred one.

Parameters

repositoryKeyWordstr

The key words used to search Github.

outputbool

Whether to print all repositories names.

Returns

None

downloadRepo(url, targetPath, name='')[source]

This function will use Github api to download zip file of repositories.

Parameters

urlstr

The total github api link of some repository

targetPathstr

The file path where you want to save the zip clone

namestr

The repository name you want to download

Returns

None

RiskQuantLib.Tool.mailTool module

class mailConnector(hostIMAP, hostSMTP, userName, password, portSMTP=25)[source]

Bases: object

This is the basic connector of mail service.

receive(number=5, folder='INBOX', message='ALL')[source]

This function is used to search mailbox and get the latest n mails, it returns html string.

send(to, subject, content, html=False)[source]

This function will send mails to a list of users. You can pass html string or pure string to it.

RiskQuantLib.Tool.mathTool module

interP1d(xList, yList, kind='linear')[source]

This function returns a cubic interpolate of two lists. It returns a model object, use model(newValue) to predict new value.

Parameters

xListlist

The X list

yListlist

The Y list

kindstr

The type of interpolation, can be ‘linear’, ‘cubic’, ‘nearest’

Returns

modelobject

The scipy model, use model(newValue) to get predicted values.

isnan(x)[source]

This function returns a bool value of given data.

Parameters

xAny

This is the data you want to tell whether it is a nan.

Returns

bool

linearRegression(xList, yList)[source]

This function returns a linear regression of two lists.

Parameters

xListlist

The X list

yListlist

The Y list

Returns

modeltuple

The tuple of (coef, intercept)

linearRegressions(xArray, yArray)[source]

This function returns a linear regression of multi-dimension array.

Parameters

xArraynp.ndarray

The X array, which has the shape of (n * k), n is the number of samples, k is the number of features

yArraynp.ndarray

The Y array, which has the shape of (n * 2), n is the number of samples

Returns

modeltuple

The tuple of (coefList, intercept)

maxDrawdown(dataList, relative=True)[source]

This function returns a max drawdown of given list.

Parameters

dataListlist

The data list

relativestr

The drawdown type. If true, the max drawdown will be a percentage relative to highest point, otherwise it will be a distance.

Returns

modelnp.float64

The max drawdown of given data.

percentage(dataList, pct)[source]

This function returns the percentage of a list.

Parameters

dataListlist

The list holding data

pctfloat

The percentage number. 99 means 99% percentage.

Returns

None

RiskQuantLib.Tool.plotTool module

plot3DScatter(array, xLabelStr, yLabelStr, zLabelStr, titleStr, savePathStr, show=False)[source]

Plot a 3D scatter chart.

Parameters

arraynp.ndarray

An array with 3 columns, like [[x1, y1, z1],[x2,y2,z2]].

xLabelStrstr

The name of x axis.

yLabelStrstr

The name of y axis.

zLabelStrstr

The name of z axis.

titleStrstr

The chart title.

savePathStrstr

The path where you want to save the chart

showbool

Show it in browser. If false, it will only save file into disk.

Returns

None

plot3DSurface(x, y, z, xLabelStr, yLabelStr, zLabelStr, titleStr, savePathStr, show=False)[source]

Plot a 3D surface chart.

Parameters

xnp.ndarray

One-dimension array, whose length equals the column number of z.

ynp.ndarray

One-dimension array, whose length equals the row number of z.

znp.ndarray

Two-dimensions array, which contains the value of surface.

xLabelStrstr

The name of x axis.

yLabelStrstr

The name of y axis.

zLabelStrstr

The name of z axis.

titleStrstr

The chart title.

savePathStrstr

The path where you want to save the chart

showbool

Show it in browser. If false, it will only save file into disk.

Returns

None

plotBar(df, titleStr, xLabelStr, yLabelStr, savePathStr, show=False)[source]

Plot a bar chart.

Parameters

dfpd.DataFrame

The dataframe you want to plot. Each column is a series. Values must be number.

titleStrstr

The chart title.

xLabelStrstr

The x label

yLabelStrstr

The y label

savePathStrstr

The path where you want to save the chart

showbool

Show it in browser. If false, it will only save file into disk.

Returns

None

plotLine(df, titleStr, xLabelStr, yLabelStr, savePathStr, show=False)[source]

Plot a multiple line graph.

Parameters

dfpd.DataFrame

The dataframe you want to plot. Each column is a series. Values must be number.

titleStrstr

The graph title.

xLabelStrstr

The x label

yLabelStrstr

The y label

savePathStrstr

The path where you want to save the graph

showbool

Show it in browser. If false, it will only save file into disk.

Returns

None

plotPie(sr, titleStr, savePathStr, show=False)[source]

Plot a pie chart.

Parameters

dfpd.DataFrame

The dataframe you want to plot. Each column is a series. Values must be number.

titleStrstr

The chart title.

savePathStrstr

The path where you want to save the chart

showbool

Show it in browser. If false, it will only save file into disk.

Returns

None

RiskQuantLib.Tool.pptTool module

formatPPTX(filePath, targetPath, tableDict=None, textDict=None, graphDict=None, slideIndex=None)[source]

This function will use the content of tableDict and textDict and graphDict to change given PPT. It will iterate across every slide and modify it. The first table in the slide will be changed into tableDict[0] and the second table in the slide will be changed into tableDict[1], etc… The first picture in the slide will be changed into graphDict[0] and the second table in the slide will be changed into graphDict[1], etc… Any symbols like {symbolName} will be changed into given string specified by textDict.

After change is done, this PPT will be saved into target file. You can also specify the slideIndex so that only the specified slide will be changed.

Parameters

filePathstr

The path of PPT file which you want to change.

targetPathstr

The path where you want to change the modified file.

tableDict :dict

The key->value pairs that declare what the table should be replaced to. The key of this dict should be int number and start from 0, like 0, 1, 2… and the value of this dict should be pandas.DataFrame object.

textDictdict

The key->value pairs that declare what the symbols should be replaced to. The key of this dict should be string type and like ‘{symbolName}’, and the value of this dict should be string type.

graphDict :dict

The key->value pairs that declare what the graph should be replaced to. The key of this dict should be int number and start from 0, like 0, 1, 2… and the value of this dict should be path string of pictures.

slideIndexint

The int number i which specify the i-th slide should be changed. If you specify this parameter, then all the rest will not be changed.

Returns

None

formatSlide(slide, tableDict=None, textDict=None, graphDict=None)[source]

This function will use the content of tableDict and textDict and graphDict to change given slide. The first table in the slide will be changed into tableDict[0] and the second table in the slide will be changed into tableDict[1], etc… The first picture in the slide will be changed into graphDict[0] and the second table in the slide will be changed into graphDict[1], etc… Any symbols like {symbolName} will be changed into given string specified by textDict.

Parameters

slidepptx.slide.Slide

The slide which you want to change.

tableDictdict

The key->value pairs that declare what the table should be replaced to. The key of this dict should be int number and start from 0, like 0, 1, 2… and the value of this dict should be pandas.DataFrame object.

textDictdict

The key->value pairs that declare what the symbols should be replaced to. The key of this dict should be string type and like ‘{symbolName}’, and the value of this dict should be string type.

graphDictdict

The key->value pairs that declare what the graph should be replaced to. The key of this dict should be int number and start from 0, like 0, 1, 2… and the value of this dict should be path string of pictures.

Returns

None

formatTableWithTemplate(shape, paraDict)[source]

This function will use the content of paraDict to fill the mark in shape object. If it find any mark like {symbolName}, it will replace it into the value declared by paraDict.

Parameters

shapepptx.shapes.placeholder.PlaceholderGraphicFrame

The shape object that you want to change, usually this shape is a table.

paraDictdict

The key->value pairs that declare what the symbols should be replaced to. The key of this dict should be string type and like ‘{symbolName}’, and the value of this dict should be string type.

Returns

None

formatTextFrameWithTemplate(shape, paraDict)[source]

This function will use the content of paraDict to fill the mark in shape object. If it find any mark like {symbolName}, it will replace it into the value declared by paraDict.

Parameters

shapepptx.shapes.placeholder.PlaceholderGraphicFrame

The shape object that you want to change, usually this shape is a text frame.

paraDictdict

The key->value pairs that declare what the symbols should be replaced to. The key of this dict should be string type and like ‘{symbolName}’, and the value of this dict should be string type.

Returns

None

replaceChart(slide, shape, picturePath)[source]

This function will replace the chart in given slide into the given picture. This change is in place.

Parameters

slidepptx.slide.Slide

The slide where the shape object lies.

shapepptx.shapes.placeholder.PlaceholderGraphicFrame

The shape object that you want to change, usually this shape is a chart.

picturePathstr

The path of picture that you want to use to replace the original chart.

Returns

None

replacePicture(slide, shape, picturePath)[source]

This function will replace the old picture in given slide into the given picture. This change is in place. And the new picture has the same shape with the original one.

Parameters

slidepptx.slide.Slide

The slide where the shape object lies.

shapepptx.shapes.placeholder.PlaceholderGraphicFrame

The shape object that you want to change, usually this shape is a picture.

picturePathstr

The path of new picture that you want to use to replace the original picture.

Returns

None

replaceTableContent(shape, dfInput)[source]

This function will replace the content of table into given dataframe. If two tables have different shapes, then only the common part will be changed, other cells in original table will remain unchanged. The change is in place, but the shape of original table won’t be changed after this function is called.

Parameters

shapepptx.shapes.placeholder.PlaceholderGraphicFrame

The shape object that you want to change, usually this shape is a table.

dfInputpd.DataFrame

The dataframe that the original table should be changed to.

Returns

None

RiskQuantLib.Tool.stringTool module

getDigitsFromStr(string, withDigitPoint=False)[source]

Extract number from a string. Return a list whose element is strings that is number.

Parameters

stringstr

The string that may contain numbers.

withDigitPointbool

Use true is the numbers are float. False if all numbers are int.

Returns

strListlist

A list whose elements are string that can be converted into numbers.

getMostSimilarStringFromList(string, stringList)[source]

This function will return the most similar string of a given string, after specifying the list where you choose string from.

getNumbersFromStr(string, withDigitPoint=False)[source]

Extract number from a string. Return a list whose element is number.

Parameters

stringstr

The string that may contain numbers.

withDigitPointbool

Use true is the numbers are float. False if all numbers are int.

Returns

strListlist

A list whose elements are numbers.

getStringSimilarity(string1, string2)[source]

This function will return a similarity of two strings.

RiskQuantLib.Tool.threadTool module

multiThread(functionList, argsList=None, kwargsList=None, workerNumber=None)[source]

Run callables by multi-thread. It will pass the first element of argList as parameter of the first function, pass the second element of argList as parameter of the second function, etc. It returns a list of results.

Return type:

List[Any]

Parameters

functionListList[Callable]

A list of callables.

argsListList[Tuple]

A list of parameters, like [(arg1, arg2), (arg3,)]

kwargsListList[Dict]

A list of parameters, like [{argName1:argValue1, argName2:argValue2}, {argName3:argValue3}]

workerNumberOptional[int]

Max number of core used.

Returns

List[Any]

The results of every function.

RiskQuantLib.Tool.wordTool module

formatTableWithTemplate(originFilePath, targetFilePath, tableIndex, dfInput)[source]

This function will change the table in docx file into the given dataframe. This change is inplace. A new file will be generated and replace the original docx file.

You should make sure the shape of table in your docx file is equal or larger than your dfInput, including index and column, which means your table in docx should have shape of (n+1, k+1) while your dfInput has shape (n, k).

Parameters

originFilePathstr

The docx file path that you want to change one of its table into the given dataframe.

targetFilePathstr

The docx file path where you want to save the changed file.

tableIndexint

The table index that showed which table you want to change.

dfInputpd.DataFrame

The dataframe that the original table should be changed to.

Returns

None

formatWordWithTemplate(originFilePath, targetFilePath, paraDict)[source]

This function will iterate across the whole docx file and check for each paragraph and table, if it finds any symbol like {symbolName}, it will replace it into the value declared by paraDict.

Parameters

originFilePathstr

The docx template file whose content you want to check and replace.

targetFilePathstr

The path you want to save the after-replacement docx file.

paraDictdict

The key->value pairs that declare what the symbols should be replaced to. The key of this dict should be string type and like ‘{symbolName}’, and the value of this dict should be string type.

Returns

None

replaceParagraphContent(paragraph, paraDict)[source]

This function will replace the paragraph content of word Document object. This replace is inplace, so this function returns None. This function is very like the str.format() function in python, it replaces any symbol like {symbolName} according to key->value relation in paraDict, if there is a {code} showed in word, and paraDict declares ‘{code}’:’000001’, then the content of {code} will be replaced to 000001.

Parameters

paragraphObject

The python-docx paragraph object.

paraDictdict

A python dict used to declare which symbol should be replaced and how should it be replaced.

Returns

None

Module contents