Portfolio - Loren1166/NautilusTrader- GitHub Wiki

Portfolio | 投资组合

The portfolio subpackage provides portfolio management functionality. 投资组合子包提供投资组合管理功能。

class Portfolio | 投资组合

class Portfolio(PortfolioFacade):
    """
    Provides a trading portfolio. 
    提供交易投资组合。

    Currently there is a limitation of one account per ExecutionClient instance. 
    目前,每个 ExecutionClient 实例限制一个账户。

    Parameters:
    参数:
        msgbus (MessageBus) – The message bus for the engine. 
        引擎的消息总线。
        cache (CacheFacade) – The read-only cache for the portfolio. 
        投资组合的只读缓存。
        clock (Clock) – The clock for the portfolio. 
        投资组合的时钟。
    """
    def __init__(self, msgbus: MessageBus, cache: CacheFacade, clock: Clock):
        ...

    def account(self, venue: Venue) -> Account:
        """
        Return the account for the given venue (if found). 
        返回给定场所的账户(如果找到)。

        Parameters: 
        参数:
            venue (Venue) – The venue for the account. 
            账户的场所。

        Return type: Account or None
        """
        ...

    def balances_locked(self, venue: Venue) -> dict:
        """
        Return the balances locked for the given venue (if found). 
        返回给定场所的锁定余额(如果找到)。

        Parameters: 
        参数:
            venue (Venue) – The venue for the margin. 
            保证金的场所。

        Return type: dict[Currency, Money] or None
        """
        ...

    def dispose(self) -> None:
        """
        Dispose of the portfolio. 
        处理投资组合。

        All stateful fields are reset to their initial value. 
        所有状态字段都重置为其初始值。
        """
        ...

    def initialize_orders(self) -> None:
        """
        Initialize the portfolios orders. 
        初始化投资组合订单。

        Performs all account calculations for the current orders state. 
        对当前订单状态执行所有账户计算。
        """
        ...

    def initialize_positions(self) -> None:
        """
        Initialize the portfolios positions. 
        初始化投资组合仓位。

        Performs all account calculations for the current position state. 
        对当前仓位状态执行所有账户计算。
        """
        ...

    def is_completely_flat(self) -> bool:
        """
        Return a value indicating whether the portfolio is completely flat. 
        返回一个值,指示投资组合是否完全平仓。

        Returns: 
        返回值:
            True if net flat across all instruments, else False. 
            如果所有工具的净持仓为平仓,则返回 True,否则返回 False。

        Return type: bool
        """
        ...

    def is_flat(self, instrument_id: InstrumentId) -> bool:
        """
        Return a value indicating whether the portfolio is flat for the given instrument ID. 
        返回一个值,指示投资组合是否对给定的工具 ID 平仓。

        Parameters: 
        参数:
            instrument_id (InstrumentId) – The instrument query filter. 
            工具查询过滤器。

        Returns: 
        返回值:
            True if net flat, else False. 
            如果净持仓为平仓,则返回 True,否则返回 False。

        Return type: bool
        """
        ...

    def is_net_long(self, instrument_id: InstrumentId) -> bool:
        """
        Return a value indicating whether the portfolio is net long the given instrument ID. 
        返回一个值,指示投资组合是否对给定的工具 ID 净多头。

        Parameters: 
        参数:
            instrument_id (InstrumentId) – The instrument for the query. 
            查询的工具。

        Returns: 
        返回值:
            True if net long, else False. 
            如果净多头,则返回 True,否则返回 False。

        Return type: bool
        """
        ...

    def is_net_short(self, instrument_id: InstrumentId) -> bool:
        """
        Return a value indicating whether the portfolio is net short the given instrument ID. 
        返回一个值,指示投资组合是否对给定的工具 ID 净空头。

        Parameters: 
        参数:
            instrument_id (InstrumentId) – The instrument for the query. 
            查询的工具。

        Returns: 
        返回值:
            True if net short, else False. 
            如果净空头,则返回 True,否则返回 False。

        Return type: bool
        """
        ...

    def margins_init(self, venue: Venue) -> dict:
        """
        Return the initial (order) margins for the given venue (if found). 
        返回给定场所的初始(订单)保证金(如果找到)。

        Parameters: 
        参数:
            venue (Venue) – The venue for the margin. 
            保证金的场所。

        Return type: dict[Currency, Money] or None
        """
        ...

    def margins_maint(self, venue: Venue) -> dict:
        """
        Return the maintenance (position) margins for the given venue (if found). 
        返回给定场所的维持(仓位)保证金(如果找到)。

        Parameters: 
        参数:
            venue (Venue) – The venue for the margin. 
            保证金的场所。

        Return type: dict[Currency, Money] or None
        """
        ...

    def net_exposure(self, instrument_id: InstrumentId) -> Money:
        """
        Return the net exposure for the given instrument (if found). 
        返回给定工具的净敞口(如果找到)。

        Parameters: 
        参数:
            instrument_id (InstrumentId) – The instrument for the calculation. 
            用于计算的工具。

        Return type: Money or None
        """
        ...

    def net_exposures(self, venue: Venue) -> dict:
        """
        Return the net exposures for the given venue (if found). 
        返回给定场所的净敞口(如果找到)。

        Parameters: 
        参数:
            venue (Venue) – The venue for the market value. 
            市值的场所。

        Return type: dict[Currency, Money] or None
        """
        ...

    def net_position(self, instrument_id: InstrumentId) -> Decimal:
        """
        Return the total net position for the given instrument ID. If no positions for instrument_id then will return Decimal('0'). 
        返回给定工具 ID 的总净持仓。如果 instrument_id 没有仓位,则将返回 Decimal('0')。

        Parameters: 
        参数:
            instrument_id (InstrumentId) – The instrument for the query. 
            查询的工具。

        Return type: Decimal
        """
        ...

    def reset(self) -> None:
        """
        Reset the portfolio. 
        重置投资组合。

        All stateful fields are reset to their initial value. 
        所有状态字段都重置为其初始值。
        """
        ...

    def set_specific_venue(self, venue: Venue) -> None:
        """
        Set a specific venue for the portfolio. 
        为投资组合设置特定场所。

        Parameters: 
        参数:
            venue (Venue) – The specific venue to set. 
            要设置的特定场所。
        """
        ...

    def unrealized_pnl(self, instrument_id: InstrumentId) -> Money:
        """
        Return the unrealized PnL for the given instrument ID (if found). 
        返回给定工具 ID 的未实现盈亏(如果找到)。

        Parameters: 
        参数:
            instrument_id (InstrumentId) – The instrument for the unrealized PnL. 
            用于未实现盈亏的工具。

        Return type: Money or None
        """
        ...

    def unrealized_pnls(self, venue: Venue) -> dict:
        """
        Return the unrealized pnls for the given venue (if found). 
        返回给定场所的未实现盈亏(如果找到)。

        Parameters: 
        参数:
            venue (Venue) – The venue for the unrealized pnl. 
            未实现盈亏的场所。

        Return type: dict[Currency, Money] or None
        """
        ...

    def update_account(self, event: AccountState) -> None:
        """
        Apply the given account state. 
        应用给定的账户状态。

        Parameters: 
        参数:
            event (AccountState) – The account state to apply. 
            要应用的账户状态。
        """
        ...

    def update_order(self, event: OrderEvent) -> None:
        """
        Update the portfolio with the given order. 
        使用给定订单更新投资组合。

        Parameters: 
        参数:
            event (OrderEvent) – The event to update with. 
            要更新的事件。
        """
        ...

    def update_position(self, event: PositionEvent) -> None:
        """
        Update the portfolio with the given position event. 
        使用给定的仓位事件更新投资组合。

        Parameters: 
        参数:
            event (PositionEvent) – The event to update with. 
            要更新的事件。
        """
        ...

    def update_quote_tick(self, tick: QuoteTick) -> None:
        """
        Update the portfolio with the given tick. 
        使用给定的行情更新投资组合。

        Clears the unrealized PnL for the quote ticks instrument, and performs any initialization calculations which may have been pending a market quote update. 
        清除报价行情工具的未实现盈亏,并执行任何可能已挂起市场报价更新的初始化计算。

        Parameters: 
        参数:
            tick (QuoteTick) – The tick to update with. 
            要更新的行情。
        """
        ...

