コード例 #1
0
ファイル: Program.cs プロジェクト: JacqueMartin/PricerAV
        static void Main(string[] args)
        {
            var history = new FundHistory();

            history.LoadFund(@"C:\work\Perso\git\Historical_data\FR0010298596.csv");
            history.LoadFund(@"C:\work\Perso\git\Historical_data\FR0010838284.csv");

            var Investors = new List <FundInvestor>();

            var Investor1 = new FundInvestor(history.Funds.First(), new DateTime(2010, 1, 1));
            var Investor2 = new FundInvestor(history.Funds.Last(), new DateTime(2010, 1, 1));

            Investors.Add(Investor1);
            Investors.Add(Investor2);

            var portofolio = new Portofolio();

            var totalOrder = 0;

            foreach (var investor in Investors)
            {
                while (investor.CurrentDate != new DateTime(2019, 2, 25))
                {
                    var actions = investor.Next();
                    foreach (var action in actions)
                    {
                        if (action.OrderToDo == OrderType.Buy)
                        {
                            var historicalValue = history.ValueAtTime(action.ISIN, action.Date);
                            portofolio.AddAction(action, historicalValue);
                            Console.WriteLine("ISIN: " + action.ISIN + "-> " + action.OrderToDo + " in: " + action.Date + " €: " + historicalValue);
                            totalOrder++;
                        }
                    }
                }
            }

            Console.WriteLine("Number of order summit: " + totalOrder);
            Console.WriteLine("Portofolio value : " + portofolio.PortofolioValue(history, new DateTime(2019, 1, 1)));

            //Console.Write(loader.Funds.Last().ToString());
            Console.ReadLine();
        }
コード例 #2
0
ファイル: Portofolio.cs プロジェクト: JacqueMartin/PricerAV
        public double PortofolioValue(FundHistory history, DateTime dateToEvaluated)
        {
            double value = 0.0;

            foreach (var order in Orders)
            {
                var ticketHistory = history.Funds.Where(x => x.ISIN == order.ISIN).FirstOrDefault();

                if (order.OrderType == OrderType.Buy)
                {
                    value += order.Quantity * ticketHistory.ClosedTickFromDate(dateToEvaluated).Value;
                }

                if (order.OrderType == OrderType.Sell)
                {
                    value -= order.Quantity * ticketHistory.ClosedTickFromDate(dateToEvaluated).Value;
                }
            }
            return(value);
        }