def account(self): ib_account = self._tws.accounts[self.account_id][self.currency] z_account = zp.Account() z_account.settled_cash = float(ib_account['TotalCashValue-S']) z_account.accrued_interest = None # TODO(tibor) z_account.buying_power = float(ib_account['BuyingPower']) z_account.equity_with_loan = float(ib_account['EquityWithLoanValue']) z_account.total_positions_value = float(ib_account['StockMarketValue']) z_account.total_positions_exposure = float( (z_account.total_positions_value / (z_account.total_positions_value + float(ib_account['TotalCashValue'])))) z_account.regt_equity = float(ib_account['RegTEquity']) z_account.regt_margin = float(ib_account['RegTMargin']) z_account.initial_margin_requirement = float( ib_account['FullInitMarginReq']) z_account.maintenance_margin_requirement = float( ib_account['FullMaintMarginReq']) z_account.available_funds = float(ib_account['AvailableFunds']) z_account.excess_liquidity = float(ib_account['ExcessLiquidity']) z_account.cushion = float( self._tws.accounts[self.account_id]['']['Cushion']) z_account.day_trades_remaining = float( self._tws.accounts[self.account_id]['']['DayTradesRemaining']) z_account.leverage = float( self._tws.accounts[self.account_id]['']['Leverage-S']) z_account.net_leverage = (float(ib_account['StockMarketValue']) / (float(ib_account['TotalCashValue']) + float(ib_account['StockMarketValue']))) z_account.net_liquidation = float(ib_account['NetLiquidation']) return z_account
def __init__(self, starting_cash, asset_finder, period_open=None, period_close=None, keep_transactions=True, keep_orders=False, serialize_positions=True): self.asset_finder = asset_finder self.period_open = period_open self.period_close = period_close self.ending_value = 0.0 self.ending_exposure = 0.0 self.period_cash_flow = 0.0 self.pnl = 0.0 self.ending_cash = starting_cash # rollover initializes a number of self's attributes: self.rollover() self.keep_transactions = keep_transactions self.keep_orders = keep_orders # An object to recycle via assigning new values # when returning portfolio information. # So as not to avoid creating a new object for each event self._portfolio_store = zp.Portfolio() self._account_store = zp.Account() self.serialize_positions = serialize_positions # This dict contains the known cash flow multipliers for sids and is # keyed on sid self._execution_cash_flow_multipliers = {}
def __init__(self, starting_cash, period_open=None, period_close=None, keep_transactions=True, keep_orders=False, serialize_positions=True): self.period_open = period_open self.period_close = period_close self.ending_value = 0.0 self.period_cash_flow = 0.0 self.pnl = 0.0 self.ending_cash = starting_cash # rollover initializes a number of self's attributes: self.rollover() self.keep_transactions = keep_transactions self.keep_orders = keep_orders # An object to recycle via assigning new values # when returning portfolio information. # So as not to avoid creating a new object for each event self._portfolio_store = zp.Portfolio() self._account_store = zp.Account() self.serialize_positions = serialize_positions
def account(self): account = self._api.get_account() z_account = zp.Account() z_account.buying_power = float(account.cash) z_account.total_position_value = float( account.portfolio_value) - float(account.cash) return z_account
def account(self): account = self.api_client.Position.Position_get().result() z_account = zp.Account() z_account.buying_power = float(account['cash']) z_account.total_position_value = float( account.portfolio_value) - float(account['cash']) return z_account
def account(self): z_account = protocol.Account() z_account.settled_cash = self.portfolio.cash z_account.accrued_interest = None z_account.buying_power = self.portfolio.portfolio_value z_account.equity_with_loan = self.portfolio.portfolio_value z_account.total_positions_value = self.portfolio.positions_value z_account.total_positions_exposure = z_account.total_positions_value / ( z_account.total_positions_value + z_account.settled_cash) return z_account
def __init__(self, trading_sessions, capital_base, data_frequency): if len(trading_sessions): start = trading_sessions[0] else: start = None # Have some fields of the portfolio changed? This should be accessed # through ``self._dirty_portfolio`` self.__dirty_portfolio = False self._immutable_portfolio = zp.Portfolio(start, capital_base) self._portfolio = zp.MutableView(self._immutable_portfolio) self.daily_returns_series = pd.Series( np.nan, index=trading_sessions, ) # Get a view into the storage of the returns series. Metrics # can access this directly in minute mode for performance reasons. self.daily_returns_array = self.daily_returns_series.values self._previous_total_returns = 0 # this is a component of the cache key for the account self._position_stats = None # Have some fields of the account changed? self._dirty_account = True self._immutable_account = zp.Account() self._account = zp.MutableView(self._immutable_account) # The broker blotter can override some fields on the account. This is # way to tangled up at the moment but we aren't fixing it today. self._account_overrides = {} self.position_tracker = PositionTracker(data_frequency) self._processed_transactions = {} self._orders_by_modified = {} self._orders_by_id = OrderedDict() # Keyed by asset, the previous last sale price of positions with # payouts on price differences, e.g. Futures. # # This dt is not the previous minute to the minute for which the # calculation is done, but the last sale price either before the period # start, or when the price at execution. self._payout_last_sale_prices = {} self.fees = { 'interest': 0., 'manager_fees': 0., }
def __init__( self, starting_cash, asset_finder, data_frequency, period_open=None, period_close=None, keep_transactions=True, keep_orders=False, serialize_positions=True, name=None): self.asset_finder = asset_finder self.data_frequency = data_frequency # Start and end of the entire period self.period_open = period_open self.period_close = period_close self.initialize(starting_cash=starting_cash, starting_value=0.0, starting_exposure=0.0) self.ending_value = 0.0 self.ending_exposure = 0.0 self.ending_cash = starting_cash self.subperiod_divider = None # Keyed by asset, the previous last sale price of positions with # payouts on price differences, e.g. Futures. # # This dt is not the previous minute to the minute for which the # calculation is done, but the last sale price either before the period # start, or when the price at execution. self._payout_last_sale_prices = {} self.keep_transactions = keep_transactions self.keep_orders = keep_orders self.name = name # An object to recycle via assigning new values # when returning portfolio information. # So as not to avoid creating a new object for each event self._portfolio_store = zp.Portfolio() self._account_store = zp.Account() self.serialize_positions = serialize_positions # This dict contains the known cash flow multipliers for sids and is # keyed on sid self._execution_cash_flow_multipliers = {}
def __init__(self, starting_cash, period_open=None, period_close=None, keep_transactions=True, keep_orders=False, serialize_positions=True): self.period_open = period_open self.period_close = period_close self.ending_value = 0.0 self.period_cash_flow = 0.0 self.pnl = 0.0 # sid => position object self.positions = positiondict() self.ending_cash = starting_cash # rollover initializes a number of self's attributes: self.rollover() self.keep_transactions = keep_transactions self.keep_orders = keep_orders # Arrays for quick calculations of positions value self._position_amounts = OrderedDict() self._position_last_sale_prices = OrderedDict() self.calculate_performance() # An object to recycle via assigning new values # when returning portfolio information. # So as not to avoid creating a new object for each event self._portfolio_store = zp.Portfolio() self._account_store = zp.Account() self._positions_store = zp.Positions() self.serialize_positions = serialize_positions self._unpaid_dividends = pd.DataFrame( columns=zp.DIVIDEND_PAYMENT_FIELDS, ) self.loc_map = {}