Esempio n. 1
0
        internal static void Save(Account account, AccountClass.Instrument instrument, TradeDayCalculator calculator, TradeDayInfo tradeDayInfo, Settings.Instrument settingInstrument)
        {
            InstrumentResetItem resetItem = CreateInstrumentResetItem(tradeDayInfo.TradeDay, instrument, calculator.ResetResults, tradeDayInfo.Settings.BuyPrice, tradeDayInfo.Settings.SellPrice);

            resetItem.ResetBalance = calculator.Balance;
            instrument.AddResetItem(tradeDayInfo.TradeDay, resetItem);
            AddOrderResetToAccount(account, calculator.ResetResults);
            AddResetResultToOrderDayHistory(account, calculator.ResetResults);
        }
Esempio n. 2
0
        private Dictionary <Guid, decimal> GetFloatingPLs(Agent.Account account, DateTime tradeDay)
        {
            Dictionary <Guid, decimal> result = new Dictionary <Guid, decimal>();

            foreach (var eachInstrument in _instrumentManager.Instruments)
            {
                InstrumentResetItem resetItem = eachInstrument.GetResetItem(tradeDay);
                if (resetItem == null)
                {
                    continue;
                }
                var     settingInstrument = Settings.Setting.Default.GetInstrument(eachInstrument.Id, tradeDay);
                decimal lastFloatingPL;
                if (!result.TryGetValue(settingInstrument.CurrencyId, out lastFloatingPL))
                {
                    result.Add(settingInstrument.CurrencyId, resetItem.FloatingPL);
                }
                else
                {
                    result[settingInstrument.CurrencyId] = lastFloatingPL + resetItem.FloatingPL;
                }
            }
            return(result);
        }
Esempio n. 3
0
        private static InstrumentResetItem CreateInstrumentResetItem(DateTime tradeDay, AccountClass.Instrument instrument, Dictionary <Guid, OrderResetResult> resetResultDict, Price buyPrice, Price sellPrice)
        {
            var result = instrument.GetResetItem(tradeDay);

            if (result == null)
            {
                result = new InstrumentResetItem(tradeDay, instrument.Owner.Id, instrument.Id);
            }
            else
            {
                result.Clear();
            }
            foreach (var eachResetResult in resetResultDict.Values)
            {
                result.FloatingPL          += eachResetResult.FloatPL.Interest + eachResetResult.FloatPL.Storage + eachResetResult.TradePLFloat;
                result.Necessary           += eachResetResult.Margin;
                result.InterestPLNotValued += eachResetResult.NotValuedPL.Interest;
                result.StoragePLNotValued  += eachResetResult.NotValuedPL.Storage;
                result.TradePLNotValued    += eachResetResult.TradePLNotValued;
            }
            result.BuyPrice  = buyPrice;
            result.SellPrice = sellPrice;
            return(result);
        }