Example #1
0
        /// <summary>
        /// Kauft ein Wertpapier mit den angegebenen Daten.
        /// </summary>
        /// <param name="strWKN">WKN, bzw. ID</param>
        /// <param name="nQuantity">Stueckzahl</param>
        /// <param name="buyDate">Kaufdatum</param>
        /// <param name="dBuyPrice">Kaufpreis</param>
        public void Buy(string strWKN, int nQuantity, WorkDate buyDate, double dBuyPrice)
        {
            DepotPosition depotposition = null;

            if (m_positions.ContainsKey(strWKN))
            {
                depotposition = m_positions[strWKN];
                int    nNewQuantity = nQuantity + depotposition.Quantity;
                double dNewPrice    = (depotposition.Quantity * depotposition.BuyPrice + nQuantity * dBuyPrice) / nNewQuantity;

                depotposition.Quantity = nNewQuantity;
                depotposition.BuyDate  = buyDate;
                depotposition.BuyPrice = dNewPrice;
            }
            else
            {
                depotposition             = new DepotPosition(strWKN, nQuantity, buyDate, dBuyPrice);
                depotposition.TrailingGap = this.DefaultTrailingGap;
                m_positions.Add(strWKN, depotposition);
            }

            m_dCash -= nQuantity * dBuyPrice * (1.0 + m_dProvisionRate);
            m_nTrades++;
            System.Console.WriteLine("Buy {0}: {1} on {2}", strWKN, nQuantity * dBuyPrice, buyDate);
        }
Example #2
0
        /// <summary>
        /// Verkauft ein Wertpapier mit den angegebenen Daten zum
        /// aktuellen Preis im Depot. Evtl. muss vor dem Verkauf
        /// eine Kursaktualisierung durchgefuehrt werden.
        /// </summary>
        /// <param name="strWKN">WKN, bzw. ID</param>
        /// <param name="nQuantity">Stueckzahl</param>
        /// <param name="sellDate">Verkaufsdatum</param>
        public void Sell(string strWKN, int nQuantity, WorkDate sellDate)
        {
            if (m_positions.ContainsKey(strWKN))
            {
                DepotPosition depotposition = m_positions[strWKN];

                nQuantity = Math.Min(nQuantity, depotposition.Quantity);
                depotposition.Quantity -= nQuantity;
                m_dCash += nQuantity * depotposition.Price * (1.0 - m_dProvisionRate);
                m_nTrades++;

                if (depotposition.Quantity == 0)
                {
                    m_positions.RemoveAt(m_positions.IndexOfKey(strWKN));
                }

                System.Console.WriteLine("Sell {0}: {1} on {2}", depotposition.WKN, nQuantity, sellDate);
            }
        }