RiskQuantLib package

Subpackages

Submodules

RiskQuantLib.module module

Module contents

addModule(moduleCategory='', targetPath='', targetName='')[source]

addModule() is a function to add a RiskQuantLib module ‘.zip’ file to library.

Use terminal command ‘addRQL’ to use this function.

The terminal command ‘addRQL’ accept two parameters: ‘moduleCategory’ and ‘targetPathString’. ‘moduleCategory’ is the sub-category of your library, by default, it can be template, model or tool. ‘targetPathString’ is the RiskQuantLib module ‘.zip’ file path that you want to add to library. It has to be a ‘.zip’ file to be added to library.

Parameters

moduleCategorystr

A terminal command parameter, specify the library sub-category you want to add ‘.zip’ file into.

targetPathstr

A terminal command parameter, specify the RiskQuantLib module ‘.zip’ file path which you want to add to library.

targetNamestr

The name you want to use to save the .zip file as, it is not necessary to add .zip behind it.

Returns

None

addModuleFromGithub(targetGithub='')[source]

addModuleFromGithub() is a function to download template from Github to local disk. Use terminal command ‘getRQL’ to use this function. After this function is called, the target repository will be saved as template project.

Parameters

targetGithubstr

A terminal command parameter, specify the project name you want to download from Github.

Returns

None

autoBuildProject(targetPath='', renderFromPath='', channel='', debug=False, force=False)[source]

autoBuildProject() is a function to build RiskQuantLib project. This function keeps running until catch a KeyboardInterrupt Exception.

Use terminal command ‘autoRQL targetProjectPath’ to use this function. The project will be built according to the targetProjectPath/config.py in the targetProjectPath.

After this function is called, the instrument class file and attribute API will be automatically generated and updated.

Parameters

targetPathstr

A terminal command parameter, specify the RiskQuantLib project path you want to build and render.

renderFromPathstr

The path of directory of source file used to render target project.

channelstr

render action in this channel will not delete the result of render in other channel unless it is overwritten by current render.

debugbool

If false, the break point in Src will not be effective, only break point within instrument class will effect. If true, the class method defined in Src directory will be dynamically bound to instrument node class. Then the program will take .py file under .Src directory as a module and import it, bind the class method into specified class. This mode is useful when your code is still under development. You will not have to change between ./Src/somecode.py and target instrument class .py file to edit any code error. The break point will stop right under ./Src/somecode.py.

forcebool

If True, the cached building file buildInfo.pkl will be deleted, a new builder object will be created. This is useful when there are some mistakes in buildInfo.pkl, or error happens when caching buildInfo.pkl. In these cases, old buildInfo.pkl exists but can not be used. If this parameter is specified as True, buildInfo.pkl will be deleted before auto-building. However, any information in old building will be deleted. If you use guardian projects, there could be problems, you will have to build all guardian projects again. Another thing to notice is the action of parameter force in autoBuildProject is different with that in buildProject or persistProject. buildInfo.pkl will be neglected in buildProject and persistProject, but will be deleted for a single time before auto-building.

Returns

None

buildProject(targetPath='', renderFromPath='', channel='', debug=False, force=False)[source]

buildProject() is a function to build RiskQuantLib project.

Use terminal command ‘bldRQL targetProjectPath’ to use this function. The project will be built according to the targetProjectPath/config.py in the targetProjectPath.

After this function is called, the instrument class file and attribute API will be automatically generated.

For old version user of RiskQuantLib, this function is totally the same as command ‘python build.py’ in terminal with working directory as targetProjectPath.

Parameters

targetPathstr

A terminal command parameter, specify the RiskQuantLib project path you want to build and render.

renderFromPathstr

The path of directory of source file used to render target project.

channelstr

render action in this channel will not delete the result of render in other channel unless it is overwritten by current render.

debugbool

If false, the break point in Src will not be effective, only break point within instrument class will effect. If true, the class method defined in Src directory will be dynamically bound to instrument node class. Then the program will take .py file under .Src directory as a module and import it, bind the class method into specified class. This mode is useful when your code is still under development. You will not have to change between ./Src/somecode.py and target instrument class .py file to edit any code error. The break point will stop right under ./Src/somecode.py.

forcebool

If True, the cached building file buildInfo.pkl will be neglected, a new builder object will be created. This is useful when there are some mistakes in buildInfo.pkl, or error happens when caching buildInfo.pkl. In these cases, old buildInfo.pkl exists but can not be used. The traditional way to solve this problem is manually deleting this file and build whole project again. With this parameter specified as True, users can choose to build project no matter buildInfo.pkl exists or not. However, any information in old building will be deleted. If you use guardian projects, there could be problems, you will have to build all guardian projects again.

Returns

