Initial Commit
This commit is contained in:
27
MarketData/MarketDataLib/MarketDataModel/GainLoss/GainLossCompoundModel.cs
Executable file
27
MarketData/MarketDataLib/MarketDataModel/GainLoss/GainLossCompoundModel.cs
Executable file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using MarketData.Utils;
|
||||
using System.Collections.ObjectModel;
|
||||
using MarketData.Generator.GainLoss;
|
||||
using MarketData.DataAccess;
|
||||
|
||||
namespace MarketData.MarketDataModel.GainLoss
|
||||
{
|
||||
// **************************************************************************************************************************************************************
|
||||
// *********************************************** G A I N / L O S S C O M P O U N D M O D E L ****************************************
|
||||
// **************************************************************************************************************************************************************
|
||||
// This GainLossModel will be used to model the GainLossView in terms of surfacing the Active Gain/Loss, Active Exposure, Active Gain/Loss%, Total Gain/Loss, Total Gain/Loss % data
|
||||
public class GainLossCompoundModel
|
||||
{
|
||||
public DateTime Date{get;set;}
|
||||
public double ActiveExposure{get;set;}
|
||||
public double ActiveGainLoss{get;set;}
|
||||
public double ActiveGainLossPercent{get;set;}
|
||||
public double TotalGainLoss{get;set;}
|
||||
public double TotalGainLossPercent{get;set;}
|
||||
public double TotalDividendsPaid{get;set;}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using MarketData.Utils;
|
||||
using System.Collections.ObjectModel;
|
||||
using MarketData.Generator.GainLoss;
|
||||
using MarketData.DataAccess;
|
||||
|
||||
namespace MarketData.MarketDataModel.GainLoss
|
||||
{
|
||||
// The GainLossCompoundModelCollection contains both the active gain loss and the total gain loss time series data
|
||||
public class GainLossCompoundModelCollection : List<GainLossCompoundModel>
|
||||
{
|
||||
public GainLossCompoundModelCollection()
|
||||
{
|
||||
}
|
||||
public GainLossCompoundModelCollection(List<GainLossCompoundModel> items)
|
||||
{
|
||||
foreach(GainLossCompoundModel item in items)Add(item);
|
||||
}
|
||||
public GainLossCompoundModelCollection(GainLossCollection activeGainLossCollection,TotalGainLossCollection totalGainLossCollection)
|
||||
{
|
||||
if(null==activeGainLossCollection||null==totalGainLossCollection)return;
|
||||
Dictionary<DateTime,GainLossItem> activeGainLossCollectionByDate=new Dictionary<DateTime,GainLossItem>();
|
||||
Dictionary<DateTime,TotalGainLossItem> totalGainLossCollectionByDate=new Dictionary<DateTime,TotalGainLossItem>();
|
||||
foreach(GainLossItem gainLossItem in activeGainLossCollection)if(!activeGainLossCollectionByDate.ContainsKey(gainLossItem.Date))activeGainLossCollectionByDate.Add(gainLossItem.Date,gainLossItem);
|
||||
foreach(TotalGainLossItem gainLossItem in totalGainLossCollection)if(!totalGainLossCollectionByDate.ContainsKey(gainLossItem.Date))totalGainLossCollectionByDate.Add(gainLossItem.Date,gainLossItem);
|
||||
List<DateTime> dates=new List<DateTime>(activeGainLossCollectionByDate.Keys);
|
||||
dates.Sort();
|
||||
foreach(DateTime date in dates)
|
||||
{
|
||||
GainLossItem activeGainLossItem=activeGainLossCollectionByDate[date];
|
||||
if(!totalGainLossCollectionByDate.ContainsKey(date))continue;
|
||||
TotalGainLossItem totalGainLossItem=totalGainLossCollectionByDate[date];
|
||||
GainLossCompoundModel gainLossModel=new GainLossCompoundModel();
|
||||
gainLossModel.Date=activeGainLossItem.Date;
|
||||
gainLossModel.ActiveExposure=activeGainLossItem.Exposure;
|
||||
gainLossModel.ActiveGainLoss=activeGainLossItem.GainLoss;
|
||||
gainLossModel.ActiveGainLossPercent=activeGainLossItem.GainLossPercent;
|
||||
gainLossModel.TotalGainLoss=totalGainLossItem.TotalGainLoss;
|
||||
gainLossModel.TotalGainLossPercent=totalGainLossItem.TotalGainLossPercent;
|
||||
gainLossModel.TotalDividendsPaid=totalGainLossItem.TotalDividendsPaid;
|
||||
Add(gainLossModel);
|
||||
}
|
||||
}
|
||||
public DMAValues DMAValuesActiveGainLoss
|
||||
{
|
||||
get
|
||||
{
|
||||
DMAValues dmaValues = new DMAValues();
|
||||
foreach (GainLossCompoundModel gainLoss in this)
|
||||
{
|
||||
dmaValues.Add(new DMAValue(gainLoss.Date,gainLoss.ActiveGainLoss));
|
||||
}
|
||||
return dmaValues;
|
||||
}
|
||||
}
|
||||
public DMAValues DMAValuesTotalGainLoss
|
||||
{
|
||||
get
|
||||
{
|
||||
DMAValues dmaValues = new DMAValues();
|
||||
foreach (GainLossCompoundModel gainLoss in this)
|
||||
{
|
||||
dmaValues.Add(new DMAValue(gainLoss.Date,gainLoss.TotalGainLoss));
|
||||
}
|
||||
return dmaValues;
|
||||
}
|
||||
}
|
||||
public DMAValues DMAValuesActiveGainLossPercent
|
||||
{
|
||||
get
|
||||
{
|
||||
DMAValues dmaValues = new DMAValues();
|
||||
foreach (GainLossCompoundModel gainLoss in this)
|
||||
{
|
||||
dmaValues.Add(new DMAValue(gainLoss.Date,gainLoss.ActiveGainLossPercent));
|
||||
}
|
||||
return dmaValues;
|
||||
}
|
||||
}
|
||||
public DMAValues DMAValuesTotalGainLossPercent
|
||||
{
|
||||
get
|
||||
{
|
||||
DMAValues dmaValues = new DMAValues();
|
||||
foreach (GainLossCompoundModel gainLoss in this)
|
||||
{
|
||||
dmaValues.Add(new DMAValue(gainLoss.Date,gainLoss.TotalGainLossPercent));
|
||||
}
|
||||
return dmaValues;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
142
MarketData/MarketDataLib/MarketDataModel/GainLoss/GainLossItem.cs
Executable file
142
MarketData/MarketDataLib/MarketDataModel/GainLoss/GainLossItem.cs
Executable file
@@ -0,0 +1,142 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using MarketData.Utils;
|
||||
using System.Collections.ObjectModel;
|
||||
using MarketData.Generator.GainLoss;
|
||||
using MarketData.DataAccess;
|
||||
|
||||
namespace MarketData.MarketDataModel.GainLoss
|
||||
{
|
||||
// *********************************************************************************************************************************************************************
|
||||
// ************************************************************************ G A I N L O S S **************************************************************************
|
||||
// *********************************************************************************************************************************************************************
|
||||
// This gain loss provides a picture of the Active Gain/Loss. The gain loss on open positions
|
||||
public class GainLossItem : IComparable
|
||||
{
|
||||
private DateTime date;
|
||||
private double gainLoss;
|
||||
private double gainLossPercent;
|
||||
private double exposure;
|
||||
private double dividends;
|
||||
private bool valueIsPercent;
|
||||
public GainLossItem()
|
||||
{
|
||||
}
|
||||
public GainLossItem(DateTime date, double gainLoss,double exposure,bool valueIsPercent)
|
||||
{
|
||||
this.date = date;
|
||||
this.gainLoss = gainLoss;
|
||||
this.exposure = exposure;
|
||||
this.valueIsPercent = valueIsPercent;
|
||||
}
|
||||
public GainLossItem(DateTime date, double gainLoss,double gainLossPercent,double exposure,bool valueIsPercent)
|
||||
{
|
||||
this.date = date;
|
||||
this.gainLoss = gainLoss;
|
||||
this.gainLossPercent=gainLossPercent;
|
||||
this.exposure = exposure;
|
||||
this.valueIsPercent = valueIsPercent;
|
||||
}
|
||||
public GainLossItem(DateTime date, double gainLoss,double gainLossPercent,double exposure,double dividends,bool valueIsPercent)
|
||||
{
|
||||
this.date = date;
|
||||
this.gainLoss = gainLoss;
|
||||
this.gainLossPercent=gainLossPercent;
|
||||
this.exposure = exposure;
|
||||
this.dividends=dividends;
|
||||
this.valueIsPercent = valueIsPercent;
|
||||
}
|
||||
public DateTime Date
|
||||
{
|
||||
get { return date; }
|
||||
}
|
||||
public double Exposure
|
||||
{
|
||||
get
|
||||
{
|
||||
return exposure;
|
||||
}
|
||||
}
|
||||
public double GainLoss
|
||||
{
|
||||
get { return gainLoss; }
|
||||
}
|
||||
public double Dividends
|
||||
{
|
||||
get{return dividends;}
|
||||
}
|
||||
public double GainLossPercent
|
||||
{
|
||||
get { return gainLossPercent; }
|
||||
}
|
||||
public bool ValueIsPercent
|
||||
{
|
||||
get
|
||||
{
|
||||
return valueIsPercent;
|
||||
}
|
||||
set
|
||||
{
|
||||
valueIsPercent = value;
|
||||
}
|
||||
}
|
||||
public String FormattedGainLoss
|
||||
{
|
||||
get
|
||||
{
|
||||
if (valueIsPercent) return Utility.FormatNumber(gainLoss);
|
||||
return Utility.FormatCurrency(gainLoss);
|
||||
}
|
||||
}
|
||||
public int CompareTo(Object obj)
|
||||
{
|
||||
if (!obj.GetType().IsInstanceOfType(this)) throw new Exception("Expected GainLoss");
|
||||
GainLossItem that = (GainLossItem)obj;
|
||||
return date.CompareTo(that.Date);
|
||||
}
|
||||
}
|
||||
public class GainLossCollection : List<GainLossItem>
|
||||
{
|
||||
public GainLossCollection(ICollection<GainLossItem> gainLoss)
|
||||
: base(gainLoss)
|
||||
{
|
||||
}
|
||||
public DMAValues DMAValues
|
||||
{
|
||||
get
|
||||
{
|
||||
DMAValues dmaValues = new DMAValues();
|
||||
foreach (GainLossItem gainLoss in this)
|
||||
{
|
||||
dmaValues.Add(new DMAValue(gainLoss.Date,gainLoss.GainLoss));
|
||||
}
|
||||
return dmaValues;
|
||||
}
|
||||
}
|
||||
public void WriteToDisk(String strPathFileName)
|
||||
{
|
||||
FileStream outStream=new FileStream(strPathFileName,FileMode.Create);
|
||||
StreamWriter streamWriter=new StreamWriter(outStream);
|
||||
streamWriter.WriteLine("Date,GainLoss,GainLossPercent,Exposure,Dividends,ValueIsPercent");
|
||||
foreach(GainLossItem item in this)
|
||||
{
|
||||
StringBuilder sb=new StringBuilder();
|
||||
sb.Append(item.Date.ToShortDateString()).Append(",");
|
||||
sb.Append(item.GainLoss).Append(",");
|
||||
sb.Append(item.GainLossPercent).Append(",");
|
||||
sb.Append(item.Exposure).Append(",");
|
||||
sb.Append(item.Dividends).Append(",");
|
||||
sb.Append(item.ValueIsPercent);
|
||||
streamWriter.WriteLine(sb.ToString());
|
||||
}
|
||||
streamWriter.Flush();
|
||||
streamWriter.Close();
|
||||
streamWriter.Dispose();
|
||||
outStream.Close();
|
||||
outStream.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
27
MarketData/MarketDataLib/MarketDataModel/GainLoss/GainLossSummaryItem.cs
Executable file
27
MarketData/MarketDataLib/MarketDataModel/GainLoss/GainLossSummaryItem.cs
Executable file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using MarketData.Utils;
|
||||
using System.Collections.ObjectModel;
|
||||
using MarketData.Generator.GainLoss;
|
||||
using MarketData.DataAccess;
|
||||
|
||||
namespace MarketData.MarketDataModel.GainLoss
|
||||
{
|
||||
public class GainLossSummaryItem
|
||||
{
|
||||
public GainLossSummaryItem()
|
||||
{
|
||||
}
|
||||
public DateTime Date { get; set; }
|
||||
public String Symbol { get; set; }
|
||||
public String CompanyName { get; set; }
|
||||
public double CurrentGainLoss { get; set; }
|
||||
public double PreviousGainLoss { get; set; }
|
||||
public double Change { get; set; }
|
||||
public double ChangePercent { get; set; }
|
||||
public bool HasStopLimit{get;set;}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using MarketData.Utils;
|
||||
using System.Collections.ObjectModel;
|
||||
using MarketData.Generator.GainLoss;
|
||||
using MarketData.DataAccess;
|
||||
|
||||
// The summary item collection is the data behind the views right-hand grid. This view shows the gain/loss for the date that is selected in the compound model
|
||||
|
||||
namespace MarketData.MarketDataModel.GainLoss
|
||||
{
|
||||
public class GainLossSummaryItemCollection:List<GainLossSummaryItem>
|
||||
{
|
||||
public GainLossSummaryItemCollection()
|
||||
{
|
||||
}
|
||||
public GainLossSummaryItemCollection(PortfolioTrades portfolioTrades,ITotalGainLossGenerator gainLossGenerator,IActiveGainLossGenerator activeGainLossGenerator,DateTime? maxDateRef=null)
|
||||
{
|
||||
List<String> symbols=portfolioTrades.Symbols;
|
||||
|
||||
if(null==gainLossGenerator || null==activeGainLossGenerator)return;
|
||||
|
||||
foreach(String symbol in symbols)
|
||||
{
|
||||
PortfolioTrades portfolioTradesSymbol=portfolioTrades.FilterSymbol(symbol);
|
||||
GainLossCollection gainLossCollection=activeGainLossGenerator.GenerateGainLoss(portfolioTradesSymbol,maxDateRef);
|
||||
|
||||
TotalGainLossCollection totalGainLossCollection=gainLossGenerator.GenerateTotalGainLoss(portfolioTradesSymbol,maxDateRef);
|
||||
GainLossCompoundModelCollection gainLossCompoundModelCollection=new GainLossCompoundModelCollection(gainLossCollection,totalGainLossCollection);
|
||||
|
||||
if(1>gainLossCompoundModelCollection.Count) continue;
|
||||
GainLossSummaryItem gainLossSummaryItem=new GainLossSummaryItem();
|
||||
gainLossSummaryItem.Date=gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-1].Date;
|
||||
gainLossSummaryItem.Symbol=symbol;
|
||||
gainLossSummaryItem.CompanyName=PricingDA.GetNameForSymbol(symbol);
|
||||
gainLossSummaryItem.CurrentGainLoss=gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-1].ActiveGainLoss;
|
||||
double previousGainLoss=1==gainLossCompoundModelCollection.Count?0.00:gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-2].ActiveGainLoss;
|
||||
gainLossSummaryItem.PreviousGainLoss=previousGainLoss;
|
||||
gainLossSummaryItem.Change=gainLossSummaryItem.CurrentGainLoss-gainLossSummaryItem.PreviousGainLoss;
|
||||
if(1==gainLossCollection.Count) gainLossSummaryItem.ChangePercent=0.00;
|
||||
else
|
||||
{
|
||||
double currentMarketValue=gainLossCollection[gainLossCollection.Count-1].Exposure+gainLossCollection[gainLossCollection.Count-1].GainLoss;
|
||||
double previousMarketValue=gainLossCollection[gainLossCollection.Count-2].Exposure+gainLossCollection[gainLossCollection.Count-2].GainLoss;
|
||||
if(0.00==previousMarketValue) gainLossSummaryItem.ChangePercent=0.00;
|
||||
else gainLossSummaryItem.ChangePercent=((currentMarketValue-previousMarketValue)/previousMarketValue)*100;
|
||||
if(gainLossSummaryItem.CurrentGainLoss<0&&gainLossSummaryItem.PreviousGainLoss<0)
|
||||
{ // if current gainloss is negative and previous gainloss is negative then show change percent as a further dip into negative (i.e.) make sure sign is negative
|
||||
if(Math.Abs(gainLossSummaryItem.CurrentGainLoss)>Math.Abs(gainLossSummaryItem.PreviousGainLoss)) gainLossSummaryItem.ChangePercent=Math.Abs(gainLossSummaryItem.ChangePercent)*-1.00;
|
||||
}
|
||||
else if(gainLossSummaryItem.CurrentGainLoss<0&&gainLossSummaryItem.PreviousGainLoss>0)
|
||||
{
|
||||
gainLossSummaryItem.ChangePercent=Math.Abs(gainLossSummaryItem.ChangePercent)*-1.00;
|
||||
}
|
||||
else if(gainLossSummaryItem.CurrentGainLoss>0&&gainLossSummaryItem.PreviousGainLoss>0)
|
||||
{
|
||||
if(gainLossSummaryItem.CurrentGainLoss<gainLossSummaryItem.PreviousGainLoss) gainLossSummaryItem.ChangePercent=Math.Abs(gainLossSummaryItem.ChangePercent)*-1.00;
|
||||
}
|
||||
}
|
||||
// here we need to check maxDateRef for null and then call appropriate HasOpenPositions() / HasOpenPositionsOn(date) method
|
||||
if(null!=maxDateRef)
|
||||
{
|
||||
if(!portfolioTrades.HasOpenPositionsOn(symbol,maxDateRef.Value)) continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!portfolioTrades.HasOpenPositions(symbol)) continue;
|
||||
}
|
||||
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());
|
||||
Clear();
|
||||
AddRange(gainLossSummaryCollection);
|
||||
}
|
||||
public GainLossSummaryItemCollection(PortfolioTrades portfolioTrades,DateTime? maxDateRef=null)
|
||||
{
|
||||
List<String> symbols=portfolioTrades.Symbols;
|
||||
foreach(String symbol in symbols)
|
||||
{
|
||||
PortfolioTrades portfolioTradesSymbol=portfolioTrades.FilterSymbol(symbol);
|
||||
ITotalGainLossGenerator gainLossGenerator=new GainLossGenerator();
|
||||
IActiveGainLossGenerator activeGainLossGenerator=new ActiveGainLossGenerator();
|
||||
GainLossCollection gainLossCollection=activeGainLossGenerator.GenerateGainLoss(portfolioTradesSymbol,maxDateRef);
|
||||
TotalGainLossCollection totalGainLossCollection=gainLossGenerator.GenerateTotalGainLoss(portfolioTradesSymbol,maxDateRef);
|
||||
GainLossCompoundModelCollection gainLossCompoundModelCollection=new GainLossCompoundModelCollection(gainLossCollection,totalGainLossCollection);
|
||||
if(1>gainLossCompoundModelCollection.Count) continue;
|
||||
GainLossSummaryItem gainLossSummaryItem=new GainLossSummaryItem();
|
||||
gainLossSummaryItem.Date=gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-1].Date;
|
||||
gainLossSummaryItem.Symbol=symbol;
|
||||
gainLossSummaryItem.CompanyName=PricingDA.GetNameForSymbol(symbol);
|
||||
gainLossSummaryItem.CurrentGainLoss=gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-1].ActiveGainLoss;
|
||||
double previousGainLoss=1==gainLossCompoundModelCollection.Count?0.00:gainLossCompoundModelCollection[gainLossCompoundModelCollection.Count-2].ActiveGainLoss;
|
||||
gainLossSummaryItem.PreviousGainLoss=previousGainLoss;
|
||||
gainLossSummaryItem.Change=gainLossSummaryItem.CurrentGainLoss-gainLossSummaryItem.PreviousGainLoss;
|
||||
if(1==gainLossCollection.Count) gainLossSummaryItem.ChangePercent=0.00;
|
||||
else
|
||||
{
|
||||
double currentMarketValue=gainLossCollection[gainLossCollection.Count-1].Exposure+gainLossCollection[gainLossCollection.Count-1].GainLoss;
|
||||
double previousMarketValue=gainLossCollection[gainLossCollection.Count-2].Exposure+gainLossCollection[gainLossCollection.Count-2].GainLoss;
|
||||
if(0.00==previousMarketValue) gainLossSummaryItem.ChangePercent=0.00;
|
||||
else gainLossSummaryItem.ChangePercent=((currentMarketValue-previousMarketValue)/previousMarketValue)*100;
|
||||
if(gainLossSummaryItem.CurrentGainLoss<0&&gainLossSummaryItem.PreviousGainLoss<0)
|
||||
{ // if current gainloss is negative and previous gainloss is negative then show change percent as a further dip into negative (i.e.) make sure sign is negative
|
||||
if(Math.Abs(gainLossSummaryItem.CurrentGainLoss)>Math.Abs(gainLossSummaryItem.PreviousGainLoss)) gainLossSummaryItem.ChangePercent=Math.Abs(gainLossSummaryItem.ChangePercent)*-1.00;
|
||||
}
|
||||
else if(gainLossSummaryItem.CurrentGainLoss<0&&gainLossSummaryItem.PreviousGainLoss>0)
|
||||
{
|
||||
gainLossSummaryItem.ChangePercent=Math.Abs(gainLossSummaryItem.ChangePercent)*-1.00;
|
||||
}
|
||||
else if(gainLossSummaryItem.CurrentGainLoss>0&&gainLossSummaryItem.PreviousGainLoss>0)
|
||||
{
|
||||
if(gainLossSummaryItem.CurrentGainLoss<gainLossSummaryItem.PreviousGainLoss) gainLossSummaryItem.ChangePercent=Math.Abs(gainLossSummaryItem.ChangePercent)*-1.00;
|
||||
}
|
||||
}
|
||||
// here we need to check maxDateRef for null and then call appropriate HasOpenPositions() / HasOpenPositionsOn(date) method
|
||||
if(null!=maxDateRef)
|
||||
{
|
||||
if(!portfolioTrades.HasOpenPositionsOn(symbol,maxDateRef.Value)) continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!portfolioTrades.HasOpenPositions(symbol)) continue;
|
||||
}
|
||||
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());
|
||||
Clear();
|
||||
AddRange(gainLossSummaryCollection);
|
||||
}
|
||||
public GainLossSummaryItemCollection(List<GainLossSummaryItem> gainLossSummaryItemCollection)
|
||||
{
|
||||
foreach(GainLossSummaryItem gainLossSummaryItem in gainLossSummaryItemCollection) Add(gainLossSummaryItem);
|
||||
}
|
||||
public GainLossSummaryItemCollection SortByChange()
|
||||
{
|
||||
GainLossSummaryItemCollection gainLossSummaryCollection=new GainLossSummaryItemCollection((from GainLossSummaryItem gainLossSummaryItem in this orderby gainLossSummaryItem.Date descending,gainLossSummaryItem.Change descending,gainLossSummaryItem.Symbol descending select gainLossSummaryItem).ToList());
|
||||
return gainLossSummaryCollection;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using MarketData.Utils;
|
||||
using System.Collections.ObjectModel;
|
||||
using MarketData.Generator.GainLoss;
|
||||
using MarketData.DataAccess;
|
||||
|
||||
namespace MarketData.MarketDataModel.GainLoss
|
||||
{
|
||||
public class SortGainLossCompoundModelYearDescendingOrder : IComparer<GainLossCompoundModel>
|
||||
{
|
||||
int IComparer<GainLossCompoundModel>.Compare(GainLossCompoundModel gainLossA, GainLossCompoundModel gainLossB)
|
||||
{
|
||||
if (gainLossA.Date < gainLossB.Date) return 1;
|
||||
if (gainLossA.Date > gainLossB.Date) return -1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using MarketData.Utils;
|
||||
using System.Collections.ObjectModel;
|
||||
using MarketData.Generator.GainLoss;
|
||||
using MarketData.DataAccess;
|
||||
|
||||
namespace MarketData.MarketDataModel.GainLoss
|
||||
{
|
||||
public class SortTotalGainLossYearDescendingOrder:IComparer<TotalGainLossItem>
|
||||
{
|
||||
int IComparer<TotalGainLossItem>.Compare(TotalGainLossItem gainLossA,TotalGainLossItem gainLossB)
|
||||
{
|
||||
if(gainLossA.Date<gainLossB.Date) return 1;
|
||||
if(gainLossA.Date>gainLossB.Date) return -1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
23
MarketData/MarketDataLib/MarketDataModel/GainLoss/SortYearDescendingOrder.cs
Executable file
23
MarketData/MarketDataLib/MarketDataModel/GainLoss/SortYearDescendingOrder.cs
Executable file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using MarketData.Utils;
|
||||
using System.Collections.ObjectModel;
|
||||
using MarketData.Generator.GainLoss;
|
||||
using MarketData.DataAccess;
|
||||
|
||||
namespace MarketData.MarketDataModel.GainLoss
|
||||
{
|
||||
public class SortYearDescendingOrder:IComparer<GainLossItem>
|
||||
{
|
||||
int IComparer<GainLossItem>.Compare(GainLossItem gainLossA,GainLossItem gainLossB)
|
||||
{
|
||||
if(gainLossA.Date<gainLossB.Date) return 1;
|
||||
if(gainLossA.Date>gainLossB.Date) return -1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
24
MarketData/MarketDataLib/MarketDataModel/GainLoss/TotalGainLossCollection.cs
Executable file
24
MarketData/MarketDataLib/MarketDataModel/GainLoss/TotalGainLossCollection.cs
Executable file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using MarketData.Utils;
|
||||
using System.Collections.ObjectModel;
|
||||
using MarketData.Generator.GainLoss;
|
||||
using MarketData.DataAccess;
|
||||
|
||||
namespace MarketData.MarketDataModel.GainLoss
|
||||
{
|
||||
// ****************************************************************************************************************************************************
|
||||
// ********************************************************************** T O T A L G A I N L O S S *************************************************
|
||||
// ****************************************************************************************************************************************************
|
||||
// This Gain/Loss provides a picture of the total Gain/Loss. This is Gain/Loss generated by all trades
|
||||
public class TotalGainLossCollection : List<TotalGainLossItem>
|
||||
{
|
||||
public TotalGainLossCollection(ICollection<TotalGainLossItem> gainLoss)
|
||||
: base(gainLoss)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
52
MarketData/MarketDataLib/MarketDataModel/GainLoss/TotalGainLossItem.cs
Executable file
52
MarketData/MarketDataLib/MarketDataModel/GainLoss/TotalGainLossItem.cs
Executable file
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using MarketData.Utils;
|
||||
using System.Collections.ObjectModel;
|
||||
using MarketData.Generator.GainLoss;
|
||||
using MarketData.DataAccess;
|
||||
|
||||
namespace MarketData.MarketDataModel.GainLoss
|
||||
{
|
||||
// ****************************************************************************************************************************************************
|
||||
// ********************************************************************** T O T A L G A I N L O S S *************************************************
|
||||
// ****************************************************************************************************************************************************
|
||||
// This Gain/Loss provides a picture of the total Gain/Loss. This is Gain/Loss generated by all trades
|
||||
public class TotalGainLossItem : IComparable
|
||||
{
|
||||
//public TotalGainLossItem()
|
||||
//{
|
||||
//}
|
||||
public TotalGainLossItem(DateTime date,double totalGainLoss,double totalGainLossPercent,double totalExposure,double totalMarketValue)
|
||||
{
|
||||
Date=date;
|
||||
TotalGainLoss=totalGainLoss;
|
||||
TotalExposure=totalExposure;
|
||||
TotalMarketValue=totalMarketValue;
|
||||
TotalGainLossPercent=totalGainLossPercent;
|
||||
}
|
||||
public TotalGainLossItem(DateTime date,double totalGainLoss,double totalGainLossPercent,double totalExposure,double totalMarketValue,double totalDividendsPaid)
|
||||
{
|
||||
Date=date;
|
||||
TotalGainLoss=totalGainLoss;
|
||||
TotalExposure=totalExposure;
|
||||
TotalMarketValue=totalMarketValue;
|
||||
TotalGainLossPercent=totalGainLossPercent;
|
||||
TotalDividendsPaid=totalDividendsPaid;
|
||||
}
|
||||
public DateTime Date{get;private set;}
|
||||
public double TotalGainLoss{get;private set;}
|
||||
public double TotalGainLossPercent{get;private set;}
|
||||
public double TotalExposure{get;private set;}
|
||||
public double TotalMarketValue{get;private set;}
|
||||
public double TotalDividendsPaid{get;private set;}
|
||||
public int CompareTo(Object obj)
|
||||
{
|
||||
if (!obj.GetType().IsInstanceOfType(this)) throw new Exception("Expected GainLoss");
|
||||
TotalGainLossItem that = (TotalGainLossItem)obj;
|
||||
return Date.CompareTo(that.Date);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user