private IEnumerable <AssetHistStatJs> GetLookbackStat(string p_lookbackStr) { List <Asset> allAssets = m_marketSummaryAssets.ToList(); // duplicate the asset pointers. Don't add navAsset to m_marketSummaryAssets if (m_mkthSelectedNavAsset != null) { allAssets.Add(m_mkthSelectedNavAsset); } DateTime todayET = Utils.ConvertTimeFromUtcToEt(DateTime.UtcNow).Date; // the default is YTD. Leave it as it is used frequently: by default server sends this to client at Open. Or at EvMemDbHistoricalDataReloaded_mktHealth() DateOnly lookbackStart = new DateOnly(todayET.Year - 1, 12, 31); // YTD relative to 31st December, last year DateOnly lookbackEnd = todayET.AddDays(-1); if (p_lookbackStr.StartsWith("Date:")) // Browser client never send anything, but "Date:" inputs. Format: "Date:2019-11-11...2020-11-10" { lookbackStart = Utils.FastParseYYYYMMDD(new StringSegment(p_lookbackStr, "Date:".Length, 10)); lookbackEnd = Utils.FastParseYYYYMMDD(new StringSegment(p_lookbackStr, "Date:".Length + 13, 10)); } // else if (p_lookbackStr.EndsWith("y")) // { // if (Int32.TryParse(p_lookbackStr.Substring(0, p_lookbackStr.Length - 1), out int nYears)) // lookbackStart = todayET.AddYears(-1 * nYears); // } // else if (p_lookbackStr.EndsWith("m")) // { // if (Int32.TryParse(p_lookbackStr.Substring(0, p_lookbackStr.Length - 1), out int nMonths)) // lookbackStart = todayET.AddMonths(-1 * nMonths); // } // else if (p_lookbackStr.EndsWith("w")) // { // if (Int32.TryParse(p_lookbackStr.Substring(0, p_lookbackStr.Length - 1), out int nWeeks)) // lookbackStart = todayET.AddDays(-7 * nWeeks); // } IEnumerable <AssetHist> assetHists = MemDb.gMemDb.GetSdaHistCloses(allAssets, lookbackStart, lookbackEnd, false, true); IEnumerable <AssetHistStatJs> lookbackStatToClient = assetHists.Select(r => { var rtStock = new AssetHistStatJs() { AssetId = r.Asset.AssetId, SqTicker = r.Asset.SqTicker, PeriodStartDate = r.PeriodStartDate, // it may be not the 'asked' start date if asset has less price history PeriodEndDate = r.PeriodEndDate, // by default it is the date of yesterday, but the user can change it PeriodStart = r.Stat?.PeriodStart ?? Double.NaN, PeriodEnd = r.Stat?.PeriodEnd ?? Double.NaN, PeriodHigh = r.Stat?.PeriodHigh ?? Double.NaN, PeriodLow = r.Stat?.PeriodLow ?? Double.NaN, PeriodMaxDD = r.Stat?.PeriodMaxDD ?? Double.NaN, PeriodMaxDU = r.Stat?.PeriodMaxDU ?? Double.NaN }; return(rtStock); }); return(lookbackStatToClient); }
private IEnumerable <AssetHistJs>?GetBrAccViewerHist(string p_lookbackStr) { if (m_braccSelectedNavAsset == null) { return(null); } List <Asset> assets = new List <Asset>(); assets.Add(m_braccSelectedNavAsset); assets.Add(MemDb.gMemDb.AssetsCache.GetAsset("S/SPY")); // add it to BrokerNav for benchmark for the chart DateTime todayET = Utils.ConvertTimeFromUtcToEt(DateTime.UtcNow).Date; // the default is YTD. Leave it as it is used frequently: by default server sends this to client at Open. Or at EvMemDbHistoricalDataReloaded_mktHealth() DateOnly lookbackStart = new DateOnly(todayET.Year - 1, 12, 31); // YTD relative to 31st December, last year DateOnly lookbackEnd = todayET.AddDays(-1); if (p_lookbackStr.StartsWith("Date:")) // Browser client never send anything, but "Date:" inputs. Format: "Date:2019-11-11...2020-11-10" { lookbackStart = Utils.FastParseYYYYMMDD(new StringSegment(p_lookbackStr, "Date:".Length, 10)); lookbackEnd = Utils.FastParseYYYYMMDD(new StringSegment(p_lookbackStr, "Date:".Length + 13, 10)); } IEnumerable <AssetHist> assetHists = MemDb.gMemDb.GetSdaHistCloses(assets, lookbackStart, lookbackEnd, true, true); IEnumerable <AssetHistJs> histToClient = assetHists.Select(r => { var histStat = new AssetHistStatJs() { AssetId = r.Asset.AssetId, SqTicker = r.Asset.SqTicker, PeriodStartDate = r.PeriodStartDate, // it may be not the 'asked' start date if asset has less price history PeriodEndDate = r.PeriodEndDate, // by default it is the date of yesterday, but the user can change it PeriodStart = r.Stat?.PeriodStart ?? Double.NaN, PeriodEnd = r.Stat?.PeriodEnd ?? Double.NaN, PeriodHigh = r.Stat?.PeriodHigh ?? Double.NaN, PeriodLow = r.Stat?.PeriodLow ?? Double.NaN, PeriodMaxDD = r.Stat?.PeriodMaxDD ?? Double.NaN, PeriodMaxDU = r.Stat?.PeriodMaxDU ?? Double.NaN }; var dates = r.Values !.Select(k => ((DateTime)k.Date).ToYYYYMMDD()).ToList(); var values = r.Values !.Select(k => k.SdaValue).ToList(); var histValues = new AssetHistValuesJs() { AssetId = r.Asset.AssetId, SqTicker = r.Asset.SqTicker, PeriodStartDate = r.PeriodStartDate, PeriodEndDate = r.PeriodEndDate, HistDates = dates, HistSdaCloses = values }; return(new AssetHistJs() { HistValues = histValues, HistStat = histStat }); }); return(histToClient); }