Optimize GainLossController
This commit is contained in:
@@ -94,7 +94,6 @@ namespace MarketData.Cache
|
||||
DateTime maxDate=symbolPrices.MaxDate; // get the latest date in the cache
|
||||
if(maxDbDates.ContainsKey(symbol) && !maxDbDates[symbol].Date.Equals(maxDate.Date)) // if the cache date and the database date are not equal then reload the cache
|
||||
{
|
||||
// MDTrace.WriteLine(LogLevel.DEBUG,$"[LocalPriceCache] Cache date and Database date for {symbol} are not equal, reloading cache. Cache Date:{maxDate.ToShortDateString()} Database Date:{maxDbDates[symbol].Date.ToShortDateString()}");
|
||||
Prices prices=PricingDA.GetPrices(symbol,symbolPrices.MinDate); // reload the prices for this symbol using the current minDate in the cache as a lower boundary
|
||||
if(null==prices)continue; // if we can't load any prices for symbol then just continue
|
||||
priceCache.Remove(symbol); // remove the pricing entries in the price cache for the symbol
|
||||
@@ -102,7 +101,6 @@ namespace MarketData.Cache
|
||||
}
|
||||
else
|
||||
{
|
||||
// MDTrace.WriteLine(LogLevel.DEBUG,$"[LocalPriceCache] Fetching latest price from database for {symbol} on {maxDate.ToShortDateString()}");
|
||||
Price price=PricingDA.GetPrice(symbol,maxDate); // the max date from the cache equals the max date from the database so just reload the latest price from the database
|
||||
if(null==price)continue; // if no latest price then just continue
|
||||
symbolPrices.Remove(maxDate); // remove the current price associated with the max date
|
||||
@@ -114,7 +112,7 @@ namespace MarketData.Cache
|
||||
|
||||
// This version of Add(PortfolioTrades) will account for adding multiple lots at different times. So instead of just checking for the existance of the symbol in the cache
|
||||
// we look to see if the symbol is in the cache and what dates are available. If the date range specified in the trade are not available then we load those date ranges.
|
||||
// This is a brute force approach always maintaining the gap between successive TradeDates in th.e portfolio trades and the maximum date for the symbol in the database.
|
||||
// This is a brute force approach always maintaining the gap between successive TradeDates in the portfolio trades and the maximum date for the symbol in the database.
|
||||
// So while it is inefficient in terms of memory usage it alleviates the need for figuring out contiguous price sections
|
||||
public void Add(PortfolioTrades portfolioTrades)
|
||||
{
|
||||
@@ -185,6 +183,7 @@ namespace MarketData.Cache
|
||||
pricesByDate.Add(price.Date,price);
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime GetMinCacheDate(String symbol)
|
||||
{
|
||||
if(!ContainsSymbol(symbol))return Utility.Epoch;
|
||||
@@ -204,6 +203,23 @@ namespace MarketData.Cache
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Prices GetPrices(String symbol,DateTime date,int dayCount)
|
||||
{
|
||||
lock(typeof(LocalPriceCache))
|
||||
{
|
||||
DateGenerator dateGenerator = new DateGenerator();
|
||||
List<DateTime> historicalDates = dateGenerator.GenerateHistoricalDates(date, dayCount);
|
||||
Prices prices = new Prices();
|
||||
foreach(DateTime historicalDate in historicalDates)
|
||||
{
|
||||
Price price = GetPrice(symbol, historicalDate);
|
||||
if(null!=price)prices.Add(price);
|
||||
}
|
||||
return prices;
|
||||
}
|
||||
}
|
||||
|
||||
public Price GetPrice(String symbol,DateTime date)
|
||||
{
|
||||
lock(typeof(LocalPriceCache))
|
||||
@@ -214,6 +230,7 @@ namespace MarketData.Cache
|
||||
return pricesByDate[date];
|
||||
}
|
||||
}
|
||||
|
||||
public bool ContainsPrice(String symbol,DateTime date)
|
||||
{
|
||||
lock(typeof(LocalPriceCache))
|
||||
@@ -224,6 +241,7 @@ namespace MarketData.Cache
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ContainsPrice(List<String> symbols,DateTime date)
|
||||
{
|
||||
lock(typeof(LocalPriceCache))
|
||||
|
||||
Reference in New Issue
Block a user