None

buildProjectFromConfig(targetPath, buildCachePath, configFilePath, renderFromPath, bindType='renderedSourceCode', debug=False, force=False)[source]

buildProjectFromConfig() is a function to build project according to config.py declaration.

Parameters

targetPathstr

The path of target RiskQuantLib project directory.

buildCachePathstr

The path of building cache.

configFilePathstr

The path of config.py used as default build config file.

renderFromPathstr

The path of source code directory

bindTypestr

The channel of binding action. Source code are rendered and injected into project by different channels, The source code injected by channel A will be not influenced by source code injected by channel B, unless the content of tag is overwritten by code in channel B. This is used when you have several builders and you want them to build into the same project. In this case, you should give a bindType for each render action to make sure they do not conflict with each other.

debugbool

If false, the break point in Src will not be effective, only break point within instrument class will effect. If true, the class method defined in Src directory will be dynamically bound to instrument node class. Then the program will take .py file under .Src directory as a module and import it, bind the class method into specified class. This mode is useful when your code is still under development. You will not have to change between ./Src/somecode.py and target instrument class .py file to edit any code error. The break point will stop right under ./Src/somecode.py.

forcebool

If True, the cached building file buildInfo.pkl will be neglected, a new builder object will be created. This is useful when there are some mistakes in buildInfo.pkl, or error happens when caching buildInfo.pkl. In these cases, old buildInfo.pkl exists but can not be used. The traditional way to solve this problem is manually deleting this file and build whole project again. With this parameter specified as True, users can choose to build project no matter buildInfo.pkl exists or not. However, any information in old building will be deleted. If you use guardian projects, there could be problems, you will have to build all guardian projects again.

Returns

None

checkAndCreateLibraryPath(moduleName=('Template', 'Model', 'Tool'))[source]

checkAndCreateLibraryPath() is a function to check whether the Template path exists.

Parameters

moduleNametuple

The parameter tells how many sub-categories the library has. By default, it has Template, Model and Tool.

Returns

sourcePathstr

The path of RiskQuantLib template directory.

checkModuleCategory(moduleCategory='')[source]

This function will check the parameter value of moduleCategory is validated or not.

clearAllModule()[source]

clearAllModule() is a function to delete all RiskQuantLib modules from library.

Use terminal command ‘clearRQL’ to use this function. After calling this function, all existing RiskQuantLib modules will be removed.

Returns

None

copyProject(fromProjectPath='', toProjectPath='')[source]

copyProject() is a function to copy RiskQuantLib project to another directory.

Use terminal command ‘copyRQL fromProjectPath toProjectPath’ to use this function. The project will be copied into the specified directory, if toProjectPath does not exist, it will be created.

This function will copy every file in current project into new directory except those files which are under path fromProjectPath/RiskQuantLib. If files with the same name already exist in toProjectPath, then they will be overwritten, so use it carefully.

Parameters

fromProjectPathstr

A terminal command parameter, specify the RiskQuantLib project path you want to copy from.

toProjectPathstr

The path where you want to copy RiskQuantLib project to.

Returns

None

deleteModule(moduleCategory='', targetName='')[source]

deleteModule() is a function to delete a RiskQuantLib module from library.

Use terminal command ‘delRQL’ to use this function. The terminal command ‘delRQL’ accept two parameters: ‘moduleCategory’ and ‘targetName’. ‘moduleCategory’ is the sub-category of your library where you want to delete module from, by default, it can be template, model or tool. ‘targetName’ is the module name you want to delete. After calling this function, the existing RiskQuantLib module will be removed from library.

Parameters

moduleCategorystr

A terminal command parameter, specify the library sub-category you want to delete module from.

targetNamestr

A terminal command parameter, specify the module name you want to delete from library.

Returns

None

initDefaultModule()[source]

This function is used to initialize default module when installing or upgrading RiskQuantLib.

initiateBuildFile()[source]

initiateBuildFile() is a function to generate content of build.py source file.

build.py will be created in every RiskQuantLib project when initiating it. It is the entrance of build and render action. Users can either call ‘python build.py’ directly or add some parameter from command line.

Returns

PYB : pythonScriptBuilder

initiateConfigFile()[source]

initiateConfigFile() is a function to generate content of config.py source file.

config.py will be created in every RiskQuantLib project when initiating it. It is the declaration file of all instruments to be used in project and their inheritance relationship, it also contains the attribute the would be used in this project.

Returns

PYB : pythonScriptBuilder

initiateExecutableBuildShortcutFile()[source]

initiateExecutableBuildShortcutFile() is a function to generate executable shortcut for different system.

build.bat or build.sh will be created in every RiskQuantLib project when initiating it on Windows or linux. It is the shortcut of run build.py by console.

