Initial Commit
This commit is contained in:
24
MarketData/MarketDataLib/Generator/Model/Expectancy.cs
Executable file
24
MarketData/MarketDataLib/Generator/Model/Expectancy.cs
Executable file
@@ -0,0 +1,24 @@
|
||||
using MarketData.DataAccess;
|
||||
using MarketData.MarketDataModel;
|
||||
using MarketData.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MarketData.Generator.Model
|
||||
{
|
||||
public class ModelStatistics
|
||||
{
|
||||
public long TotalTrades{get;set;} // The total number of trades
|
||||
public long WinningTrades{get;set;} // The number of winning trades
|
||||
public long LosingTrades{get;set;} // The number of losing trades
|
||||
public double AverageWinningTradePercentGain{get;set;} // Average percent gain of the winning trades
|
||||
public double AverageLosingTradePercentLoss{get;set;} // Average percent loss of the losing trades
|
||||
public double WinningTradesPercent{get;set;} // Percentage of trades that are winners
|
||||
public double LosingTradesPercent{get;set;} // Percentage of trades that are losers
|
||||
public double Expectancy { get; set; } // The Expectancy. (WinningTradesPercent * AverageWinningTradePercent)/(percent losing trades * average loss) We are looking for a number greater than zero.
|
||||
}
|
||||
}
|
||||
128
MarketData/MarketDataLib/Generator/Model/StopLimits.cs
Executable file
128
MarketData/MarketDataLib/Generator/Model/StopLimits.cs
Executable file
@@ -0,0 +1,128 @@
|
||||
using MarketData.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
/// <summary>
|
||||
/// This StopLimit class is used by models and the UI
|
||||
/// </summary>
|
||||
|
||||
namespace MarketData.Generator.Model
|
||||
{
|
||||
public class StopLimits:List<StopLimit>
|
||||
{
|
||||
public StopLimits()
|
||||
{
|
||||
}
|
||||
public StopLimits(List<StopLimit> stopLimits)
|
||||
{
|
||||
foreach(StopLimit stopLimit in stopLimits)Add(stopLimit);
|
||||
}
|
||||
public NVPCollections ToNVPCollections()
|
||||
{
|
||||
NVPCollections nvpCollections=new NVPCollections();
|
||||
foreach(StopLimit stopLimit in this)
|
||||
{
|
||||
nvpCollections.Add(stopLimit.ToNVPCollection());
|
||||
}
|
||||
return nvpCollections;
|
||||
}
|
||||
public static StopLimits FromNVPCollections(NVPCollections nvpCollections)
|
||||
{
|
||||
StopLimits stopLimits=new StopLimits();
|
||||
foreach(NVPCollection nvpCollection in nvpCollections)
|
||||
{
|
||||
stopLimits.Add(StopLimit.FromNVPCollection(nvpCollection));
|
||||
}
|
||||
return stopLimits;
|
||||
}
|
||||
public void AddFromNVPCollection(NVPCollection nvpCollection)
|
||||
{
|
||||
Add(StopLimit.FromNVPCollection(nvpCollection));
|
||||
}
|
||||
}
|
||||
public class StopLimit
|
||||
{
|
||||
public StopLimit()
|
||||
{
|
||||
}
|
||||
public StopLimit(StopLimit stopLimit)
|
||||
{
|
||||
this.Symbol=stopLimit.Symbol;
|
||||
this.AnalysisDate=stopLimit.AnalysisDate;
|
||||
this.PreviousStop=stopLimit.PreviousStop;
|
||||
this.NewStop=stopLimit.NewStop;
|
||||
this.CurrentPriceLow=stopLimit.CurrentPriceLow;
|
||||
this.CurrentPriceClose=stopLimit.CurrentPriceClose;
|
||||
this.PriceTrendIndicatorSlope=stopLimit.PriceTrendIndicatorSlope;
|
||||
this.StopLimitId=stopLimit.StopLimitId;
|
||||
}
|
||||
public StopLimit(String symbol,DateTime analysisDate,double previousStop,double newStop,double currentPriceLow,double currentPriceClose,double priceTrendIndicatorSlope)
|
||||
{
|
||||
this.Symbol=symbol;
|
||||
this.AnalysisDate=analysisDate;
|
||||
this.PreviousStop=previousStop;
|
||||
this.NewStop=newStop;
|
||||
this.CurrentPriceLow=currentPriceLow;
|
||||
this.CurrentPriceClose=currentPriceClose;
|
||||
this.PriceTrendIndicatorSlope=priceTrendIndicatorSlope;
|
||||
}
|
||||
public String Symbol { get; set; }
|
||||
public DateTime AnalysisDate{get;set;}
|
||||
public double PreviousStop{get;set;}
|
||||
public double NewStop{get;set;}
|
||||
public double CurrentPriceLow{get;set;}
|
||||
public double CurrentPriceClose{get;set;}
|
||||
public double PriceTrendIndicatorSlope{get;set;}
|
||||
public String StopLimitId {get;set;}
|
||||
public static String Header()
|
||||
{
|
||||
StringBuilder sb=new StringBuilder();
|
||||
sb.Append("Id,Symbol,AnalysisDate,PreviousStop,NewStop,CurrentPriceLow,CurrentPriceClose,PriceTrendIndicatorSlope");
|
||||
return sb.ToString();
|
||||
}
|
||||
public override String ToString()
|
||||
{
|
||||
StringBuilder sb=new StringBuilder();
|
||||
sb.Append(null==StopLimitId?"":StopLimitId).Append(",");
|
||||
sb.Append(Symbol).Append(",");
|
||||
sb.Append(AnalysisDate.ToShortDateString()).Append(",");
|
||||
sb.Append(Utility.FormatCurrency(PreviousStop)).Append(",");
|
||||
sb.Append(Utility.FormatCurrency(NewStop)).Append(",");
|
||||
sb.Append(Utility.FormatCurrency(CurrentPriceLow)).Append(",");
|
||||
sb.Append(Utility.FormatCurrency(CurrentPriceClose)).Append(",");
|
||||
sb.Append(Utility.FormatNumber(PriceTrendIndicatorSlope,4,false));
|
||||
return sb.ToString();
|
||||
}
|
||||
public virtual NVPCollection ToNVPCollection()
|
||||
{
|
||||
NVPCollection nvpCollection=new NVPCollection();
|
||||
nvpCollection.Add(new NVP("Symbol",Symbol.ToString()));
|
||||
nvpCollection.Add(new NVP("AnalysisDate",AnalysisDate.ToString()));
|
||||
nvpCollection.Add(new NVP("PreviousStop",PreviousStop.ToString()));
|
||||
nvpCollection.Add(new NVP("NewStop",NewStop.ToString()));
|
||||
nvpCollection.Add(new NVP("CurrentPriceLow",CurrentPriceLow.ToString()));
|
||||
nvpCollection.Add(new NVP("CurrentPriceClose",CurrentPriceClose.ToString()));
|
||||
nvpCollection.Add(new NVP("PriceTrendIndicatorSlope",PriceTrendIndicatorSlope.ToString()));
|
||||
nvpCollection.Add(new NVP("StopLimitId",StopLimitId==null?"":StopLimitId));
|
||||
return nvpCollection;
|
||||
}
|
||||
public static StopLimit FromNVPCollection(NVPCollection nvpCollection)
|
||||
{
|
||||
StopLimit stopLimit=new StopLimit();
|
||||
|
||||
NVPDictionary nvpDictionary=nvpCollection.ToDictionary();
|
||||
stopLimit.Symbol=nvpDictionary["Symbol"].Get<String>();
|
||||
stopLimit.AnalysisDate=nvpDictionary["AnalysisDate"].Get<DateTime>();
|
||||
stopLimit.PreviousStop=nvpDictionary["PreviousStop"].Get<double>();
|
||||
stopLimit.NewStop=nvpDictionary["NewStop"].Get<double>();
|
||||
stopLimit.CurrentPriceLow=nvpDictionary["CurrentPriceLow"].Get<double>();
|
||||
stopLimit.CurrentPriceClose=nvpDictionary["CurrentPriceClose"].Get<double>();
|
||||
stopLimit.PriceTrendIndicatorSlope=nvpDictionary["PriceTrendIndicatorSlope"].Get<double>();
|
||||
if(nvpDictionary.ContainsKey("StopLimitId"))stopLimit.StopLimitId=nvpDictionary["StopLimitId"].Get<String>();
|
||||
return stopLimit;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user