Skip to content

A functional trading journal with statistical analysis and balance sheets.

License

Notifications You must be signed in to change notification settings

srccircumflex/Simple-Rich-Trading-Journal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Rich Trading Journal

image

0.3 #5 (2024-05-12)
Note Widget implemented
Bug fixes, improvements, code maintenance, some variables and element ids have been renamed.
#2

Unset cells of the table are formatted in the note interface with {*N/A*} (md). Module config.msg created.

#4
Light color theme added.
You can now create several journals (see commandline).
Configurations can now be transferred via the commandline.
Demos can now be created for a certain number of years.
#5

An bug has been fixed which led to an incorrect calculation of the ITC column of Dividends.

The project is still being worked on and some scenarios have not been tested.

✨ The project was realized with the opensource packages from plotly and CodeMirror.

This work is licensed under CC BY-NC-ND 4.0

Table of Contents

Install and Run

  • Install the latest version of the Python interpreter. At least version 3.10 is required.
  • Open the terminal and navigate in the project folder.
  • Install the required packages.

(the program name python could be different depending on the operating system or version, e.g. python3 or py)

> python -m pip install -r requirements.txt

Start through

> python main.py

The following message is displayed in the terminal:

Dash is running on http://127.0.0.1:8050/

 * Serving Flask app 'Simple Rich Trading Protocol'
 * Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:8050
Press CTRL+C to quit

Visit the link in your browser.

Demo

A demo is available for testing purposes. Start it by

> python demo

Create and start your own demo as follows

> python demo make='your demo id' -
> python demo 'your demo id'

By default, a sample journal is created with random data for the last three years. A custom number of years can be defined via the demo id:

> python demo make='your demo id#9'
> python demo 'your demo id#9'

For an example of how the plugins work, use the keyword plugin. Please note: in this case there must be an - in front of your id.

> python demo - 'your demo id' plugin

Records

