Init
This commit is contained in:
35
MarketDataLib/MarketDataModel/GainLoss/DMAValue.cs
Normal file
35
MarketDataLib/MarketDataModel/GainLoss/DMAValue.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
|
||||
namespace MarketData.MarketDataModel.GainLoss
|
||||
{
|
||||
public class DMAValue
|
||||
{
|
||||
private DateTime date;
|
||||
private double value;
|
||||
private double maValue;
|
||||
|
||||
public DMAValue()
|
||||
{
|
||||
}
|
||||
public DMAValue(DateTime date, double value)
|
||||
{
|
||||
this.date = date;
|
||||
this.value = value;
|
||||
}
|
||||
public DateTime Date
|
||||
{
|
||||
get { return date; }
|
||||
set { date = value; }
|
||||
}
|
||||
public double Value
|
||||
{
|
||||
get { return value; }
|
||||
set { this.value = value; }
|
||||
}
|
||||
public double MAValue
|
||||
{
|
||||
get { return maValue; }
|
||||
set { this.maValue = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
21
MarketDataLib/MarketDataModel/GainLoss/DMAValues.cs
Normal file
21
MarketDataLib/MarketDataModel/GainLoss/DMAValues.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MarketData.MarketDataModel.GainLoss
|
||||
{
|
||||
public class DMAValues : List<DMAValue>
|
||||
{
|
||||
public DMAValues()
|
||||
{
|
||||
}
|
||||
public float[] GetValues(int startIndex, int count)
|
||||
{
|
||||
if (startIndex + count > Count) return null;
|
||||
float[] valuesArray = new float[count];
|
||||
for (int index = startIndex, arrayIndex = 0; index < startIndex + count; index++, arrayIndex++)
|
||||
{
|
||||
valuesArray[arrayIndex] = (float)this[index].Value;
|
||||
}
|
||||
return valuesArray;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
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,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
114
MarketDataLib/MarketDataModel/GainLoss/GainLossItem.cs
Normal file
114
MarketDataLib/MarketDataModel/GainLoss/GainLossItem.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MarketData.Utils;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
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)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
49
MarketDataLib/MarketDataModel/GainLoss/TotalGainLossItem.cs
Normal file
49
MarketDataLib/MarketDataModel/GainLoss/TotalGainLossItem.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
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(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