Add simulated stock history to UI

This commit is contained in:
derek.holloway
2026-03-13 10:35:20 -07:00
parent b6798e84f5
commit b54f4a29b7
3 changed files with 17 additions and 8 deletions
+9 -5
View File
@@ -81,14 +81,16 @@
<!-- Trade History --> <!-- Trade History -->
<div class="gridFrame"> <div class="gridFrame">
<div> <div>
<h2>Auto Trade History</h2> <h2>@HistoryTitle</h2>
</div> </div>
@foreach (PurchasedStock cur in Session.TradeHistory){ @foreach (PurchasedStock cur in Session.TradeHistory){
<div class="signalBlock"> <div class="signalBlock">
<p style="text-align: center; font-weight: bold;">@cur.Symbol</p> <p style="text-align: center; font-weight: bold;">@cur.Symbol</p>
<p>Purchased Quantity: @cur.Quantity</p> <p>Purchased Quantity: @cur.Quantity</p>
<p>Purchased Price: @cur.PurchasePrice</p> <p>Purchased Price: @cur.PurchasePrice</p>
<p>Sell Price: @cur.PurchasePrice</p> <p>Sell Price: @cur.PurchasePrice</p><br />
<p>Buy Date: @cur.BuyDate.ToString("MM/dd/yy")</p><br />
<p>Sell Date: @cur.BuyDate.ToString("MM/dd/yy")</p>
</div> </div>
} }
</div> </div>
@@ -105,7 +107,7 @@
loginSession? Session = null; loginSession? Session = null;
string resultError = ""; string resultError = "";
string HistoryTitle = "Auto Trade History";
@@ -218,8 +220,10 @@
// Simulate 1 month // Simulate 1 month
D683_Project_Test tests = new D683_Project_Test(aiModule); D683_Project_Test tests = new D683_Project_Test(aiModule);
float score = await tests.Simulate(Session.TrackedStocks); (float, List<PurchasedStock>) score = await tests.Simulate(Session.TrackedStocks);
TestResults = $"The amount of money the AI did better than the SPY: ${score} or { score / 10 }% better"; TestResults = $"The amount of money the AI did better than the SPY: ${score} or { score.Item1 / 10 }% better";
Session.TradeHistory = score.Item2;
HistoryTitle = "Simulated History";
} }
} }
+5 -2
View File
@@ -16,7 +16,7 @@ namespace Controllers.ProjectTest {
_aiModule = aiModule; _aiModule = aiModule;
} }
public async Task<float> Simulate(List<Stock> TrackedStocks) { public async Task<(float, List<PurchasedStock>)> Simulate(List<Stock> TrackedStocks) {
float StartingMoney = Money; float StartingMoney = Money;
// Run once for each day 30 days straight // Run once for each day 30 days straight
for (int i=30; i>=0; i--) { for (int i=30; i>=0; i--) {
@@ -68,6 +68,8 @@ namespace Controllers.ProjectTest {
Money = Money + sellPrice; Money = Money + sellPrice;
// Mark as sold // Mark as sold
cur.Sold = true; cur.Sold = true;
// Set Sell Date
cur.SellDate = DateTime.Now.AddDays(-i);
} }
} }
@@ -85,6 +87,7 @@ namespace Controllers.ProjectTest {
Symbol = HighestRanking.Symbol.ToUpper(), Symbol = HighestRanking.Symbol.ToUpper(),
PurchasePrice = stockPrice, PurchasePrice = stockPrice,
Quantity = MaxQty, Quantity = MaxQty,
BuyDate = DateTime.Now.AddDays(-i)
} ); } );
Money = Money - ( stockPrice * MaxQty ); Money = Money - ( stockPrice * MaxQty );
} }
@@ -103,7 +106,7 @@ namespace Controllers.ProjectTest {
float earned = StartingMoney / SPYbegin * SPYend; float earned = StartingMoney / SPYbegin * SPYend;
// Return the difference between the AI and the SPY -> if value returned is 10. The AI did better than the SPY by $10 // Return the difference between the AI and the SPY -> if value returned is 10. The AI did better than the SPY by $10
return Money - earned; return (Money - earned, StockHistory);
} }
+3 -1
View File
@@ -5,7 +5,9 @@ namespace Entities {
public float Quantity { get; set; } = 0; public float Quantity { get; set; } = 0;
public float PurchasePrice { get; set; } = 0; public float PurchasePrice { get; set; } = 0;
public float SellPrice { get; set; } = 0; public float SellPrice { get; set; } = 0;
public bool Sold = false; public bool Sold { get; set; } = false;
public DateTime BuyDate { get; set; } = new DateTime();
public DateTime SellDate { get; set; } = new DateTime();
} }
} }