finalynx.portfolio.folder

Module Contents

Classes

FolderDisplay

Enumeration to select how a folder should be displayed.

Sidecar

Folder

Holds a group of Node objects to build the portfolio hierarchy.

SharedFolder

Portfolio

This is the root of your custom portfolio hierarchy.

API

class finalynx.portfolio.folder.FolderDisplay[source]

Bases: enum.Enum

Enumeration to select how a folder should be displayed.

There are three options:

  • Expanded: Show all children in the output.

  • Collapsed: Only show the folder name.

  • Line: Only show the folder name and render it as if it was a line.

EXPANDED

0

COLLAPSED

1

LINE

2

class finalynx.portfolio.folder.Sidecar[source]
output_format: str

‘[delta]’

condition_format: str = <Multiline-String>
title: Optional[str]

None

render_folders: Union[bool, str]

True

class finalynx.portfolio.folder.Folder(name: str, asset_class: finalynx.portfolio.constants.AssetClass = AssetClass.UNKNOWN, asset_subclass: finalynx.portfolio.constants.AssetSubclass = AssetSubclass.UNKNOWN, parent: Optional[finalynx.portfolio.folder.Folder] = None, target: Optional[finalynx.portfolio.targets.Target] = None, children: Optional[List[finalynx.portfolio.node.Node]] = None, newline: bool = False, display: finalynx.portfolio.folder.FolderDisplay = FolderDisplay.EXPANDED, perf: Optional[finalynx.portfolio.line.LinePerf] = None, currency: Optional[str] = None, envelope: Optional[finalynx.portfolio.envelope.Envelope] = None)[source]

Bases: finalynx.portfolio.node.Node

Holds a group of Node objects to build the portfolio hierarchy.

Initialization

This class handles the orchestration of rendering of its children.

Parameters:
  • name – Name to be displayed in the final output.

  • asset_class – Useful shortcut to set all chidlren’s asset class at once. Children keep priority over this shortcut.

  • parent – Optional Node object as a parent. Each folder sets their children’s parents as itself by default.

  • target – Optional Target instance for this folder to render the total amount based on your own investment objectives.

  • children – List of Node objects contained in the folder. The folder’s amount corresponds to the sum of the amounts contained in all children.

  • newline – When printing to the console, you can print a blank line after this folder for better readability.

  • display – Choose how the folder should be displayed (expanded, collapsed or as a line).

  • perf – Useful shortcut to set all chidlren’s performance at once. Children keep priority over this shortcut.

add_child(child: finalynx.portfolio.node.Node) None[source]

Manually add a child at the end of the existing children in this folder.

Parameters:

child – Any Node object to add as a child.

Returns:

Nohing to return.

get_amount() float[source]

Get the total amount contained in this folder.

Returns:

The sum of what each child’s get_amount() method returns.

get_currency() str[source]
Returns:

This folder’s currency symbol, equal to its children common currency. If children have different currencies, return an unknown symbol (TODO to be improved).

get_ideal() float[source]
Returns:

The ideal amount to be invested in this node based on surrounding targets.

get_perf(ideal: bool = True) finalynx.portfolio.line.LinePerf[source]

Get the weighted mean expected performance of all children to get the folder’s expected performance.

tree(output_format: str = '[console]', _tree: Optional[rich.tree.Tree] = None, hide_root: bool = False, **render_args: Any) rich.tree.Tree[source]

Generate a fully rendered Tree object from the rich package using the

This Tree can either be manipulated for further operations or directly printed to the console using rich’s print method.

Parameters:
  • hide_amount – Replace the amoutns by simple dots (easier to share the result), defaults to False.

  • _tree – Internal method to pass the folder’s root tree object to the children.

  • args – Provide any list of arguments supported by the Tree class if this is the root folder in the hierarchy.

  • formatrich for console output, name for only names, defaults to rich

Returns:

A Tree instance containing the rendered titles for each Node object.

render_sidecar(sidecar: finalynx.portfolio.folder.Sidecar, hide_root: Optional[bool] = None, _tree: Optional[rich.tree.Tree] = None) rich.tree.Tree[source]

Generates a vertical tree with the specified output format for each node.

