alpaca_daily_losers.liquidate

Attributes

LIQUIDATE_PERCENTAGE

Classes

Liquidate

Functions

send_message(message)

Send a message to Slack.

send_position_messages(positions, pos_type)

Sends position messages based on the type of position.

Module Contents

alpaca_daily_losers.liquidate.send_message(message: str)

Send a message to Slack.

Parameters:

message (str) – Message to send.

alpaca_daily_losers.liquidate.send_position_messages(positions: list, pos_type: str)

Sends position messages based on the type of position.

Parameters:
  • positions (list) – List of position dictionaries.

  • pos_type (str) – Type of position (“buy”, “sell”, or “liquidate”).

Returns:

True if message was sent successfully, False otherwise.

Return type:

bool

alpaca_daily_losers.liquidate.LIQUIDATE_PERCENTAGE = 1.0
class alpaca_daily_losers.liquidate.Liquidate(trading_client: py_alpaca_api.trading.Trading, py_logger: logging.Logger)
static calculate_cash_needed(total_holdings: float, cash_row: pandas.DataFrame) float

Calculate the amount of cash needed to liquidate a portion of holdings.

Parameters:
  • total_holdings (float) – The total value of the holdings to be liquidated.

  • cash_row (pd.DataFrame) – A DataFrame containing the cash information.

Returns:

The amount of cash needed for liquidation, including a fixed fee of $5.00.

Return type:

float

static get_top_performers(current_positions: pandas.DataFrame) pandas.DataFrame

Returns the top performers from the given current positions DataFrame.

Parameters:

current_positions (pd.DataFrame) – DataFrame containing the current positions.

Returns:

DataFrame containing the top performers.

Return type:

pd.DataFrame

liquidate_positions() None

Liquidates positions to make cash 10% of the portfolio.

This method sells positions in order to meet the requirement of having cash equal to 10% of the portfolio’s total value. It identifies the top performers in the current positions and calculates the amount of cash needed to meet the requirement. It then sells the necessary amount of shares for each top performer.

Returns:

None

_sell_top_performers(top_performers: pandas.DataFrame, top_performers_market_value: float, cash_needed: float) list

Sells positions of top performers to liquidate the required cash.

Parameters:
  • top_performers (pd.DataFrame) – DataFrame containing top performer positions.

  • top_performers_market_value (float) – The total market value of top performers.

  • cash_needed (float) – The amount of cash needed to be liquidated.

Returns:

List of sold positions with their details.

Return type:

list

static _send_liquidation_message(message: str)

Send a liquidation message using the global send_message function.

Parameters:

message (str) – The message to be sent.