streamline ml training better

This commit is contained in:
MuslemRahimi 2024-09-25 00:37:47 +02:00
parent 0e6751c149
commit 001ff4ba67
4 changed files with 66 additions and 6 deletions

View File

@ -9,7 +9,7 @@ import pandas as pd
from tqdm import tqdm
import concurrent.futures
import re
import subprocess
async def save_json(symbol, data):
with open(f"json/trend-analysis/{symbol}.json", 'w') as file:
@ -89,6 +89,14 @@ async def process_symbol(ticker, start_date, end_date, crypto_symbols):
print(e)
async def run():
#Train first model
try:
print('training...')
subprocess.run(["python3", "ml_models/classification.py", "--train"], check=True)
except subprocess.CalledProcessError as e:
print(f"Error running classification.py: {e}")
con = sqlite3.connect('stocks.db')
etf_con = sqlite3.connect('etf.db')
crypto_con = sqlite3.connect('crypto.db')

View File

@ -20,6 +20,15 @@ import aiohttp
import pickle
import time
import argparse
# Set up argument parser
parser = argparse.ArgumentParser(description="Train and test process script.")
parser.add_argument('--train', action='store_true', help="Set to True to run training")
# Parse the arguments
args = parser.parse_args()
async def download_data(ticker, start_date, end_date, nth_day):
try:
@ -189,11 +198,14 @@ async def test_process(nth_day):
async def main():
for nth_day in [5,20,60]:
for nth_day in [5, 20, 60]:
await train_process(nth_day)
await test_process(nth_day=5)
# Run the main function
#asyncio.run(main())
if __name__ == "__main__":
# Run main if --train is set to True
if args.train:
asyncio.run(main())
else:
print("Training not initiated. Pass --train True to start training.")

View File

@ -548,6 +548,15 @@ def run_earnings():
]
run_command(command)
def run_fomc_impact():
run_command(["python3", "cron_fomc_impact.py"])
command = [
"sudo", "rsync", "-avz", "-e", "ssh",
"/root/backend/app/json/fomc-impact",
f"root@{useast_ip_address}:/root/backend/app/json"
]
run_command(command)
def run_economy_indicator():
run_command(["python3", "cron_economic_indicator.py"])
command = [
@ -557,6 +566,33 @@ def run_economy_indicator():
]
run_command(command)
def run_trend_analysis():
run_command(["python3", "cron_trend_analysis.py"])
command = [
"sudo", "rsync", "-avz", "-e", "ssh",
"/root/backend/app/json/trend-analysis",
f"root@{useast_ip_address}:/root/backend/app/json"
]
run_command(command)
def run_sentiment_analysis():
run_command(["python3", "cron_sentiment_analysis.py"])
command = [
"sudo", "rsync", "-avz", "-e", "ssh",
"/root/backend/app/json/sentiment-analysis",
f"root@{useast_ip_address}:/root/backend/app/json"
]
run_command(command)
def run_price_analysis():
run_command(["python3", "cron_price_analysis.py"])
command = [
"sudo", "rsync", "-avz", "-e", "ssh",
"/root/backend/app/json/price-analysis",
f"root@{useast_ip_address}:/root/backend/app/json"
]
run_command(command)
# Create functions to run each schedule in a separate thread
def run_threaded(job_func):
job_thread = threading.Thread(target=job_func)
@ -577,6 +613,7 @@ schedule.every().day.at("07:30").do(run_threaded, run_financial_statements).tag(
schedule.every().day.at("08:00").do(run_threaded, run_economy_indicator).tag('economy_indicator_job')
schedule.every().day.at("08:00").do(run_threaded, run_cron_insider_trading).tag('insider_trading_job')
schedule.every().day.at("08:30").do(run_threaded, run_dividends).tag('dividends_job')
schedule.every().day.at("08:30").do(run_threaded, run_fomc_impact).tag('fomc_impact_job')
schedule.every().day.at("09:00").do(run_threaded, run_congress_trading).tag('congress_job')
schedule.every().day.at("10:00").do(run_threaded, run_shareholders).tag('shareholders_job')
schedule.every().day.at("10:30").do(run_threaded, run_sec_filings).tag('sec_filings_job')
@ -598,6 +635,9 @@ schedule.every().day.at("14:00").do(run_threaded, run_cron_sector).tag('sector_j
schedule.every(2).days.at("01:00").do(run_threaded, run_market_maker).tag('markt_maker_job')
schedule.every(2).days.at("08:30").do(run_threaded, run_financial_score).tag('financial_score_job')
schedule.every().saturday.at("05:00").do(run_threaded, run_ownership_stats).tag('ownership_stats_job')
schedule.every().saturday.at("08:00").do(run_threaded, run_trend_analysis).tag('trend_analysis_job')
schedule.every().saturday.at("08:00").do(run_threaded, run_sentiment_analysis).tag('sentiment_analysis_job')
schedule.every().saturday.at("08:00").do(run_threaded, run_price_analysis).tag('price_analysis_job')
schedule.every(5).minutes.do(run_threaded, run_cron_market_movers).tag('market_movers_job')