class PortfolioFacade | 投资组合外观

class PortfolioFacade:
    """
    Provides a read-only facade for a Portfolio. 
    提供投资组合的只读外观。
    """
    def account(self, venue: Venue) -> Account:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    @property
    def analyzer(self) -> PortfolioAnalyzer:
        """
        The portfolios analyzer. 
        投资组合分析器。

        Returns: PortfolioAnalyzer
        """
        ...

    def balances_locked(self, venue: Venue) -> dict:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    @property
    def initialized(self) -> bool:
        """
        If the portfolio is initialized. 
        如果投资组合已初始化。

        Returns: bool
        """
        ...

    def is_completely_flat(self) -> bool:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    def is_flat(self, instrument_id: InstrumentId) -> bool:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    def is_net_long(self, instrument_id: InstrumentId) -> bool:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    def is_net_short(self, instrument_id: InstrumentId) -> bool:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    def margins_init(self, venue: Venue) -> dict:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    def margins_maint(self, venue: Venue) -> dict:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    def net_exposure(self, instrument_id: InstrumentId) -> Money:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    def net_exposures(self, venue: Venue) -> dict:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    def net_position(self, instrument_id: InstrumentId):
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    def unrealized_pnl(self, instrument_id: InstrumentId) -> Money:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    def unrealized_pnls(self, venue: Venue) -> dict:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

