RiskQuantLib.Tool package¶
Submodules¶
RiskQuantLib.Tool.codeTool module¶
- class codeBuilder(indent=0, globalIndentStep=0)[源代码]¶
基类:
objectThis class is the basic class used to generate source code of any language.
- class codeBuilderPython(indent=0, globalIndentStep=0)[源代码]¶
基类:
codeBuilder
- class pythonScriptBuilder[源代码]¶
基类:
objectThis class is the python source code builder, used to generate python source code automatically.
- setImport(libraryName, libraryAbbr='', importSubModule=False, subModuleName='')[源代码]¶
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
- startClass(className, parentClassName='')[源代码]¶
Start a new class. This function must be followed by endClass()
RiskQuantLib.Tool.databaseTool module¶
- class mysqlConnector(databaseName, hostAddress, port, userName, passWord, charset='utf8mb4')[源代码]¶
基类:
sqlConnectorThis is the API to connect with mysql database using PyMySQL.
- class neo4jConnector(hostAddress, port, userName, password)[源代码]¶
基类:
objectThis is the API to connect with neo4j database.
- class oracleConnector(databaseName, hostAddress, port, userName, passWord)[源代码]¶
基类:
sqlConnectorThis 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)[源代码]¶
基类:
object- getAllTables(*args, **kwargs)[源代码]¶
Get names of all tables. You may need to specify schema=some if you are connecting to oracle or sqlserver.
- class sqlServerConnector(databaseName, hostAddress, port, userName, passWord, charset='cp936')[源代码]¶
基类:
sqlConnectorThis is the API to connect with sql server database.
RiskQuantLib.Tool.dateTool module¶
- class argentinaMerval(otherHolidays=None)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
object- addHolidayRule(holidayRule)[源代码]¶
Add customized holiday rule, this will overwrite current holiday settings.
- 返回类型:
- makeSchedule(start, end, period, forwardAdjust=True, forwardScale=True, forwardAdjustEndDay=False)[源代码]¶
Generate periodical trading dates between start and end, given period.
- makeScheduleByPeriod(start, period, count, forwardAdjust=True)[源代码]¶
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.
- 返回类型:
List[Timestamp]
- numTradingDaysBetween(start, end, countStart=True, countEnd=True)[源代码]¶
Return number of trading days between two dates.
- 返回类型:
- numTradingDaysBetweenGrid(start, dateList, countStart=True, countEnd=True)[源代码]¶
Return number of trading days between a date and a date list.
- offset(date, n, period=0)[源代码]¶
Return date of trading day n days before or after date.
- 返回类型:
Timestamp
- tradingDaysBetween(start, end, startPoint=True, endPoint=True)[源代码]¶
Return a list of trading days between start and end. Endpoints are counted only if they are trading.
- 返回类型:
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]¶
- class canadaSettlement(otherHolidays=None)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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')[源代码]¶
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)[源代码]¶
This function will return a list, whose elements are the next n weekdays.
- class germanyEurex(otherHolidays=None)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
calendar- holidayRule = <QuantLib.QuantLib.NullCalendar; proxy of <Swig Object of type 'QuantLib::NullCalendar *'> >¶
Quick way to initialize a null calendar.
- class polandSettlement(otherHolidays=None)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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)[源代码]¶
基类:
nullQuick 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.
RiskQuantLib.Tool.decoratorTool module¶
- class checker(argIndexList=None, argKeyList=None, argIterableIndexList=None, argIterableKeyList=None)[源代码]¶
基类:
objectThis 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:')[源代码]¶
基类:
objectThis 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)[源代码]¶
基类:
objectThis 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)[源代码]¶
基类:
checkerThis 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’])
- class timer(prefix='None')[源代码]¶
基类:
objectThis 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)[源代码]¶
基类:
checkerThis 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}).
RiskQuantLib.Tool.excelTool module¶
- formatExcelWithTemplate(templateExcelPathString, dataExcelPathString, savePathString)[源代码]¶
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¶
- loadCsv(filePath, index_col=0)[源代码]¶
Use pandas.read_csv to load csv file, default set the first column as index.
- loadCsvDict(dirPath, index_col=0)[源代码]¶
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)[源代码]¶
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)[源代码]¶
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.
- loadExcelDict(dirPath)[源代码]¶
Read all excel file in the target directory, return a dict whose keys are file names and values are pandas.DataFrames.
- modifyDateIsToday(filePath, mode='M')[源代码]¶
This function will return a bool value, showing whether the target file is modified on today.
RiskQuantLib.Tool.frameTool module¶
RiskQuantLib.Tool.githubTool module¶
- class Github[源代码]¶
基类:
objectThis class is used to do operations of Github with github api.
For basic use of search, establish url.
- downloadRepositories(repositoryIndex, targetPath)[源代码]¶
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)[源代码]¶
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='')[源代码]¶
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.guiTool module¶
RiskQuantLib.Tool.mailTool module¶
RiskQuantLib.Tool.mathTool module¶
- interP1d(xList, yList, kind='linear')[源代码]¶
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)[源代码]¶
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)[源代码]¶
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)[源代码]¶
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)[源代码]¶
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.
RiskQuantLib.Tool.plotTool module¶
- plot3DScatter(array, xLabelStr, yLabelStr, zLabelStr, titleStr, savePathStr, show=False)[源代码]¶
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)[源代码]¶
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)[源代码]¶
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)[源代码]¶
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)[源代码]¶
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)[源代码]¶
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)[源代码]¶
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)[源代码]¶
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)[源代码]¶
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)[源代码]¶
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)[源代码]¶
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)[源代码]¶
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)[源代码]¶
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)[源代码]¶
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)[源代码]¶
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.
RiskQuantLib.Tool.threadTool module¶
- multiThread(functionList, argsList=None, kwargsList=None, workerNumber=None)[源代码]¶
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.
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)[源代码]¶
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)[源代码]¶
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)[源代码]¶
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