Exemple #1
0
 def position_for_ticker_exists_in_portfolio(ticker: Ticker) -> bool:
     if isinstance(ticker, FutureTicker):
         # Check if any of specific tickers with open positions in portfolio belongs to tickers family
         return any([
             ticker.belongs_to_family(t)
             for t in specific_tickers_with_open_position
         ])
     else:
         return ticker in specific_tickers_with_open_position
Exemple #2
0
    def _filter_transactions(self, ticker: Ticker, transactions: List[Transaction], start_date: datetime,
                             end_date: datetime) -> QFSeries:
        """ Filters out transactions, which do not correspond to the given ticker and returns a QFSeries of remaining
        transactions. Only transactions between start_date market open and end_date market close are considered. """
        transactions = [t for t in transactions if start_date + MarketOpenEvent.trigger_time()
                        <= t.time <= end_date + MarketCloseEvent.trigger_time()]

        if isinstance(ticker, FutureTicker):
            transactions_for_tickers = [t for t in transactions if ticker.belongs_to_family(t.ticker)]
        else:
            transactions_for_tickers = [t for t in transactions if ticker == t.ticker]

        transactions_records = [(t, t.time) for t in transactions_for_tickers]
        transactions_series = QFDataFrame.from_records(transactions_records, columns=["Transaction", "Index"]) \
            .set_index("Index").iloc[:, 0]
        return transactions_series