The Portfolio facilitates the management of trading operations. Portfolio 促进了交易操作的管理。

The intended use case is for a single Portfolio instance per running system, a fleet of trading strategies will organize around a portfolio with the help of the Trader` class. 预期的用例是每个运行的系统对应一个 Portfolio 实例,借助 Trader 类,一组交易策略将围绕一个投资组合进行组织。

The portfolio can satisfy queries for account information, margin balances, total risk exposures and total net positions. 投资组合可以满足账户信息、保证金余额、总风险敞口和总净持仓的查询。

Portfolio | 投资组合

class Portfolio | 投资组合

class Portfolio(PortfolioFacade):
    """
    Provides a trading portfolio. 
    提供交易投资组合。

    Currently there is a limitation of one account per ExecutionClient instance. 
    目前,每个 ExecutionClient 实例限制一个账户。

    Parameters:
    参数:
        msgbus (MessageBus) – The message bus for the engine. 
        引擎的消息总线。
        cache (CacheFacade) – The read-only cache for the portfolio. 
        投资组合的只读缓存。
        clock (Clock) – The clock for the portfolio. 
        投资组合的时钟。
    """
    def __init__(self, msgbus: MessageBus, cache: CacheFacade, clock: Clock):
        ...

    def account(self, venue: Venue) -> Account:
        """
        Return the account for the given venue (if found). 
        返回给定场所的账户(如果找到)。

        Parameters: 
        参数:
            venue (Venue) – The venue for the account. 
            账户的场所。

        Return type: Account or None
        """
        ...

    @property
    def analyzer(self) -> PortfolioAnalyzer:
        """
        The portfolios analyzer. 
        投资组合分析器。

        Returns: PortfolioAnalyzer
        """
        ...

    def balances_locked(self, venue: Venue) -> dict:
        """
        Return the balances locked for the given venue (if found). 
        返回给定场所的锁定余额(如果找到)。

        Parameters: 
        参数:
            venue (Venue) – The venue for the margin. 
            保证金的场所。

        Return type: dict[Currency, Money] or None
        """
        ...

    def dispose(self) -> None:
        """
        Dispose of the portfolio. 
        处理投资组合。

        All stateful fields are reset to their initial value. 
        所有状态字段都重置为其初始值。
        """
        ...

    def initialize_orders(self) -> None:
        """
        Initialize the portfolios orders. 
        初始化投资组合订单。

        Performs all account calculations for the current orders state. 
        对当前订单状态执行所有账户计算。
        """
        ...

    def initialize_positions(self) -> None:
        """
        Initialize the portfolios positions. 
        初始化投资组合仓位。

        Performs all account calculations for the current position state. 
        对当前仓位状态执行所有账户计算。
        """
        ...

    @property
    def initialized(self) -> bool:
        """
        If the portfolio is initialized. 
        如果投资组合已初始化。

        Returns: bool
        """
        ...

    def is_completely_flat(self) -> bool:
        """
        Return a value indicating whether the portfolio is completely flat. 
        返回一个值,指示投资组合是否完全平仓。

        Returns: 
        返回值:
            True if net flat across all instruments, else False. 
            如果所有工具的净持仓为平仓,则返回 True,否则返回 False。

        Return type: bool
        """
        ...

    def is_flat(self, instrument_id: InstrumentId) -> bool:
        """
        Return a value indicating whether the portfolio is flat for the given instrument ID. 
        返回一个值,指示投资组合是否对给定的工具 ID 平仓。

        Parameters: 
        参数:
            instrument_id (InstrumentId) – The instrument query filter. 
            工具查询过滤器。

        Returns: 
        返回值:
            True if net flat, else False. 
            如果净持仓为平仓,则返回 True,否则返回 False。

        Return type: bool
        """
        ...

    def is_net_long(self, instrument_id: InstrumentId) -> bool:
        """
        Return a value indicating whether the portfolio is net long the given instrument ID. 
        返回一个值,指示投资组合是否对给定的工具 ID 净多头。

        Parameters: 
        参数:
            instrument_id (InstrumentId) – The instrument for the query. 
            查询的工具。

        Returns: 
        返回值:
            True if net long, else False. 
            如果净多头,则返回 True,否则返回 False。

        Return type: bool
        """
        ...

    def is_net_short(self, instrument_id: InstrumentId) -> bool:
        """
        Return a value indicating whether the portfolio is net short the given instrument ID. 
        返回一个值,指示投资组合是否对给定的工具 ID 净空头。

        Parameters: 
        参数:
            instrument_id (InstrumentId) – The instrument for the query. 
            查询的工具。

        Returns: 
        返回值:
            True if net short, else False. 
            如果净空头,则返回 True,否则返回 False。

        Return type: bool
        """
        ...

    def margins_init(self, venue: Venue) -> dict:
        """
        Return the initial (order) margins for the given venue (if found). 
        返回给定场所的初始(订单)保证金(如果找到)。

        Parameters: 
        参数:
            venue (Venue) – The venue for the margin. 
            保证金的场所。

        Return type: dict[Currency, Money] or None
        """
        ...

    def margins_maint(self, venue: Venue) -> dict:
        """
        Return the maintenance (position) margins for the given venue (if found). 
        返回给定场所的维持(仓位)保证金(如果找到)。

        Parameters: 
        参数:
            venue (Venue) – The venue for the margin. 
            保证金的场所。

        Return type: dict[Currency, Money] or None
        """
        ...

    def net_exposure(self, instrument_id: InstrumentId) -> Money:
        """
        Return the net exposure for the given instrument (if found). 
        返回给定工具的净敞口(如果找到)。

        Parameters: 
        参数:
            instrument_id (InstrumentId) – The instrument for the calculation. 
            用于计算的工具。

        Return type: Money or None
        """
        ...

    def net_exposures(self, venue: Venue) -> dict:
        """
        Return the net exposures for the given venue (if found). 
        返回给定场所的净敞口(如果找到)。

        Parameters: 
        参数:
            venue (Venue) – The venue for the market value. 
            市值的场所。

        Return type: dict[Currency, Money] or None
        """
        ...

    def net_position(self, instrument_id: InstrumentId) -> Decimal:
        """
        Return the total net position for the given instrument ID. If no positions for instrument_id then will return Decimal('0'). 
        返回给定工具 ID 的总净持仓。如果 instrument_id 没有仓位,则将返回 Decimal('0')。

        Parameters: 
        参数:
            instrument_id (InstrumentId) – The instrument for the query. 
            查询的工具。

        Return type: Decimal
        """
        ...

    def reset(self) -> None:
        """
        Reset the portfolio. 
        重置投资组合。

        All stateful fields are reset to their initial value. 
        所有状态字段都重置为其初始值。
        """
        ...

    def set_specific_venue(self, venue: Venue) -> None:
        """
        Set a specific venue for the portfolio. 
        为投资组合设置特定场所。

        Parameters: 
        参数:
            venue (Venue) – The specific venue to set. 
            要设置的特定场所。
        """
        ...

    def unrealized_pnl(self, instrument_id: InstrumentId) -> Money:
        """
        Return the unrealized PnL for the given instrument ID (if found). 
        返回给定工具 ID 的未实现盈亏(如果找到)。

        Parameters: 
        参数:
            instrument_id (InstrumentId) – The instrument for the unrealized PnL. 
            用于未实现盈亏的工具。

        Return type: Money or None
        """
        ...

    def unrealized_pnls(self, venue: Venue) -> dict:
        """
        Return the unrealized pnls for the given venue (if found). 
        返回给定场所的未实现盈亏(如果找到)。

        Parameters: 
        参数:
            venue (Venue) – The venue for the unrealized pnl. 
            未实现盈亏的场所。

        Return type: dict[Currency, Money] or None
        """
        ...

    def update_account(self, event: AccountState) -> None:
        """
        Apply the given account state. 
        应用给定的账户状态。

        Parameters: 
        参数:
            event (AccountState) – The account state to apply. 
            要应用的账户状态。
        """
        ...

    def update_order(self, event: OrderEvent) -> None:
        """
        Update the portfolio with the given order. 
        使用给定订单更新投资组合。

        Parameters: 
        参数:
            event (OrderEvent) – The event to update with. 
            要更新的事件。
        """
        ...

    def update_position(self, event: PositionEvent) -> None:
        """
        Update the portfolio with the given position event. 
        使用给定的仓位事件更新投资组合。

        Parameters: 
        参数:
            event (PositionEvent) – The event to update with. 
            要更新的事件。
        """
        ...

    def update_quote_tick(self, tick: QuoteTick) -> None:
        """
        Update the portfolio with the given tick. 
        使用给定的行情更新投资组合。

        Clears the unrealized PnL for the quote ticks instrument, and performs any initialization calculations which may have been pending a market quote update. 
        清除报价行情工具的未实现盈亏,并执行任何可能已挂起市场报价更新的初始化计算。

        Parameters: 
        参数:
            tick (QuoteTick) – The tick to update with. 
            要更新的行情。
        """
        ...

class PortfolioFacade | 投资组合外观

class PortfolioFacade:
    """
    Provides a read-only facade for a Portfolio. 
    提供投资组合的只读外观。
    """
    def account(self, venue: Venue) -> Account:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    @property
    def analyzer(self) -> PortfolioAnalyzer:
        """
        The portfolios analyzer. 
        投资组合分析器。

        Returns: PortfolioAnalyzer
        """
        ...

    def balances_locked(self, venue: Venue) -> dict:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    @property
    def initialized(self) -> bool:
        """
        If the portfolio is initialized. 
        如果投资组合已初始化。

        Returns: bool
        """
        ...

    def is_completely_flat(self) -> bool:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    def is_flat(self, instrument_id: InstrumentId) -> bool:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    def is_net_long(self, instrument_id: InstrumentId) -> bool:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    def is_net_short(self, instrument_id: InstrumentId) -> bool:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    def margins_init(self, venue: Venue) -> dict:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    def margins_maint(self, venue: Venue) -> dict:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    def net_exposure(self, instrument_id: InstrumentId) -> Money:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    def net_exposures(self, venue: Venue) -> dict:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    def net_position(self, instrument_id: InstrumentId):
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    def unrealized_pnl(self, instrument_id: InstrumentId) -> Money:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...

    def unrealized_pnls(self, venue: Venue) -> dict:
        """
        Abstract method (implement in subclass). 
        抽象方法(在子类中实现)。
        """
        ...