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

@@ -5,20 +5,14 @@
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"name": ".NET Core Launch (mk)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/net8.0/MarketData.dll",
"program": "${workspaceFolder}/bin/Debug/net8.0/mk.dll",
"args": [],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
}

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

View File

@@ -114,7 +114,6 @@ namespace MarketData.MarketDataModel.GainLoss
GainLossSummaryItem gainLossSummaryItem=new GainLossSummaryItem();
gainLossSummaryItem.Date=gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-1].Date;
gainLossSummaryItem.Symbol=symbol;
// gainLossSummaryItem.CompanyName=PricingDA.GetNameForSymbol(symbol);
gainLossSummaryItem.CompanyName=namesDictionary.ContainsKey(symbol)?namesDictionary[symbol]:"";
gainLossSummaryItem.CurrentGainLoss=gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-1].ActiveGainLoss;
double previousGainLoss=1==gainLossCompoundModelCollection.Count?0.00:gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-2].ActiveGainLoss;
@@ -150,7 +149,6 @@ namespace MarketData.MarketDataModel.GainLoss
if(!portfolioTrades.HasOpenPositions(symbol)) continue;
}
gainLossSummaryItem.HasStopLimit = stopLimits.ContainsKey(symbol);
// gainLossSummaryItem.HasStopLimit=PortfolioDA.HasStopLimit(symbol);
Add(gainLossSummaryItem);
}
GainLossSummaryItemCollection gainLossSummaryCollection=new GainLossSummaryItemCollection((from GainLossSummaryItem gainLossSummaryItem in this orderby gainLossSummaryItem.Date descending,gainLossSummaryItem.Change descending,gainLossSummaryItem.Symbol descending select gainLossSummaryItem).ToList());