Returns

PYB : pythonScriptBuilder

initiateExecutableDebugShortcutFile()[source]

initiateExecutableDebugShortcutFile() is a function to generate executable shortcut for different system.

debug.bat or debug.sh will be created in every RiskQuantLib project when initiating it on Windows or linux. It is the shortcut of run build.py by console.

Returns

PYB : pythonScriptBuilder

initiateMainFile()[source]

initiateMainFile() is a function to generate content of main.py source file.

main.py will be created in every RiskQuantLib project when initiating it. It is the entrance of all project. Users should call ‘python main.py’ to run the project.

Returns

PYB : pythonScriptBuilder

listItem(hints, itemList)[source]
listModule(moduleCategory='')[source]

listModule() is a function to show all RiskQuantLib modules from library.

Use terminal command ‘listRQL’ to use this function.

Parameters

moduleCategorystr

A terminal command parameter, specify the library sub-category you want to show.

Returns

None

newProject(targetPath='')[source]

newProject() is a function to create a new RiskQuantLib project.

Use terminal command ‘newRQL’ to use this function. The terminal command ‘newRQL’ accept a parameter ‘targetPathString’, which is the path that you want to build RiskQuantLib project. If there is already a RiskQuantLib project in target path, it will be deleted and replaced by a new project.

Parameters

targetPathstr

A terminal command parameter, specify the path where you want to build a new project.

Returns

None

packModule(targetPath='', targetName='', keepTop=False)[source]

packModule() is a function to pack a RiskQuantLib project into ‘.zip’ file.

Use terminal command ‘pkgRQL’ to use this function. The terminal command ‘pkgRQL’ accept a parameter ‘targetPathString’, which is the path that you want to package. It doesn’t need to have a directory named ‘RiskQuantLib’ to be packaged.

Parameters

targetPathstr

A terminal command parameter, specify the path which you want to package.

targetNamestr

A terminal command parameter, specify the name you want to mark the zip file with.

keepTopbool

A terminal command parameter, specify if this function will keep the top level directory.

Returns

None

parseBuildPath(targetPath, checkExist=False)[source]

parseBuildPath() is a function to generate the paths of project related file.

Parameters

targetPathstr

The path of target RiskQuantLib project directory.

checkExistbool

If true, this function will check the existence of related path of target project. It will raise exception iin case of absence.

Returns

rqlPathstr

the path of RiskQuantLib directory

configFilePathstr

The path of config.py used as default build config file.

buildCachePathstr

the path of building cache

persistProject(targetPath='', renderFromPath='', channel='', force=False)[source]

persistProject() is a function to persist RiskQuantLib project.

Use terminal command ‘pstRQL targetProjectPath’ to use this function. The project will be changed into a permanent project, where all current attribute APIs and instrument registrations will not be influenced by build.py anymore.

This function is like a snapshot of your project, it freezes all effective APIs into permanent ones.

Surely, you can still build the persisted project with new config.py file. Just remember, no matter how many times you build it, the persisted API will remain effective and will not be influenced.

This command is used when you want to distribute your project to someone else, but you do not want him to change your current API. Or this command is used when you are quite sure your current code is stable and can be settled down so that you can move on to next stage.

This command can not be cancelled or un-done, use it carefully.

Parameters

targetPathstr

A terminal command parameter, specify the RiskQuantLib project path you want to persist.

renderFromPathstr

The path of directory of source file used to render target project.

channelstr

render action in this channel will not delete the result of render in other channel unless it is overwritten by current render.

forcebool

If True, the cached building file buildInfo.pkl will be neglected, a new builder object will be created. This is useful when there are some mistakes in buildInfo.pkl, or error happens when caching buildInfo.pkl. In these cases, old buildInfo.pkl exists but can not be used. The traditional way to solve this problem is manually deleting this file and build whole project again. With this parameter specified as True, users can choose to build project no matter buildInfo.pkl exists or not. However, any information in old building will be deleted. If you use guardian projects, there could be problems, you will have to build all guardian projects again.

Returns

None

receiveModule(targetPath='')[source]

receiveModule() is a function to receive any file or directory from your friend by LOCAL AREA NETWORK (LAN).

Use terminal command ‘recvRQL’ to use this function. You can also specify a path where your want to save the shared file or directory, like ‘recvRQL targetPath’. If you do not give a path, the file will be stored in current working directory.

After this function is called, you can receive the file shared from your friend, who is also in the same LAN. You can not receive files or project from people outside your local network by this function. If you want to share with friends who is across ocean, maybe you should use Github and getRQL command.

Parameters

targetPathstr

A terminal command parameter, specify the path where you want to hold the received file.

Returns

None

removeDefaultModule(moduleCategory='', moduleName='')[source]

