text stringlengths 0 93.6k |
|---|
# Add strategy Sharpe ratio as text on the plot |
ax3.text( |
0.05, |
0.95, |
f"Strategy Sharpe Ratio: {strategy_sharpe_ratio:.4f}", |
transform=ax3.transAxes, |
verticalalignment="top", |
) |
plt.tight_layout() |
plt.savefig( |
f"{symbol}_prediction_with_stats_and_strategy.png", dpi=300, bbox_inches="tight" |
) |
print( |
f"Plot with statistics and strategy performance saved as '{symbol}_prediction_with_stats_and_strategy.png'" |
) |
plt.show() |
print(f"\nFuture predictions for the next {future_days} days:") |
for date, price in zip(future_dates, future_predictions): |
print(f"{date.date()}: ${price[0]:.2f}") |
print("\nAnalysis and prediction completed successfully.") |
# Parse command-line arguments |
def parse_arguments(): |
parser = argparse.ArgumentParser( |
description="Stock Price Prediction and Analysis Tool" |
) |
parser.add_argument( |
"-s", |
"--symbol", |
type=str, |
default="MSFT", |
help="Stock symbol to analyze (default: MSFT)", |
) |
parser.add_argument( |
"-sd", |
"--start_date", |
type=str, |
default="2018-01-01", |
help="Start date for historical data (default: 2018-01-01)", |
) |
parser.add_argument( |
"-fd", |
"--future_days", |
type=int, |
default=30, |
help="Number of days to predict into the future (default: 30)", |
) |
parser.add_argument( |
"-q", |
"--quick_test", |
action="store_true", |
help="Run in quick test mode (default: False)", |
) |
parser.add_argument( |
"-sw", |
"--suppress_warnings", |
action="store_true", |
help="Suppress warnings (default: False)", |
) |
args = parser.parse_args() |
# Validate start_date |
try: |
datetime.strptime(args.start_date, "%Y-%m-%d") |
except ValueError: |
parser.error("Incorrect start date format, should be YYYY-MM-DD") |
return args |
# Main execution block |
if __name__ == "__main__": |
# Parse command-line arguments |
args = parse_arguments() |
symbol = args.symbol |
start_date = args.start_date |
end_date = datetime.now().strftime("%Y-%m-%d") |
future_days = args.future_days |
quick_test_flag = args.quick_test |
suppress_warnings_flag = args.suppress_warnings |
# Print analysis parameters |
print(f"Analyzing {symbol} from {start_date} to {end_date}") |
print(f"Predicting {future_days} days into the future") |
print(f"Quick test mode: {'Enabled' if quick_test_flag else 'Disabled'}") |
print(f"Warnings suppressed: {'Yes' if suppress_warnings_flag else 'No'}") |
# Run the stock analysis and prediction |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.