Skip to content
Snippets Groups Projects
Commit 060ad453 authored by Suresh, Nayana (PG/T - Comp Sci & Elec Eng)'s avatar Suresh, Nayana (PG/T - Comp Sci & Elec Eng)
Browse files

Update montecarlo_ec2

parent cd0144fb
No related branches found
No related tags found
No related merge requests found
......@@ -31,9 +31,7 @@ def calculate_mean_std(close_prices):
return mean_value, std_value
def process_stock_data(event):
"""
Processing the stock data to identify signals and perform Monte Carlo simulation for each signal.
"""
logging.debug(f"Received event: {event}")
stock_data = event.get('stock_data')
h = int(event.get('h'))
d = int(event.get('d'))
......@@ -43,11 +41,14 @@ def process_stock_data(event):
var99_list = []
signal_dates = []
logging.debug(f"Processing {len(stock_data)} records with h={h}, d={d}, t={t}")
for i in range(h, len(stock_data)):
if (t == 'buy' and stock_data[i]['Buy'] == 1) or (t == 'sell' and stock_data[i]['Sell'] == 1):
close_prices = [entry['Close'] for entry in stock_data[i-h:i]]
if len(close_prices) < h:
logging.debug(f"Skipping index {i}, insufficient data")
continue
mean_value, std_value = calculate_mean_std(close_prices)
......@@ -58,13 +59,15 @@ def process_stock_data(event):
signal_dates.append(stock_data[i]['Date'])
results = {
# 'dates': signal_dates,
'var95': var95_list,
'var99': var99_list
}
logging.debug(f"Generated results: {results}")
return results
def main():
try:
# check and parsing the incoming JSON payload
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment