Files
marketdata/MarketDataLib/Generator/CMMomentum/SlotPosition.cs
2024-02-22 14:52:53 -05:00

119 lines
3.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using MarketData.MarketDataModel;
using MarketData.DataAccess;
using MarketData.Utils;
using System.Linq;
using MarketData.Helper;
using MarketData.Numerical;
namespace MarketData.Generator.CMMomentum
{
public class SlotPositions : List<SlotPosition>
{
public SlotPositions()
{
}
public SlotPositions(int slot, Positions positions)
{
for (int index = 0; index < positions.Count; index++)
{
Add(new SlotPosition(slot, positions[index]));
}
}
public NVPCollections ToNVPCollections()
{
NVPCollections nvpCollections = new NVPCollections();
foreach (SlotPosition position in this)
{
nvpCollections.Add(position.ToNVPCollection());
}
return nvpCollections;
}
public static SlotPositions FromNVPCollections(NVPCollections nvpCollections)
{
SlotPositions positions = new SlotPositions();
foreach (NVPCollection nvpCollection in nvpCollections)
{
positions.Add(SlotPosition.FromNVPCollection(nvpCollection));
}
return positions;
}
}
public class SlotPosition : Position
{
public SlotPosition()
{
}
public SlotPosition(int slot, Position position) : base(position)
{
Slot = slot;
//Symbol = position.Symbol;
//PurchaseDate = position.PurchaseDate;
//SellDate = position.SellDate;
//Shares = position.Shares;
//PurchasePrice = position.PurchasePrice;
//CurrentPrice = position.CurrentPrice;
//Beta= position.Beta;
//BetaMonths = position.BetaMonths;
//SharpeRatio = position.SharpeRatio;
//Weight = position.Weight;
//RiskAdjustedWeight = position.RiskAdjustedWeight;
//RiskAdjustedAllocation = position.RiskAdjustedAllocation;
//TargetBetaOverBeta = position.TargetBetaOverBeta;
}
public SlotPosition(Position position) : base(position)
{
//Symbol = position.Symbol;
//PurchaseDate = position.PurchaseDate;
//SellDate = position.SellDate;
//Shares = position.Shares;
//PurchasePrice = position.PurchasePrice;
//CurrentPrice = position.CurrentPrice;
//Beta = position.Beta;
//BetaMonths = position.BetaMonths;
//SharpeRatio = position.SharpeRatio;
//Weight = position.Weight;
//RiskAdjustedWeight = position.RiskAdjustedWeight;
//RiskAdjustedAllocation = position.RiskAdjustedAllocation;
//TargetBetaOverBeta = position.TargetBetaOverBeta;
}
public Position ToPosition()
{
Position position = new Position(this);
return position;
//Position position = new Position();
//position.Symbol = Symbol;
//position.PurchaseDate = PurchaseDate;
//position.SellDate = SellDate;
//position.Shares = Shares;
//position.PurchasePrice = PurchasePrice;
//position.CurrentPrice = CurrentPrice;
//position.Beta = Beta;
//position.BetaMonths = BetaMonths;
//position.SharpeRatio = SharpeRatio;
//position.Weight = Weight;
//position.RiskAdjustedWeight = RiskAdjustedWeight;
//position.RiskAdjustedAllocation = RiskAdjustedAllocation;
//position.TargetBetaOverBeta = TargetBetaOverBeta;
//return position;
}
public int Slot { get; set; }
public override NVPCollection ToNVPCollection()
{
NVPCollection nvpCollection = base.ToNVPCollection();
nvpCollection.Insert(0, new NVP("Slot", Slot.ToString()));
return nvpCollection;
}
public static new SlotPosition FromNVPCollection(NVPCollection nvpCollection)
{
NVPDictionary nvpDictionary = nvpCollection.ToDictionary();
Position position = Position.FromNVPCollection(nvpCollection);
SlotPosition slotPosition = new SlotPosition(position);
slotPosition.Slot = nvpDictionary["Slot"].Get<int>();
return slotPosition;
}
}
}