setDefaultModule() is a function to remove a module from default initialization.

Use terminal command ‘udftRQL’ to use this function. The terminal command ‘udftRQL’ accept two parameters: ‘moduleCategory’ and ‘moduleName’. ‘moduleCategory’ is the sub-category of your library where you want to remove module from, by default, it can be model or tool. ‘moduleName’ is the module name you want to set as default one. After calling this function, the RiskQuantLib module will be removed from default, which means every new RiskQuantLib project created by ‘newRQL’ command will not use this module anymore.

Parameters

moduleCategorystr

A terminal command parameter, specify the library sub-category you want to remove module from.

moduleNamestr

A terminal command parameter, specify the module name you want to remove from default.

Returns

None

saveModule(moduleCategory='', targetPath='', targetName='')[source]

saveModule() is a function to save a RiskQuantLib module and add it to library.

Use terminal command ‘saveRQL’ to use this function. The terminal command ‘saveRQL’ accept two parameters: ‘moduleCategory’ and ‘targetPath’. ‘moduleCategory’ is the sub-category of your library where you want to save file into, by default, it can be template, model or tool. ‘targetPath’ is the file or directory path that you want to save. There is also an optional parameter ‘targetName’, which is the name you want to give to this module. After calling this function, a ‘.zip’ file will be created in the target directory, and this file will be stored as a module.

Parameters

moduleCategorystr

A terminal command parameter, specify the library sub-category you want to save ‘.zip’ file into.

targetPathstr

A terminal command parameter, specify the file or directory path which you want to save as template.

targetNamestr

A terminal command parameter, specify the name you want to save this module as.

Returns

None

sendModule(targetPath='')[source]

sendModule() is a function to send any file or directory to your friend by LOCAL AREA NETWORK (LAN).

Use terminal command ‘sendRQL targetProjectPath’ or ‘sendRQL targetFilePath’ to use this function. If you send a directory, it will be packed into a zip file at first, and sent to your friend.

After this function is called, you can send to your friend who is also in the same LAN. You can not send files or project to people outside your local network by this function. If you want to share with friends who is across ocean, maybe you should use Github and getRQL command.

Return type:

None

Parameters

targetPathstr

A terminal command parameter, specify the path of file or directory you want to send.

Returns

None

setDefaultModule(moduleCategory='', moduleName='')[source]

setDefaultModule() is a function to set a module into default initialization one.

Use terminal command ‘dftRQL’ to use this function. The terminal command ‘dftRQL’ accept two parameters: ‘moduleCategory’ and ‘moduleName’. ‘moduleCategory’ is the sub-category of your library where you want to set module as default from, by default, it can be model or tool. ‘moduleName’ is the module name you want to set as default one. After calling this function, the existing RiskQuantLib module will be set as default, which means every new RiskQuantLib project created by ‘newRQL’ command will use this module.

Parameters

moduleCategorystr

A terminal command parameter, specify the library sub-category you want to set module as default from.

moduleNamestr

A terminal command parameter, specify the module name you want to set as default.

Returns

None

unBuildProject(targetPath='')[source]

unBuildProject() is a function to un-build RiskQuantLib project.

Use terminal command ‘ubldRQL targetProjectPath’ to use this function. The project will be un-built and return to the initial status.

After this function is called, the attribute API will be automatically removed, any all registration of instrument will be deleted. But, python source file will not be deleted until you do it by yourself.

After a project is un-built, you can not use instrument directly in main.py or create new instrument inherited from those un-registered instrument. The file config.py will not be changed after you call this function.

Parameters

targetPathstr

A terminal command parameter, specify the RiskQuantLib project path you want to un-build and un-render.

Returns

None

unpackModule(moduleCategory='', moduleName='', targetPath='')[source]

unpackModule() is a function to unpack a RiskQuantLib module from library and use it again.

Use terminal command ‘tplRQL’ to use this function. The terminal command ‘tplRQL’ accept two parameters: ‘moduleCategory’ and ‘moduleName’, ‘moduleCategory’ is the sub-category of your library where you want to unpack module from, by default, it can be template, model or tool. ‘moduleName’ is the module name you want to unpack from library. ‘targetPathString’ is the path where you want to unpack RiskQuantLib module into. After calling this function, the content of existing RiskQuantLib module will be unpacked to the location you choose, and you can start a project at the foundation of this un-packed module, or use the functions or models of un-packed module.

Parameters

moduleCategorystr

A terminal command parameter, specify the library sub-category you want to un-pack ‘.zip’ file from.

moduleNamestr

A terminal command parameter, specify the module name you want to unpack from library.

targetPathstr

A terminal command parameter, specify the path where you want to un-pack module into.

Returns

None