Make current price work with date offsets
This commit is contained in:
@@ -17,8 +17,6 @@ def Predict():
|
||||
# get the number of days ago to run the simulation for
|
||||
DaysBack = int(sys.argv[2])
|
||||
|
||||
print(f"Days back: {DaysBack}")
|
||||
|
||||
# calculate the time offsets
|
||||
end_date = datetime.now() - timedelta(days=DaysBack)
|
||||
start_date = end_date - timedelta(days=70)
|
||||
@@ -26,9 +24,6 @@ def Predict():
|
||||
# convert to string formats
|
||||
start_str = start_date.strftime('%Y-%m-%d')
|
||||
end_str = end_date.strftime('%Y-%m-%d')
|
||||
|
||||
print(f"Start Date: {start_str}")
|
||||
print(f"End Date: {end_str}")
|
||||
|
||||
# Define paths (consistent with your previous script)
|
||||
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from datetime import datetime, timedelta
|
||||
import sys
|
||||
import yfinance as yf
|
||||
|
||||
@@ -6,8 +7,21 @@ def getCurrentPrice():
|
||||
# Get the Symbol from ARGV
|
||||
symbol = sys.argv[1]
|
||||
|
||||
# get the number of days ago to run the simulation for
|
||||
DaysBack = int(sys.argv[2])
|
||||
|
||||
ticker = yf.Ticker(symbol)
|
||||
data = ticker.history(period="1d", interval="1m")
|
||||
|
||||
# Calculate the target date
|
||||
target_date = datetime.now() - timedelta(days=DaysBack)
|
||||
start_str = target_date.strftime('%Y-%m-%d')
|
||||
|
||||
# End date must be the day AFTER the target to get that day's data
|
||||
end_date = target_date + timedelta(days=1)
|
||||
end_str = end_date.strftime('%Y-%m-%d')
|
||||
|
||||
# Fetch data for that specific 24-hour window
|
||||
data = ticker.history(start=start_str, end=end_str)
|
||||
current_price = data['Close'].iloc[-1]
|
||||
|
||||
# Return to C# via stdout
|
||||
|
||||
Reference in New Issue
Block a user