Finalize the preditctor algorithm
This commit is contained in:
@@ -207,7 +207,7 @@
|
||||
async Task RunTest(){
|
||||
D683_Project_Test tests = new D683_Project_Test(aiModule);
|
||||
float score = await tests.Simulate();
|
||||
TestResults = score.ToString();
|
||||
TestResults = "Performance [measured in dollars difference from starting money]: " + score.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,6 +22,13 @@ namespace Controllers.Automation {
|
||||
// Start this process on a background thread so its non-blocking
|
||||
Task thread = new Task(() => {
|
||||
|
||||
// Check if the day is a weekend
|
||||
DateTime chosenDate = DateTime.Now.AddDays(-DaysBefore);
|
||||
if (chosenDate.DayOfWeek == DayOfWeek.Saturday || chosenDate.DayOfWeek == DayOfWeek.Sunday) {
|
||||
// If its a weekend skip
|
||||
return;
|
||||
}
|
||||
|
||||
// Load the userlist
|
||||
List<string> VerifiedUserList = new List<string>(){ "TESTMODE" };
|
||||
if (!testmode) {
|
||||
@@ -121,6 +128,9 @@ namespace Controllers.Automation {
|
||||
|
||||
// Get sell price
|
||||
float sellPrice = cur.Quantity * _aiModule.GetCurrentPrice( cur.Symbol );
|
||||
if (sellPrice == 0) {
|
||||
return -1f;
|
||||
}
|
||||
|
||||
// Try create payment session
|
||||
(bool, string) createResult = _paymentProcessor.CreatePayment(username);
|
||||
@@ -157,6 +167,9 @@ namespace Controllers.Automation {
|
||||
|
||||
// Get Stock Price
|
||||
float stockPrice = _aiModule.GetCurrentPrice( stockSymbol );
|
||||
if (stockPrice == 0) {
|
||||
return -1f;
|
||||
}
|
||||
|
||||
// Get max stocks user can purchase [ int cast truncates the decimal ]
|
||||
int MaxQty = (int)( Money / stockPrice );
|
||||
|
||||
@@ -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