Finalize the preditctor algorithm
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Controllers.PythonInterop;
|
||||
using Entities;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Razor.TagHelpers;
|
||||
|
||||
namespace Controllers.ProjectTest {
|
||||
@@ -36,26 +37,29 @@ namespace Controllers.ProjectTest {
|
||||
// Run once for each day 30 days straight
|
||||
for (int i=30; i>=0; i--) {
|
||||
|
||||
// Check if the day is a weekend
|
||||
DateTime chosenDate = DateTime.Now.AddDays(-i);
|
||||
if (chosenDate.DayOfWeek == DayOfWeek.Saturday || chosenDate.DayOfWeek == DayOfWeek.Sunday) {
|
||||
// If its a weekend skip
|
||||
continue;
|
||||
}
|
||||
|
||||
// Go through each watched stock and find the highest prediction
|
||||
List<Task> threadpool = new List<Task>();
|
||||
foreach(Stock cur in TrackedStocks) {
|
||||
|
||||
// Predict the trend on a new thread
|
||||
Task thread = new Task(async () => {
|
||||
Task thread = new Task(() => {
|
||||
(string, float)Result = _aiModule.PredictAI(cur.Symbol, i);
|
||||
|
||||
// If error log it
|
||||
if (!string.IsNullOrEmpty(Result.Item1)){
|
||||
Console.WriteLine(Result.Item1);
|
||||
}
|
||||
|
||||
// Write the score to the users tracked stocks
|
||||
cur.Score = Result.Item2;
|
||||
});
|
||||
thread.Start();
|
||||
threadpool.Add(thread);
|
||||
}
|
||||
|
||||
// Wait for all processes to finish
|
||||
await Task.WhenAll( threadpool );
|
||||
|
||||
@@ -68,18 +72,20 @@ namespace Controllers.ProjectTest {
|
||||
}
|
||||
|
||||
// Sell all stocks
|
||||
float totalSale = 0;
|
||||
foreach(PurchasedStock cur in StockHistory) {
|
||||
if (cur.Sold == false) {
|
||||
// Get sell price
|
||||
float sellPrice = cur.Quantity * _aiModule.GetCurrentPrice( cur.Symbol, i );
|
||||
if (sellPrice == 0) {
|
||||
// Account for holidays
|
||||
goto next;
|
||||
}
|
||||
// Add up the total sale
|
||||
totalSale += sellPrice;
|
||||
Money = Money + sellPrice;
|
||||
// Mark as sold
|
||||
cur.Sold = true;
|
||||
}
|
||||
}
|
||||
Money += totalSale;
|
||||
|
||||
// Dont buy anything on the last run
|
||||
if (i != 0) {
|
||||
@@ -98,6 +104,8 @@ namespace Controllers.ProjectTest {
|
||||
} );
|
||||
Money = Money - ( stockPrice * MaxQty );
|
||||
}
|
||||
|
||||
next:;
|
||||
}
|
||||
|
||||
// Return a score [Bigger than 0 is money earned] or [Less than 0 is money lost]
|
||||
|
||||
Reference in New Issue
Block a user