Skip to content

tradeTypes

Ben Bell edited this page Nov 15, 2024 · 1 revision

Trade Types, Exceptions, and Data Classes Documentation

The tradeTypes.py module defines the trade types, exceptions, and data classes used in the backtesting framework.

Enums

TradeType

An enumeration of the different types of trades.

  • BUY: Buy trade
  • SELL: Sell trade
  • SHORT_SELL: Short sell trade
  • STOP: Stop order
  • COVER: Cover short position
  • GTC: Good-Till-Canceled order
  • Cancel: Cancel order
  • MARKET_BUY: Market buy order
  • MARKET_SELL: Market sell order
  • SHORT_COVER: Short cover order
  • LIMIT_BUY: Limit buy order
  • LIMIT_SELL: Limit sell order

Exceptions

InsufficientFundsError

Raised when there are insufficient funds to execute a trade.

InsufficientSharesError

Raised when there are insufficient shares to execute a sell trade.

InvalidCommissionTypeError

Raised when an invalid commission type is specified.

InvalidOrderError

Raised when an invalid order is specified.

ShortPositionError

Raised when there is an error with a short position.

Data Classes

Holding

Represents a holding in the portfolio.

Attributes

  • tradeType (TradeType): The type of trade.
  • ticker (str): The ticker symbol of the asset.
  • commission (float): The commission for the trade.
  • executedSuccessfully (bool): Whether the trade was executed successfully.
  • numShares (int): The number of shares.
  • totalCost (float): The total cost of the trade.
  • entryPrice (float): The entry price of the trade.
  • shortPosition (bool): Whether the holding is a short position.

Transaction

Represents a transaction in the backtest.

Attributes

  • tradeType (TradeType): The type of trade.
  • ticker (str): The ticker symbol of the asset.
  • commission (float): The commission for the trade.
  • executedSuccessfully (bool): Whether the trade was executed successfully.
  • numShares (int): The number of shares.
  • pricePerShare (float): The price per share.
  • totalCost (float): The total cost of the trade.
  • date (datetime): The date of the transaction.
  • profitLoss (float): The profit or loss from the trade.
  • notes (str): Additional notes about the transaction.

Order

Represents an order in the backtest.

Attributes

  • tradeType (TradeType): The type of trade.
  • ticker (str): The ticker symbol of the asset.
  • numShares (int): The number of shares.
  • targetPrice (float): The target price for the order.
  • duration (str): The duration of the order ('DAY' or 'GTC').
  • orderDate (datetime): The date the order was placed.
  • active (bool): Whether the order is active.
  • limitPrice (Optional[float]): The limit price for the order (if applicable).

Clone this wiki locally