Changes for MGSHBacktest model.

Code cleanup.
This commit is contained in:
2025-02-10 07:57:00 -05:00
parent 36b10b4824
commit 0db4473632
16 changed files with 378 additions and 78 deletions

View File

@@ -55,67 +55,118 @@ namespace MarketData.MarketDataModel
get {return tradeId ;}
set { tradeId = value; ;}
}
public String Symbol
{
get { return symbol; }
set { symbol = value; }
}
public DateTime TradeDate
{
get { return tradeDate; }
set { tradeDate = value; }
}
public double Shares
{
get { return shares; }
set { shares = value; }
}
public double Exposure()
{
return Price*Shares;
}
public String BuySell
{
get { return buySell; }
set { buySell = value; }
}
public String Status
{
get { return status; }
set { status = value; }
}
public bool IsOpen
{
get { return status.ToUpper().Equals("OPEN"); }
}
public bool IsClosed
{
get { return !IsOpen; }
}
public String Account
{
get { return account; }
set{account=value;}
}
public DateTime SellDate
{
get { return sellDate; }
set { sellDate = value; }
}
public double SellPrice
{
get { return sellPrice;}
set { sellPrice = value;}
}
public double Price
{
get { return price; }
set { price = value; }
}
public double Commission
{
get { return commission; }
set { commission = value; }
}
public virtual NVPCollection ToNVPCollection()
{
NVPCollection nvpCollection=new NVPCollection();
nvpCollection.Add(new NVP("TradeId",TradeId.ToString()));
if(null!=Symbol)nvpCollection.Add(new NVP("Symbol",Symbol.ToString()));
nvpCollection.Add(new NVP("TradeDate",TradeDate.ToString()));
nvpCollection.Add(new NVP("Shares",Shares.ToString()));
nvpCollection.Add(new NVP("Commission",Commission.ToString()));
if(null!=BuySell)nvpCollection.Add(new NVP("BuySell",BuySell.ToString()));
if(null!=Account)nvpCollection.Add(new NVP("Account",Account.ToString()));
if(null!=Status)nvpCollection.Add(new NVP("Status",Status.ToString()));
nvpCollection.Add(new NVP("SellPrice",SellPrice.ToString()));
nvpCollection.Add(new NVP("SellDate",SellDate.ToString()));
nvpCollection.Add(new NVP("Price",Price.ToString()));
return nvpCollection;
}
public static PortfolioTrade FromNVPCollection(NVPCollection nvpCollection)
{
PortfolioTrade portfolioTrade=new PortfolioTrade();
NVPDictionary nvpDictionary=nvpCollection.ToDictionary();
portfolioTrade.TradeId=nvpDictionary["TradeId"].Get<int>();
portfolioTrade.Symbol=nvpDictionary["Symbol"].Get<String>();
portfolioTrade.TradeDate=nvpDictionary["TradeDate"].Get<DateTime>();
portfolioTrade.Shares=nvpDictionary["Shares"].Get<double>();
portfolioTrade.Commission=nvpDictionary["Commission"].Get<double>();
if(nvpDictionary.ContainsKey("BuySell"))portfolioTrade.BuySell=nvpDictionary["BuySell"].Get<String>();
if(nvpDictionary.ContainsKey("Account"))portfolioTrade.Account=nvpDictionary["Account"].Get<String>();
if(nvpDictionary.ContainsKey("Status"))portfolioTrade.Status=nvpDictionary["Status"].Get<String>();
portfolioTrade.SellPrice=nvpDictionary["SellPrice"].Get<double>();
portfolioTrade.SellDate=nvpDictionary["SellDate"].Get<DateTime>();
portfolioTrade.Price=nvpDictionary["Price"].Get<double>();
return portfolioTrade;
}
}
}

View File

@@ -99,6 +99,7 @@ namespace MarketData.MarketDataModel
{
return this.Min(x => x.TradeDate);
}
public DateTime GetMinTradeDate(String symbol)
{
DateTime minDate=Utility.Epoch;
@@ -271,5 +272,26 @@ namespace MarketData.MarketDataModel
if(!portfolioTrade.SellDate.Equals(Utility.Epoch)&&price.Date>portfolioTrade.SellDate) return null;
return portfolioTrade.Shares*portfolioTrade.Price;
}
// Collections
public NVPCollections ToNVPCollections()
{
NVPCollections nvpCollections=new NVPCollections();
foreach(PortfolioTrade portfolioTrade in this)
{
nvpCollections.Add(portfolioTrade.ToNVPCollection());
}
return nvpCollections;
}
public static PortfolioTrades FromNVPCollections(NVPCollections nvpCollections)
{
PortfolioTrades portfolioTrades=new PortfolioTrades();
foreach(NVPCollection nvpCollection in nvpCollections)
{
portfolioTrades.Add(PortfolioTrade.FromNVPCollection(nvpCollection));
}
return portfolioTrades;
}
}
}

View File

@@ -3,6 +3,10 @@ using System;
using System.Collections.Generic;
using System.Text;
/// <summary>
/// This StopLimit class is used for database persistence
/// </summary>
namespace MarketData.MarketDataModel
{
public class StopLimitConstants
@@ -102,4 +106,4 @@ namespace MarketData.MarketDataModel
return stopLimit;
}
}
}
}