Optimize GainLossController
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user