Exemplo n.º 1
0
def get_unrealized_short_pnl(trader: shift.Trader):
    total_unrealized_short_pnl = 0
    for item, value in trader.get_portfolio_items().items():
        if(value.get_shares() < 0):
            total_unrealized_short_pnl += trader.get_unrealized_pl(item)

    return total_unrealized_short_pnl
def get_unrealized_pnl(trader: shift.Trader):
    short_profit = 0
    long_profit = 0
    for item, value in ziplist(trader.get_portfolio_items().keys(),
                               trader.get_portfolio_items().values()):
        pnl = trader.get_unrealized_pl(item)
        #in short
        if value.get_shares() < 0:
            short_profit += pnl
        if value.get_shares() > 0:
            long_profit += pnl

    return short_profit, long_profit
Exemplo n.º 3
0
def print_portfolio_information(trader: shift.Trader):
    """
    This method provides information on the structure of PortfolioSummary and PortfolioItem objects:
     get_portfolio_summary() returns a PortfolioSummary object with the following data:
     1. Total Buying Power (get_total_bp())
     2. Total Shares (get_total_shares())
     3. Total Realized Profit/Loss (get_total_realized_pl())
     4. Timestamp of Last Update (get_timestamp())

     get_portfolio_items() returns a dictionary with "symbol" as keys and PortfolioItem as values,
     with each providing the following information:
     1. Symbol (get_symbol())
     2. Shares (get_shares())
     3. Price (get_price())
     4. Realized Profit/Loss (get_realized_pl())
     5. Timestamp of Last Update (get_timestamp())
    :param trader:
    :return:
    """

    print("Buying Power\tTotal Shares\tTotal P&L\tTimestamp")
    print("%12.2f\t%12d\t%9.2f\t%26s" % (
        trader.get_portfolio_summary().get_total_bp(),
        trader.get_portfolio_summary().get_total_shares(),
        trader.get_portfolio_summary().get_total_realized_pl(),
        trader.get_portfolio_summary().get_timestamp(),
    ))

    upl = {}
    for item in list(trader.get_portfolio_items().keys()):
        upl[item] = trader.get_unrealized_pl(item)

    print("Symbol\t\tShares\t\tPrice\t\t  P&L\t\t Unrealized P&L \nTimestamp")
    for item in trader.get_portfolio_items().values():
        print("%6s\t\t%6d\t%9.2f\t%9.2f\t%26s" % (
            item.get_symbol(),
            item.get_shares(),
            item.get_price(),
            item.get_realized_pl(),
            item.get_timestamp(),
        ))
    print("UNREALIZED PNL")
    print(upl)
    return