General Information

  • The first record must be a deposit.
  • Some columns have a slightly different meaning or function depending on the type of record.
  • The time entries in the InvestTime and TakeTime columns are parsed automatically and can be entered according to the following patterns:

    [MM]
    [hh][MM]
    [dd][HH][MM]
    [dd][mm][HH][MM]
    [dd][mm][yy][HH][MM]
    With the exception of the last field from the left, all fields must have two digits.

    Characters from [ .,:/-] are allowed between the fields but are not required. If fields are omitted, they are filled from the current date. To apply the current date in full, a character from [n#0] can be entered.

  • ITC stands for 'Interests, Taxes and other Costs or Income'.

Trades

image

Enter a value greater than 0 in the column n and define the cells of the columns InvestTime and InvestAmount or InvestCourse to open a trade. The value from the ITC column is subtracted or added to the final profit in the calculations.

If a value is entered in TakeAmount or TakeCourse but not in TakeTime, the trade is still considered to be open, the Profit and Performance cell is calculated and, if with open is active, also the summary footer and a visible side section.

image

A trade is considered finalized if TakeTime is also defined.

image

Another way to close positions is to give the log a closing instruction. This can also be used to close several individual positions at once or to close individual positions only partially.

image

To do this, enter the appropriate Name, a negative number n, the TakeTime and the TakeAmount or TakeCourse in a free row.

Deposits

image

Enter a 0 in the column n and define the cells of the columns InvestTime and InvestAmount to define a deposit. The value from the ITC column is subtracted or added to the amount in the calculations.

The column Profit contains the sum of the profits of the following trades in relation to non-exhausted previous or interim deposits. Performance is then calculated in relation to the amount. The value in Dividend is calculated like Profit.

Entries in the column group Take are not accepted, these are defined by the program based on following payouts. Once the amount has been exhausted, the deposit record will no longer receive a profit value from that point on.

image

Payouts

image

Enter a 0 in the column n and define the cells of the columns TakeTime and TakeAmount to define a payout. The value from the ITC column is subtracted or added to the amount in the calculations.

Payouts are deducted from the sum of deposits, but not from profits. However, if the payouts exceed the available money, a ITC record is created from the remaining amount.

Entries in the column group Invest are not accepted.

The value in Performance represents the rate to the sum of previous deposits.

Dividends

image

For a dividend record it is important to enter a Name first, then enter a 0 in the column n and define the cells of the columns TakeTime and TakeAmount or TakeCourse.

Entries in the column group Invest or column ITC are not accepted.

If the dividend is defined in column TakeCourse, its amount is calculated with the sum of column n of previous associated trades. The ITC column represents the sum of the InvestAmount's of those trades. This is then used to calculate Performance to represent the dividend rate.

A trade belongs to the dividend if the Name is identical and it is open at the time of the dividend. The Dividend column of these associated trades is calculated in proportion to the InvestAmount.

image

Interests, Taxes and other Costs or Income (ITC)

image

Enter a 0 in the column n and define the cell of the column ITC and InvestTime or TakeTime to define a ITC record.

A ITC record is deducted or added to the profit.

Entries in the columns InvestAmount or TakeAmount are not accepted.

The value in Performance represents the rate to the sum of previous deposits.

Additional Features

Amount Calculation

You can enter arithmetic formulas in amount cells.

Supported operants and syntax:
+ addition
- subtraction
* multiplication
/ division
** exponentiation
% modulo
& bitwise and
| bitwise or
^ bitwise xor
(...) calculation in brackets
1 000,1 international thousands and decimal separator
1.000,1 non-english thousands and decimal separator
1,000.1 english thousands and decimal separator

Copy and Paste

Functions are implemented but still buggy.

Supported actions:
ctrl+c write a cell content to the clipboard.
ctrl+x write a cell content to the clipboard and delete it from the log.
ctrl+a, ctrl+y, ctrl+z write a row to the clipboard.
ctrl+shift+x write a row to the clipboard and delete it from the log.
ctrl+v insert the content (if the insertion does not work, move the cursor to another cell and back again and try again).

Until now, the entire log has been recalculated after insertion, which may take more computing time than simply editing a cell.

Currently, the following error may occur temporarily, which leads to the copy function being blocked: Uncaught (in promise) DOMException: Clipboard write was blocked due to lack of user activation.

The feature can be deactivated by disableCopyPaste.

Autocompletion

(since v0.2)

An autocomplete interface is available for the Name, Symbol and Type column. Use the key combination ctrl+space while one of these cells is in focus.

image

The interface searches for similar entries in the column based on the cell value. If the cell is empty, press the down-arrow after calling up the interface. Click on an entry or select it with Enter. Click anywhere else or press Escape to close the interface without confirming.

The pool is always created when the page is loaded and is not expanded during editing.

Note Widget

(since v0.3)
As before, (short) notes can be entered in the cell of the table.

image

The note interface consists of a dash Markdown component as a display element (the note sheet) and a CodeMirror Editor (the note editor).

Get in Touch

Press ctrl+i to open the note sheet, if the note editor is not yet open, it will be opened the next time ctrl+i is pressed. Otherwise, the note sheet is closed.

ctrl+shift+i has different functions, depending on whether an element of the note interface is open. If neither the note sheet nor the note editor is open, the key combination functions as direct access to the note editor. Otherwise, the window position of the elements is switched.

To return the cursor from the note editor to the journal, press ctrl+#. The next time you press ctrl+i, it jumps back to the note editor.

esc closes all elements of the note interface.

General Syntax Rule

The dynamic integration of cell variables is active by default (noteCellVariableFormatter). These are processed internally using the python string format library. As the curly brackets {} are part of their specifications, when using them as characters or in LaTeX/Mathematics sections, please note that they must be masked by doubling them. This communicates to the formatter that it is a character and not a command: {{ becomes { and }} becomes }. As the syntax of LaTeX/Mathematics also frequently uses curly brackets, an internal (invisible) automation is activated by default (noteMathJaxMasker), which masks the curly brackets in LaTeX/Mathematics sections.

Markdown and LaTeX Mathematics

The note interface supports most expressions of the Markdown language, see the Markdown Guide for an introduction.

In addition, the rendering of LaTeX/Mathematics can be activated by noteMathJax. In the document, the sections that are written in the language must then be delimited by the character strings $$. Due to the inclusion of various functions, the doubling should also be used for the inline expression, even if the original documentation provides for a simple $.

image

Cell Variables

image

The value from a cell in the row can be dynamically included in the document, for example the time of opening an record via {InvestTime}.

In the file plugin/__init__.py you will find a list of the available fields.

image

A function is implemented and activated by default that recognizes the dropping of files/images, urls/links and filepaths into the note editor and integrates them into the document in Markdown language accordingly (noteFileDropCloner).

To ensure that the page can access the file, a copy of the dropped file is created in the asset folder (this also means that updates to the original file are not applied).

Please note: For security reasons, all browsers deny access to the file system. Therefore, links with the file:/// protocol are not functional; hence the implementation of the FileDropClone feature. Depending on the browser, it is possible to grant access [for certain pages] in various ways. Here is a small excerpt on the topic related to the Firefox browser.

Nice to Know

General

  • The project has so far only been tested on Mozilla Firefox 125.0.2 on Linux.
  • Before the log is (further) edited, large calculations should be completed.
  • When calculations are running, working... is displayed in the tab label.
  • The log is recalculated when a defined record is detected or changed.
  • Reload the page to reorder all the records.
  • Confirm an entry in InvestAmount or TakeAmount with Enter, not with Tap (BUG).
  • Side sections are only calculated if they are visible. If many edits are made, they should be hidden.
  • The side section can be hidden by pressing the button in the lower control bar again.
  • The bottom control bar is only visible when the mouse is moved over it.
  • The size of the side section can be changed: drag/double-click the separator
  • Look at rconfig.py
  • Look at plugin/__init__.py
  • To import data, plugin.init_log could be implemented.
  • If internal errors occur after editing, a red stripe appears. This disappears after the next edit without errors. If the error cannot be identified, the page should be reloaded.
  • Debug by reloading the page.

Commandline

By default, SRTJ does not expect any command line parameters.

In addition to the main journal, further journals can be created/called up via the command line.

> python main.py 'your journal id'

In addition, configurations from rconfig.py can be transferred via the command line. If this is done in addition to the transfer of a custom journal id, this must be specified with the key -. The command line parser supports the transfer of lists in python syntax for the definition of such configurations, note that string types are defined with quotation marks (otherwise, do not pay attention to these). Alternatively, only a field of a list can be defined.

> python main.py - 'your journal id' colorTheme light scopeByIndex 0 logColOrder [1, 3, 4, 5,2,6,7, 8] logColWidths[2] 100

Version History

0.2 #1 (2024-05-05)

Autocompletion implemented

0.1 #1 (2024-04-29)

Initial Commit