Optimize GainLossController

This commit is contained in:
2025-04-29 23:13:41 -04:00
parent a65583955a
commit eff2a7a953
4 changed files with 149 additions and 17 deletions

View File

@@ -17,6 +17,37 @@ namespace MarketData.Generator
private ParityGenerator()
{
}
/// <summary>
/// Given PortfolioTrades for a symbol and corresponding latestPrice gives us the breakeven element.
/// This call avoid calling the database. Used by GetGainLossWithDetailByDate in the GainLossController
/// </summary>
/// <param name="symbolTrades"></param>
/// <param name="latestPrice"></param>
/// <returns></returns>
public static ParityElement GenerateBreakEven(PortfolioTrades symbolTrades,Price latestPrice)
{
try
{
ParityElement parityElement=new ParityElement();
Price zeroPrice=null;
if(null==symbolTrades||0==symbolTrades.Count)return null;
PortfolioTrades openTrades=symbolTrades.GetOpenTrades();
GainLossGenerator gainLossGenerator=new GainLossGenerator();
zeroPrice=ParityGenerator.GenerateGainLossValue(openTrades,latestPrice);
parityElement.ParityOffsetPrice=zeroPrice.Close;
parityElement.ParityOffsetPercent=((latestPrice.Close-zeroPrice.Close)/zeroPrice.Close);
parityElement.Symbol=latestPrice.Symbol;
parityElement.PricingDate=latestPrice.Date;
return parityElement;
}
catch(Exception exception)
{
MDTrace.WriteLine(LogLevel.DEBUG,String.Format("{0}",exception));
return null;
}
}
public static ParityElement GenerateBreakEven(String symbol)
{
try