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]