Example #1
0
        public TradeTracker(Trade trade, decimal optionsCapitalUsageMultiplier)
        {
            _optionsCapitalUsageMultiplier = optionsCapitalUsageMultiplier;

            Positions = new Dictionary <int, Position>()
            {
                //dummy position used for cash transactions without a related instrument
                { NullInstrumentId, new Position(new Instrument(), _optionsCapitalUsageMultiplier) }
            };
            CurrencyPositions = new Dictionary <int, CurrencyPosition>();

            CumulativeReturns = new SortedList <DateTime, double>();
            CumulativePnL     = new SortedList <DateTime, decimal>();

            Capital = new AllocatedCapital();

            _ordersRemaining           = trade.Orders?.Count ?? 0;
            _cashTransactionsRemaining = trade.CashTransactions?.Count ?? 0;

            Trade = trade;

            _currentEquity = 1;
            _totalPnL      = 0;
            TodaysPnL      = 0;
        }
Example #2
0
        public TradeTracker(Trade trade, decimal optionsCapitalUsageMultiplier)
        {
            _optionsCapitalUsageMultiplier = optionsCapitalUsageMultiplier;

            Positions = new Dictionary<int, Position>()
            {
                //dummy position used for cash transactions without a related instrument
                { NullInstrumentId, new Position(new Instrument(), _optionsCapitalUsageMultiplier)} 
            };
            CurrencyPositions = new Dictionary<int, CurrencyPosition>();

            CumulativeReturns = new SortedList<DateTime, double>();
            CumulativePnL = new SortedList<DateTime, decimal>();

            Capital = new AllocatedCapital();

            _ordersRemaining = trade.Orders == null ? 0 : trade.Orders.Count;
            _cashTransactionsRemaining = trade.CashTransactions == null ? 0 : trade.CashTransactions.Count;

            Trade = trade;

            _currentEquity = 1;
            _totalPnL = 0;
            TodaysPnL = 0;
        }
Example #3
0
        public TradeTracker(Trade trade)
        {
            Positions         = new Dictionary <int, Position>();
            CurrencyPositions = new Dictionary <int, CurrencyPosition>();

            CumulativeReturns = new SortedList <DateTime, double>();
            CumulativePnL     = new SortedList <DateTime, decimal>();

            Capital = new AllocatedCapital();

            _ordersRemaining = trade.Orders == null ? 0 : trade.Orders.Count;

            Trade = trade;

            _currentEquity = 1;
            _totalPnL      = 0;
            TodaysPnL      = 0;
        }
Example #4
0
        public PortfolioTracker(Dictionary <int, TimeSeries> data, Dictionary <int, TimeSeries> fxData, List <Trade> trades, string name)
        {
            _data   = data;
            _fxData = fxData;
            Name    = name;

            Trades = trades;

            TradeTrackers = trades.ToDictionary(t => t.ID, t => new TradeTracker(t));

            ProfitLossEquityCurve      = new EquityCurve(0);
            ProfitLossLongEquityCurve  = new EquityCurve(0);
            ProfitLossShortEquityCurve = new EquityCurve(0);

            RoacEquityCurve = new EquityCurve(1);
            RotcEquityCurve = new EquityCurve(1);

            Capital = new AllocatedCapital();

            Positions = new Dictionary <int, Position>
            {
                //dummy position used for cash transactions without a related instrument
                { NullInstrumentId, new Position(new Instrument()) }
            };

            //group cash transactions by date so they're easily accessible
            _cashTransactionsByDate =
                trades
                .Where(x => x.CashTransactions != null)
                .SelectMany(x => x.CashTransactions)
                .Where(x => x.Type != "Deposits & Withdrawals")
                .GroupBy(x => x.TransactionDate.Date)
                .ToDictionary(x => x.Key, x => x.ToList());

            //group fx transactions
            _fxTransactionsByDate =
                trades
                .Where(x => x.FXTransactions != null)
                .SelectMany(x => x.FXTransactions)
                .GroupBy(x => x.DateTime.Date)
                .ToDictionary(x => x.Key, x => x.ToList());

            _allOrders = Trades.Where(x => x.Orders != null).SelectMany(x => x.Orders).ToList();
        }
Example #5
0
        public PortfolioTracker(Dictionary<int, TimeSeries> data, Dictionary<int, TimeSeries> fxData, List<Trade> trades, string name, DateTime firstDate, decimal optionsCapitalUsageMultiplier)
        {
            _data = data;
            _fxData = fxData;
            Name = name;
            _optionsCapitalUsageMultiplier = optionsCapitalUsageMultiplier;
            Trades = trades;

            TradeTrackers = trades.ToDictionary(t => t.ID, t => new TradeTracker(t, optionsCapitalUsageMultiplier));

            ProfitLossEquityCurve = new EquityCurve(0, firstDate);
            ProfitLossLongEquityCurve = new EquityCurve(0, firstDate);
            ProfitLossShortEquityCurve = new EquityCurve(0, firstDate);

            RoacEquityCurve = new EquityCurve(1, firstDate);
            RotcEquityCurve = new EquityCurve(1, firstDate);

            Capital = new AllocatedCapital();

            Positions = new Dictionary<int, Position>
            {
                //dummy position used for cash transactions without a related instrument
                { NullInstrumentId, new Position(new Instrument(), _optionsCapitalUsageMultiplier)} 
            };

            //group cash transactions by date so they're easily accessible
            _cashTransactionsByDate =
                trades
                .Where(x => x.CashTransactions != null)
                .SelectMany(x => x.CashTransactions)
                .Where(x => x.Type != "Deposits & Withdrawals")
                .GroupBy(x => x.TransactionDate.Date)
                .ToDictionary(x => x.Key, x => x.ToList());

            //group fx transactions
            _fxTransactionsByDate =
                trades
                .Where(x => x.FXTransactions != null)
                .SelectMany(x => x.FXTransactions)
                .GroupBy(x => x.DateTime.Date)
                .ToDictionary(x => x.Key, x => x.ToList());

            _allOrders = Trades.Where(x => x.Orders != null).SelectMany(x => x.Orders).ToList();
        }
Example #6
0
        public Position(Instrument instrument)
        {
            Instrument     = instrument;
            Orders         = new List <Order>();
            _openPositions = new List <Tuple <decimal, int> >();

            Capital = new AllocatedCapital();

            PnLLong  = 0;
            PnLShort = 0;

            RealizedPnLLong  = 0;
            RealizedPnLShort = 0;

            _unrecognizedPnLLong  = 0;
            _unrecognizedPnLShort = 0;

            _priorPeriodQuantity = 0;
            _deferredPnL         = 0;

            ROAC = 1;
        }
Example #7
0
        public Position(Instrument instrument, decimal optionsCapitalUsageMultiplier = 1)
        {
            Instrument = instrument;
            Orders = new List<Order>();
            _openPositions = new List<Tuple<decimal, int>>();

            Capital = new AllocatedCapital();

            PnLLong = 0;
            PnLShort = 0;

            RealizedPnLLong = 0;
            RealizedPnLShort = 0;

            _unrecognizedPnLLong = 0;
            _unrecognizedPnLShort = 0;

            _priorPeriodQuantity = 0;
            _deferredPnL = 0;

            ROAC = 1;
            _optionsCapitalUsageMultiplier = optionsCapitalUsageMultiplier;
        }