File size: 1,448 Bytes
ab50b27 52235c8 087ef0b 52235c8 ab50b27 52235c8 34c23a9 ea51e19 34c23a9 a261fc2 52235c8 a261fc2 34c23a9 52235c8 34c23a9 52235c8 3c1e863 34c23a9 52235c8 34c23a9 52235c8 f6326dc 52235c8 34c23a9 52235c8 a261fc2 34c23a9 52235c8 34c23a9 ab50b27 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
import streamlit as st
import yfinance as yf
import pandas as pd
from Pandas_Market_Predictor import Pandas_Market_Predictor
def fetch_yfinance_data(symbol):
data = yf.download(symbol, start="2022-01-01", end="2022-12-31", interval="5m")
return data
def calculate_indicators(data):
# Convert all columns to numeric
data = data.apply(pd.to_numeric, errors='coerce')
# Example: Simple condition for doji and inside
data['Doji'] = abs(data['Close'] - data['Open']) <= 0.01 * (data['High'] - data['Low'])
data['Inside'] = (data['High'] < data['High'].shift(1)) & (data['Low'] > data['Low'].shift(1))
return data
def main():
st.title("AI Stock Trend Predictor")
# Input for stock symbol
symbol = st.text_input("Enter stock symbol (e.g., AAPL):", "AAPL")
# Fetch yfinance data
stock_data = fetch_yfinance_data(symbol)
# Calculate indicators
stock_data = calculate_indicators(stock_data)
# Create predictor
my_market_predictor = Pandas_Market_Predictor(stock_data)
# Predict Trend
indicators = ["Doji", "Inside"]
trend = my_market_predictor.Trend_Detection(indicators, 10)
# Display results
st.subheader("Predicted Trend:")
st.write("Buy Trend :", trend['BUY'])
st.write("Sell Trend :", trend['SELL'])
st.write("Hold Trend :", trend['HOLD'])
# Delete the DataFrame to release memory
del stock_data
if __name__ == "__main__":
main() |