finalynx.portfolio.node๏ƒ

Module Contents๏ƒ

Classes๏ƒ

Node

Abstract class that represents an element in the Portfolio tree.

API๏ƒ

class finalynx.portfolio.node.Node(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, newline: bool = False, perf: Optional[finalynx.portfolio.constants.LinePerf] = None, currency: Optional[str] = None, envelope: Optional[finalynx.portfolio.envelope.Envelope] = None, aliases: Optional[Dict[str, str]] = None, agents: Optional[Dict[str, Callable[..., str]]] = None)[source]๏ƒ

Bases: finalynx.portfolio.hierarchy.Hierarchy, finalynx.portfolio.render.Render

Abstract class that represents an element in the Portfolio tree.

Initialization

This is an abstract class used by the Line and Folder subclasses.

Parameters:
  • name โ€“ The name that will be displayed in the final portfolio tree.

  • parent โ€“ Parent of this node, passed up to the superclass Hierarchy.

  • target โ€“ Optional Target instance to format this lineโ€™s amount based on the objective you selected.

  • newline โ€“ Print a new line in the console at the end of this Line for better readability.

  • aliases โ€“ Add or replace render aliases used when specifying a render format.

  • agents โ€“ Add or replace keywords associated to rendering callbacks.

abstract get_amount() float[source]๏ƒ

Virtual method that must be implemented by all subclasses.

get_ideal() float[source]๏ƒ
Returns:

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

get_delta() float[source]๏ƒ
Returns:

How much should be invested in this node to reach the ideal amount set by the target.

abstract get_perf() finalynx.portfolio.constants.LinePerf[source]๏ƒ
Returns:

The expected yearly performance of this node.

get_currency() str[source]๏ƒ
Returns:

This nodeโ€™s currency symbol.

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 specified format.

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 amounts 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.

Returns:

If the _tree argument is empty, the function returns a new Tree instance with this nodeโ€™s render. Otherwise, it adds this nodeโ€™s render as a child node and returns the _tree.

process() None[source]๏ƒ

Some Node or Target objects might need to process some data once the investment values have been fetched from Finary. Here, this method is left as esmpty but can be overridden by subclasses.

_render_currency() str[source]๏ƒ
Returns:

A formatted rendering of this elementโ€™s currency.

_render_hint() str[source]๏ƒ
Returns:

A formatted rendering of a hint message (at the end by default).

_render_prehint() str[source]๏ƒ
Returns:

A formatted rendering of a pre-hint message (next to the amount by default).

_render_amount(hide_amounts: bool = False) str[source]๏ƒ
Returns:

A formatted rendering of the node amount aligned with the other elements in the same parent.

Parameters:

hide_amounts โ€“ Replaces amoutn with a dummy amount with dots instead of the real amount (easier to share).

_render_goal() str[source]๏ƒ
Returns:

A formatted rendering of the target goal. This could either be an ideal amount or ratio to be reached.

_render_ideal() str[source]๏ƒ
Returns:

A formatted rendering of the ideal amount to be invested based on the target.

_render_delta(align: bool = True, children: Optional[List[finalynx.portfolio.node.Node]] = None) str[source]๏ƒ

Creates a formatted rendering of the delta investment needed to reach the target.

Parameters:
  • align โ€“ Use the children parameter as a list of nodes to align all amounts vertically.

  • children โ€“ List of Node objects used for vertical alignemnt, defaults to this parentโ€™s children.

Returns:

The rendered string.

_render_perf() str[source]๏ƒ
Returns:

A formatted rendering of the nodeโ€™s expected yearly performance.

_render_name() str[source]๏ƒ
Returns:

A formatted rendering of the node name.

_render_name_color() str[source]๏ƒ
Returns:

A formatted rendering of the node nameโ€™s color.

_render_newline() str[source]๏ƒ
Returns:

A rendering of the newline if set by the user.

__repr__() str[source]๏ƒ
Returns:

A console representation of this node for debugging.

__str__() str[source]๏ƒ
Returns:

The formatted console rendering of this node.

abstract to_dict() Dict[str, Any][source]๏ƒ