Parameters:
  • output_format – The output format to be rendered for each node.

  • condition_format – Only show this node’s output_format if the rendered condition_format is not empty (useful to match multiple sidecars together).

  • title – Name of this sidecar, displayed only if root is not hidden.

  • hide_root – Need to specify if the main tree’s root is hidden.

process() None[source]

Some Node or Target objects might need to process some data once the investment values have been fetched from Finary. Folders do not have any processing procedure. Here, we only call the process() method of all children.

match_lines(fetch_line: finalynx.fetch.fetch_line.FetchLine) List[finalynx.portfolio.line.Line][source]

Used by the fetch subpackage to

This method passes down the instance corresponding to an investment fetched online (e.g. in your Finary account) to its children and returns a constructed list of matching lines.

Parameters:

fetch_line – FetchLine instance created that represents an investment found online.

Returns:

A list of nodes that match with the online investment based on name, key, envelope, etc.

set_child_attribs(child: finalynx.portfolio.node.Node, asset_class: finalynx.portfolio.constants.AssetClass, asset_subclass: finalynx.portfolio.constants.AssetSubclass, perf: Optional[finalynx.portfolio.line.LinePerf], currency: Optional[str], envelope: Optional[finalynx.portfolio.envelope.Envelope]) None[source]

Used by Folders to set attributes once in the Folder instead of setting it in each child. Called at initialization time and when a child is manually added to the folder.

_render_name_color() str[source]

Internal method that overrides the superclass’ render method to display the folder name with a bold font of different color.

_render_newline() str[source]

Internal method that overrides the superclass’ render method to display a new line after the folder has rendered.

Returns:

The newline character depending on the user configuration.

_render_ideal() str[source]
Returns:

A string representation of the ideal amount to be invested in this folder. If this folder has no target, use the sum of its children’s ideals.

to_dict() Dict[str, Any][source]
static from_dict(dict: Dict[str, Any], buckets: Dict[str, finalynx.portfolio.bucket.Bucket], envelopes: Dict[str, finalynx.portfolio.envelope.Envelope]) finalynx.portfolio.folder.Folder[source]
class finalynx.portfolio.folder.SharedFolder(name: str, bucket: finalynx.portfolio.bucket.Bucket, asset_class: finalynx.portfolio.constants.AssetClass = AssetClass.UNKNOWN, asset_subclass: finalynx.portfolio.constants.AssetSubclass = AssetSubclass.UNKNOWN, target_amount: float = np.inf, parent: Optional[finalynx.portfolio.folder.Folder] = None, target: Optional[finalynx.portfolio.targets.Target] = None, newline: bool = False, display: finalynx.portfolio.folder.FolderDisplay = FolderDisplay.EXPANDED)[source]

Bases: finalynx.portfolio.folder.Folder

process() None[source]
to_dict() Dict[str, Any][source]
static from_dict(dict: Dict[str, Any], buckets: Dict[str, finalynx.portfolio.bucket.Bucket]) finalynx.portfolio.folder.SharedFolder[source]
class finalynx.portfolio.folder.Portfolio(name: str = 'Portfolio', target: Optional[finalynx.portfolio.targets.Target] = None, children: Optional[List[finalynx.portfolio.node.Node]] = None, currency: Optional[str] = None)[source]

Bases: finalynx.portfolio.folder.Folder

This is the root of your custom portfolio hierarchy.

Initialization

This class is actually nothing more than a normal Folder renamed to Portfolio for user clarity (and with ‘Portfolio’ as the default folder name). Technically, the hierarchy could just as much start with a Folder object.

Parameters:
  • name – The name that will be displayed in the rendered tree, defaults to Portfolio.

  • target – optional TargetSomething instance to render the total portfolio amount with certain conditions, defaults to None.

  • children – List of Line, Folder, and SharedFolder objects to recursively define the entire structure, defaults to an empty list.

static from_dict(dict: Dict[str, Any], buckets: Dict[str, finalynx.portfolio.bucket.Bucket], envelopes: Dict[str, finalynx.portfolio.envelope.Envelope]) finalynx.portfolio.folder.Portfolio[source]