private void GetSpots(DateTime beginningTest, IDataFeedProvider simulateMarket)
        {//Get all the spots of the underlying asset from the debTest date to the maturity date
            Spots.Clear();
            var firstDateMarket = simulateMarket.GetMinDate();

            if (beginningTest.Date < firstDateMarket.Date)
            {
                throw new Exception("No Market data before the " + firstDateMarket.ToShortDateString());
            }
            if (beginningTest.Date > Option.Maturity.Date)
            {
                throw new Exception("No Market data after the Maturity date (" + Option.Maturity.ToShortDateString() + ")");
            }

            var dataFeed = simulateMarket.GetDataFeed(Option, beginningTest);

            if (dataFeed.Count() == 0)
            {
                throw new Exception("No Market data");
            }
            foreach (DataFeed d in dataFeed)
            {
                var spotList = new List <double>();
                foreach (string shareId in Option.UnderlyingShareIds)
                {
                    spotList.Add((double)d.PriceList[shareId]);
                }
                Spots.Add(spotList.ToArray());
                MarketDataDates.Add(d.Date);
            }
            PayOff = computePayOff();
        }
Exemple #2
0
        async Task ExecuteLoadSpotsCommand()
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;

            try
            {
                Spots.Clear();
                var spots = await App.Database.GetItemsSortedAsync();

                foreach (var spot in spots)
                {
                    Spots.Add(spot);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Exemple #3
0
        public void Dispose()
        {
            Spots.ForEach(s => s.Dispose());
            Spots.Clear();

            Logo?.Dispose();
            Logo = null;

            Parent = null;
        }
Exemple #4
0
        public void RebuildSpots(bool keepExistedData = false)
        {
            if (!Parent.ParentScheduleSettings.FlightDateStart.HasValue || !Parent.ParentScheduleSettings.FlightDateEnd.HasValue)
            {
                return;
            }

            var startDate = Parent.ParentScheduleSettings.FlightDateStart.Value;
            var endDate   = Parent.ParentScheduleSettings.FlightDateEnd.Value;
            var spotDate  = startDate;

            var newSpots = new List <Spot>();

            while (spotDate < endDate)
            {
                var spot = new Spot(this)
                {
                    Date = spotDate
                };
                spotDate = Parent.SpotType == SpotType.Week ? spotDate.AddDays(7) : new DateTime(spotDate.AddMonths(1).Year, spotDate.AddMonths(1).Month, 1);
                newSpots.Add(spot);
            }

            if (!(Spots.Any() && Spots.First().Date == startDate && Spots.Count == newSpots.Count))
            {
                if (keepExistedData)
                {
                    if (Spots.Count >= newSpots.Count)
                    {
                        for (int i = 0; i < newSpots.Count; i++)
                        {
                            newSpots[i].Count = Spots[i].Count;
                        }
                    }
                    else
                    {
                        for (int i = 0; i < Spots.Count; i++)
                        {
                            newSpots[i].Count = Spots[i].Count;
                        }
                    }
                }

                Spots.Clear();
                Spots.AddRange(newSpots);
            }
        }