Most of the styles we follow are in line with QuantLib’s conventions. More styles and variable naming conventions in Julialang. More styles for Python.
Use four spaces per indentation level.
Each notebook will have one section (#) and several subsections (##), subsubsections (###), etc. Each sub/sub/section should be followed by one descriptive paragraph with one to ten sentences. You don't need to assign a sectioning for each cell. In fact, each sub/sub/section could consist of a series of cells following the same purpose.
- File names, folder names: UpperCamelCase [julia] or Python packages should also have short, all-lowercase names although the use of underscores is discouraged. [python]
- Names of variables, functions, and macros: lowerCamelCase [julia] or snake_case [python] Exceptions:
Δpricelowercase with words separated by underscores as necessary to improve readability [python] - The arguments of function (including constructors) are aligned with the indent of the first argument.
- Always use
selffor the first argument to instance methods. Always useclsfor the first argument to class methods. If a function argument’s name clashes with a reserved keyword, it is generally better to append a single trailing underscore rather than use an abbreviation or spelling corruption. Thusclass_is better thanclss. - Use of underscores is discouraged unless the name would be hard to read otherwise.
- Names of Types, Modules, Classes, Structs, Dictionaries: UpperCamelCase
- Functions that write to their arguments have names that end in
!. These are sometimes called "mutating" or "in-place" functions because they are intended to produce changes in their arguments after the function is called, not just return a value. - A constant or a static variable: ALL_CAPS_AND_UNDERSCORES
- Refrain from using
getin the name of a function (e.g. usePCAinstead ofgetPCAorget_PCA). - Conciseness is valued, but avoid abbreviation (
indexinrather thanindxin) as it becomes difficult to remember whether and how particular words are abbreviated. - List of abbreviations:
math,cov,corr,vol,max,min. - Number of something is named
nSomething[julia] orn_something[python] (notnumSomething,numberSomething, etc.)
- Each line is commented.
- Use the settings of your VS Code to hide comments unless your cursor is on a line.
- Files -> Preferences -> Settings -> search for “editor.token” -> Edit in settings.json -> add the following lines:
"editor.renderWhitespace": "none", "workbench.colorCustomizations": { "editor.lineHighlightBackground": "#2C3E50" }, "editor.tokenColorCustomizations": { "comments": "#201c1c" }
- The
=operator does not make a copy. It is assigning a new variable (i.e., way to refer to an object) the same reference (actual object in memory). If you want a copy, you can usecopy.
- In the Julia programming language: no use of pandas. Use
DataFramesandTimeArray.
- Should be transparent.
- All time-series data (pd.Series, pd.DataFrame, etc.) in Python should be converted to
TimeArraystructs in Julia. We strongly advise against using the Pandas Julia wrapper or the Julia DataFrame.TimeArraystructs can be converted to DataFrames in the code blocks and then converted back toTimeArraysfor convenience.
=,>,=>,<,=<,+=,-=,*=,==,===,&&,||: leave a space before and after*,/,^: do not leave spaces before and after+,-: leave spaces before and after;: put a space after (and not before) comma and semicolon