Notice
Recent Posts
Recent Comments
ยซ   2024/11   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
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
Archives
Today
In Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

A Joyful AI Research Journey๐ŸŒณ๐Ÿ˜Š

[6] 241106 Team Project Role: Stock Headline Sentiment Analysis [Goorm All-In-One Pass! AI Project Master 4๊ธฐ 6์ผ] ๋ณธ๋ฌธ

๐ŸŒณAI Project Mastery Bootcamp 2024โœจ/Project

[6] 241106 Team Project Role: Stock Headline Sentiment Analysis [Goorm All-In-One Pass! AI Project Master 4๊ธฐ 6์ผ]

yjyuwisely 2024. 11. 6. 15:12

๊ฐ์„ฑ ๋ถ„์„ ์ด์Šˆ

Neutral ์•ˆ ํ•ด๋ด„ ํ•ด๋ณด์ž! ๊ถ๊ธˆํ•˜๋‹ค 

์ค‘๋ฆฝ ๊ฐ์„ฑ ๋ถ„์„์€ ํŠน์ • ํ…์ŠคํŠธ๊ฐ€ ๊ธ์ •์ ์ด๊ฑฐ๋‚˜ ๋ถ€์ •์ ์ธ ๊ฐ์„ฑ์„ ๊ฐ–์ง€ ์•Š๊ณ  ์ค‘๋ฆฝ์ ์ธ ์ƒํƒœ์ž„์„ ํ‰๊ฐ€ํ•˜๋Š” ๊ณผ์ •์ž…๋‹ˆ๋‹ค. ๊ฐ์„ฑ ๋ถ„์„์€ ์ผ๋ฐ˜์ ์œผ๋กœ ๊ธ์ •, ์ค‘๋ฆฝ, ๋ถ€์ •์˜ ์„ธ ๊ฐ€์ง€ ๋ฒ”์ฃผ๋กœ ๋‚˜๋ˆŒ ์ˆ˜ ์žˆ์œผ๋ฉฐ, ์ค‘๋ฆฝ ๊ฐ์„ฑ์€ ์ฃผ๋กœ ๊ฐ์ •์ด ๋ช…ํ™•ํ•˜๊ฒŒ ๋“œ๋Ÿฌ๋‚˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ์— ํ•ด๋‹นํ•ฉ๋‹ˆ๋‹ค.

๊ณต๋ชจ์ฃผ ์ƒ์žฅ ์˜ˆ์ • ๋“ฑ 

๊ฐ์„ฑ ๋ถ„์„ -> ์›€์ง์ž„! ๊ตฌํ˜„ (๋‚˜๋ฌด, ํ• ์•„๋ฒ„์ง€) 

ARIMA 


https://github.com/yjyuwisely/AI_project_mastery_bootcamp/blob/main/241107_stock_sentiment.ipynb

 

AI_project_mastery_bootcamp/241107_stock_sentiment.ipynb at main · yjyuwisely/AI_project_mastery_bootcamp

Goorm All-In-One Pass! AI Project Master Bootcamp. Contribute to yjyuwisely/AI_project_mastery_bootcamp development by creating an account on GitHub.

github.com

์ฝ”๋“œ) 

import requests
from bs4 import BeautifulSoup
from transformers import pipeline
import ipywidgets as widgets

def get_stock_buy_recommendation(stock_name):
    """
    Fetch the top 10 news headlines related to the given stock, perform sentiment analysis using BERT, and provide a buy recommendation.
    ์ฃผ์–ด์ง„ ์ฃผ์‹๊ณผ ๊ด€๋ จ๋œ ์ƒ์œ„ 10๊ฐœ์˜ ๋‰ด์Šค ํ—ค๋“œ๋ผ์ธ์„ ๊ฐ€์ ธ์˜ค๊ณ , BERT๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ์ • ๋ถ„์„์„ ์ˆ˜ํ–‰ํ•œ ๋’ค ๋งค์ˆ˜ ์ถ”์ฒœ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
    
    Parameters:
    stock_name (str): The name of the stock to search for
    ์ฃผ์‹ ์ด๋ฆ„ (str): ๊ฒ€์ƒ‰ํ•  ์ฃผ์‹์˜ ์ด๋ฆ„

    Returns:
    tuple: (list of (headline, sentiment_emoji), buy_recommendation_str)
    ํŠœํ”Œ: (ํ—ค๋“œ๋ผ์ธ๊ณผ ๊ฐ์ • ์ด๋ชจํ‹ฐ์ฝ˜์˜ ๋ฆฌ์ŠคํŠธ, ๋งค์ˆ˜ ์ถ”์ฒœ ๋ฌธ์ž์—ด)
    """
    # Fetch news headlines from Naver search
    # ๋„ค์ด๋ฒ„ ๊ฒ€์ƒ‰์—์„œ ๋‰ด์Šค ํ—ค๋“œ๋ผ์ธ ๊ฐ€์ ธ์˜ค๊ธฐ
    url = f'https://search.naver.com/search.naver?ie=utf8&sm=nws_hty&query={stock_name}'
    response = requests.get(url)
    soup = BeautifulSoup(response.content, 'html.parser')

    # Extract the top 10 news headline text
    # ์ƒ์œ„ 10๊ฐœ์˜ ๋‰ด์Šค ํ—ค๋“œ๋ผ์ธ ํ…์ŠคํŠธ ์ถ”์ถœ
    headlines = [headline.get_text() for headline in soup.find_all('a', class_='news_tit')[:10]]

    # Load the pre-trained BERT sentiment analysis model
    # ์‚ฌ์ „ ํ•™์Šต๋œ BERT ๊ฐ์ • ๋ถ„์„ ๋ชจ๋ธ ๋กœ๋“œ
    sentiment_analyzer = pipeline('sentiment-analysis')

    # Perform sentiment analysis on each headline using BERT
    # ๊ฐ ํ—ค๋“œ๋ผ์ธ์— ๋Œ€ํ•ด BERT๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ์ • ๋ถ„์„ ์ˆ˜ํ–‰
    results = []
    positive_count = 0
    negative_count = 0
    for headline in headlines:
        sentiment = sentiment_analyzer(headline)[0]['label']

        # Represent sentiment using emoji expressions
        # ๊ฐ์ •์„ ์ด๋ชจํ‹ฐ์ฝ˜์œผ๋กœ ํ‘œํ˜„
        if sentiment == 'POSITIVE':
            sentiment_emoji = '๐Ÿ˜Š'
            positive_count += 1
        elif sentiment == 'NEGATIVE':
            sentiment_emoji = '๐Ÿ˜ฐ'
            negative_count += 1
        else:
            sentiment_emoji = '๐Ÿ˜'

        results.append((headline, sentiment_emoji))

    # Determine the buy recommendation based on sentiment
    # ๊ฐ์ • ๋ถ„์„ ๊ฒฐ๊ณผ์— ๋”ฐ๋ผ ๋งค์ˆ˜ ์ถ”์ฒœ ๊ฒฐ์ •
    if positive_count > negative_count:
        buy_recommendation = f'{stock_name}์„(๋ฅผ) ๋งค์ˆ˜ํ•˜์„ธ์š” ๐Ÿ˜Š'
    elif positive_count < negative_count:
        buy_recommendation = f'{stock_name}์„(๋ฅผ) ๋งค์ˆ˜ํ•˜์ง€ ๋งˆ์„ธ์š” ๐Ÿ˜ฐ'
    else:
        buy_recommendation = f'{stock_name}์— ๋Œ€ํ•ด ์ค‘๋ฆฝ์ ์ธ ์ž…์žฅ์ž…๋‹ˆ๋‹ค ๐Ÿ˜'

    return results, buy_recommendation

# Create a text input widget for the user to enter a stock name
# ์‚ฌ์šฉ์ž๊ฐ€ ์ฃผ์‹ ์ด๋ฆ„์„ ์ž…๋ ฅํ•  ์ˆ˜ ์žˆ๋Š” ํ…์ŠคํŠธ ์ž…๋ ฅ ์œ„์ ฏ ์ƒ์„ฑ
stock_input = widgets.Text(
    value='',
    placeholder='์ข…๋ชฉ๋ช…์„ ์ž…๋ ฅํ•˜์„ธ์š”.',
    description='์ข…๋ชฉ๋ช…:',
    disabled=False
)

# Create a button to trigger the sentiment analysis and recommendation
# ๊ฐ์ • ๋ถ„์„๊ณผ ์ถ”์ฒœ์„ ์‹คํ–‰ํ•  ๋ฒ„ํŠผ ์ƒ์„ฑ
analyze_button = widgets.Button(description="ํˆฌ์ž์˜๊ฒฌ")

# Create an output widget to display the results
# ๊ฒฐ๊ณผ๋ฅผ ํ‘œ์‹œํ•  ์ถœ๋ ฅ ์œ„์ ฏ ์ƒ์„ฑ
output = widgets.Output()
27.
# Define a function to handle the button click
# ๋ฒ„ํŠผ ํด๋ฆญ์„ ์ฒ˜๋ฆฌํ•˜๋Š” ํ•จ์ˆ˜ ์ •์˜
def get_recommendation(button):
    with output:
        output.clear_output()  # Clear previous output before displaying new results / ์ด์ „ ๊ฒฐ๊ณผ๋ฅผ ์ง€์šฐ๊ณ  ์ƒˆ ๊ฒฐ๊ณผ ํ‘œ์‹œ
        stock_name = stock_input.value
        headline_results, buy_recommendation = get_stock_buy_recommendation(stock_name)

        # Display the news headlines and sentiment
        # ๋‰ด์Šค ํ—ค๋“œ๋ผ์ธ๊ณผ ๊ฐ์ • ๋ถ„์„ ๊ฒฐ๊ณผ ํ‘œ์‹œ
        print(f'{stock_name}์— ๋Œ€ํ•œ ์ƒ์œ„ 10๊ฐœ์˜ ๋‰ด์Šค ํ—ค๋“œ๋ผ์ธ:')
        for headline, emoji in headline_results:
            print(f'{emoji} {headline}')

        # Display the buy recommendation
        # ๋งค์ˆ˜ ์ถ”์ฒœ ํ‘œ์‹œ
        print()
        print(buy_recommendation)

# Add the widgets to the Colab notebook
# Colab ๋…ธํŠธ๋ถ์— ์œ„์ ฏ ์ถ”๊ฐ€
display(stock_input, analyze_button, output)

# Connect the button click to the get_recommendation function
# ๋ฒ„ํŠผ ํด๋ฆญ์„ get_recommendation ํ•จ์ˆ˜์— ์—ฐ๊ฒฐ
analyze_button.on_click(get_recommendation)

๊ฒฐ๊ณผ)


๋‰ด์Šค ๊ฐ์ • ๋ถ„์„ ๋ฐ ์ด๋ฒคํŠธ ์˜ํ–ฅ ํ‘œ์‹œ

  • ๋‰ด์Šค ํ—ค๋“œ๋ผ์ธ ๊ฐ์ • ๋ถ„์„: ์ตœ๊ทผ ์ฃผ์‹๊ณผ ๊ด€๋ จ๋œ ๋‰ด์Šค ๊ธฐ์‚ฌ๋‚˜ ์†Œ์…œ ๋ฏธ๋””์–ด ๋ฐ์ดํ„ฐ๋ฅผ ์ˆ˜์ง‘ํ•˜์—ฌ, ๊ฐ์ • ๋ถ„์„์„ ํ†ตํ•ด ๊ธ์ •์ , ๋ถ€์ •์ , ์ค‘๋ฆฝ์ ์ธ ์˜๊ฒฌ์„ ๋ถ„๋ฅ˜ํ•  ์ˆ˜ ์žˆ์–ด์š”. ์ด๋ฅผ ํ†ตํ•ด ์‚ฌ์šฉ์ž์—๊ฒŒ ์ตœ๊ทผ ๋‰ด์Šค๊ฐ€ ์ฃผ์‹์— ์–ด๋–ค ์˜ํ–ฅ์„ ๋ฏธ์น˜๋Š”์ง€ ๋ณด์—ฌ์ค„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ๋‹จ๊ธฐ ์˜ˆ์ธก ๋ชจ๋ธ ์ถ”๊ฐ€: ์ฃผ๊ฐ€์˜ ๋‹จ๊ธฐ ์˜ˆ์ธก์„ ์œ„ํ•ด ARIMA, LSTM, Prophet ๋“ฑ์˜ ํƒ€์ž„ ์‹œ๋ฆฌ์ฆˆ ์˜ˆ์ธก ๋ชจ๋ธ์„ ์ถ”๊ฐ€ํ•˜์—ฌ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ฉฐ์น  ๋’ค ์ฃผ๊ฐ€์˜ ๋ณ€๋™ ๊ฐ€๋Šฅ์„ฑ์„ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์†Œ์…œ ๋ฏธ๋””์–ด ํŠธ๋ Œ๋“œ ๋ถ„์„

  • ํŠธ์œ„ํ„ฐ, Reddit, ๊ธฐํƒ€ SNS ๋ถ„์„: ํŠน์ • ์ฃผ์‹์— ๋Œ€ํ•œ ์†Œ์…œ ๋ฏธ๋””์–ด์˜ ๋ฐ˜์‘์„ ์ˆ˜์ง‘ํ•˜๊ณ  ์ด๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ํŠธ๋ Œ๋“œ๋ฅผ ์‹œ๊ฐํ™”ํ•˜์—ฌ ์‚ฌ์šฉ์ž์—๊ฒŒ ํŠธ๋ ˆ์ด๋”ฉ ์•„์ด๋””์–ด๋ฅผ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

https://github.com/hello22433/AI_JooAU_firstproject

 

GitHub - hello22433/AI_JooAU_firstproject

Contribute to hello22433/AI_JooAU_firstproject development by creating an account on GitHub.

github.com


241106 Wed 6th class

http://data.krx.co.kr/contents/MDC/MAIN/main/index.cmd

 

KRX ์ •๋ณด๋ฐ์ดํ„ฐ์‹œ์Šคํ…œ

์ฆ๊ถŒ·ํŒŒ์ƒ์ƒํ’ˆ์˜ ์‹œ์žฅ์ •๋ณด(Marketdata), ๊ณต๋งค๋„์ •๋ณด, ํˆฌ์ž๋ถ„์„์ •๋ณด(SMILE) ๋“ฑ ํ•œ๊ตญ๊ฑฐ๋ž˜์†Œ์˜ ์ •๋ณด๋ฐ์ดํ„ฐ๋ฅผ ํ†ตํ•ฉํ•˜์—ฌ ์ œ๊ณต ์„œ๋น„์Šค

data.krx.co.kr

 

์›Œ๋“œํด๋ผ์šฐ๋“œ + ์ฃผ์‹ ๋งค์ˆ˜/๋งค๋„์— ๋Œ€ํ•œ ํ‰๊ฐ€

์›Œ๋“œ์— ๊ด€๋ จ๋œ ๋‰ด์Šค๊ธฐ์‚ฌ์— ๋Œ“๊ธ€ ๊ฐ™์€ ๊ฒŒ ์žˆ์„๊ฑด๋ฐ ๊ทธ ๋Œ“๊ธ€์„ ์‚ฌ๋žŒ์˜ ํ‘œ์ •์œผ๋กœ ์‹œ๊ฐํ™”์‹œํ‚ค๋Š” ๊ฑด ์–ด๋–จ๊นŒ์š” ?

ํ‚ค์›Œ๋“œ์— ๋Œ€ํ•œ ์‚ฌ๋žŒ๋“ค์˜ ๊ฐ์ •์„ ํ‰๊ฐ€ํ•˜๋Š” ์ž๋ฃŒ๋กœ ์“ธ ์ˆ˜ ์žˆ์ง€ ์•Š์„๊นŒ ์‹ถ์Šต๋‹ˆ๋‹ค ์ง๊ด€์ ์œผ๋กœ

๊ทธ ๊ด€๋ จ ๊ธฐ์‚ฌ ๋˜๋Š” ์‚ฌ๋žŒ๋“ค ๋Œ“๊ธ€์„ ์›น ์Šคํฌ๋กค๋งํ•ด์„œ ์‚ฌ๋žŒ๋“ค์˜ ๊ฐ์„ฑ์„ ์ด๋ชจํ‹ฐ์ฝ˜(๊ธ์ • / ๋ถ€์ •)์œผ๋กœ ํ‘œํ˜„ํ•œ๋‹ค

๊ทธ ๊ฐ์ •์— ๋Œ€ํ•œ ํŒ๋‹จ๋„ ๋ฐ์ดํ„ฐ๋ถ„์„์„ ์ด์šฉํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์•„์„œ์š” ์ปดํ“จํ„ฐ๊ฐ€ ๊ฐ์ •์„ ์ธ์‹ํ•˜๋Š” ์„ผ์„œ๊ฐ€ ์—†์œผ๋‹ˆ ์ธ๊ณต์ง€๋Šฅ ์ฝ”๋“œ๋ฅผ ํ™œ์šฉํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค


 


  1. ๋‰ด์Šค ํ—ค๋“œ๋ผ์ธ ๊ฐ์ • ๋ถ„์„: ์ตœ๊ทผ ์ฃผ์‹๊ณผ ๊ด€๋ จ๋œ ๋‰ด์Šค ๊ธฐ์‚ฌ๋‚˜ ์†Œ์…œ ๋ฏธ๋””์–ด ๋ฐ์ดํ„ฐ๋ฅผ ์ˆ˜์ง‘ํ•˜์—ฌ, ๊ฐ์ • ๋ถ„์„์„ ํ†ตํ•ด ๊ธ์ •์ , ๋ถ€์ •์ , ์ค‘๋ฆฝ์ ์ธ ์˜๊ฒฌ์„ ๋ถ„๋ฅ˜ํ•  ์ˆ˜ ์žˆ์–ด์š”. ์ด๋ฅผ ํ†ตํ•ด ์‚ฌ์šฉ์ž์—๊ฒŒ ์ตœ๊ทผ ๋‰ด์Šค๊ฐ€ ์ฃผ์‹์— ์–ด๋–ค ์˜ํ–ฅ์„ ๋ฏธ์น˜๋Š”์ง€ ๋ณด์—ฌ์ค„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  1. ๊ธฐ์ˆ ์  ์ง€ํ‘œ ๊ณ„์‚ฐ ๋ฐ ์‹œ๊ฐํ™”
  • ์ด๋™ ํ‰๊ท ์„  (Moving Averages): ๋‹จ๊ธฐ ๋ฐ ์žฅ๊ธฐ ์ด๋™ ํ‰๊ท ์„ ์„ ์ฐจํŠธ์— ํ•จ๊ป˜ ํ‘œ์‹œํ•˜์—ฌ ๊ณจ๋“  ํฌ๋กœ์Šค๋‚˜ ๋ฐ๋“œ ํฌ๋กœ์Šค๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ํŠธ๋ Œ๋“œ๋ฅผ ์‰ฝ๊ฒŒ ํŒŒ์•…ํ•˜๋Š” ๋ฐ ๋„์›€์„ ์ค๋‹ˆ๋‹ค.
  • RSI (Relative Strength Index): RSI๋Š” ํŠน์ • ์ฃผ์‹์ด ๊ณผ๋งค๋„ ๋˜์—ˆ๋Š”์ง€ ๊ณผ๋งค์ˆ˜ ๋˜์—ˆ๋Š”์ง€๋ฅผ ํŒŒ์•…ํ•˜๋Š” ๋ฐ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค. RSI ๊ทธ๋ž˜ํ”„๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋งค์ˆ˜/๋งค๋„ ํƒ€์ด๋ฐ์— ๋Œ€ํ•œ ์ถ”๊ฐ€์ ์ธ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • MACD (Moving Average Convergence Divergence): MACD๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ์‚ฌ์šฉ์ž๊ฐ€ ๋ชจ๋ฉ˜ํ…€์˜ ๋ณ€ํ™”๋ฅผ ์‰ฝ๊ฒŒ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  1. ์†Œ์…œ ๋ฏธ๋””์–ด ํŠธ๋ Œ๋“œ ๋ถ„์„: ํŠธ์œ„ํ„ฐ, Reddit, ๊ธฐํƒ€ SNS ๋ถ„์„: ํŠน์ • ์ฃผ์‹์— ๋Œ€ํ•œ ์†Œ์…œ ๋ฏธ๋””์–ด์˜ ๋ฐ˜์‘์„ ์ˆ˜์ง‘ํ•˜๊ณ  ์ด๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ํŠธ๋ Œ๋“œ๋ฅผ ์‹œ๊ฐํ™”ํ•˜์—ฌ ์‚ฌ์šฉ์ž์—๊ฒŒ ํŠธ๋ ˆ์ด๋”ฉ ์•„์ด๋””์–ด๋ฅผ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ˜„์žฌ ํ”„๋กœ์ ํŠธ์— ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋Š” ํฅ๋ฏธ๋กœ์šด ๊ธฐ๋Šฅ๋“ค์ด ๋งŽ์•„์š”. ์›Œ๋“œํด๋ผ์šฐ๋“œ์™€ ๋งค์ˆ˜/๋งค๋„ ํ‰๊ฐ€ ์™ธ์—๋„ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋” ํ’๋ถ€ํ•œ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•˜๊ณ  ์ฃผ์‹ ํˆฌ์ž์˜ ๊ฒฐ์ •์„ ๋„์šธ ์ˆ˜ ์žˆ๋Š” ๋ช‡ ๊ฐ€์ง€ ์ถ”๊ฐ€ ๊ธฐ๋Šฅ์„ ์ถ”์ฒœ๋“œ๋ฆด๊ฒŒ์š”:

1. ๋‰ด์Šค ๊ฐ์ • ๋ถ„์„ ๋ฐ ์ด๋ฒคํŠธ ์˜ํ–ฅ ํ‘œ์‹œ

  • ๋‰ด์Šค ํ—ค๋“œ๋ผ์ธ ๊ฐ์ • ๋ถ„์„: ์ตœ๊ทผ ์ฃผ์‹๊ณผ ๊ด€๋ จ๋œ ๋‰ด์Šค ๊ธฐ์‚ฌ๋‚˜ ์†Œ์…œ ๋ฏธ๋””์–ด ๋ฐ์ดํ„ฐ๋ฅผ ์ˆ˜์ง‘ํ•˜์—ฌ, ๊ฐ์ • ๋ถ„์„์„ ํ†ตํ•ด ๊ธ์ •์ , ๋ถ€์ •์ , ์ค‘๋ฆฝ์ ์ธ ์˜๊ฒฌ์„ ๋ถ„๋ฅ˜ํ•  ์ˆ˜ ์žˆ์–ด์š”. ์ด๋ฅผ ํ†ตํ•ด ์‚ฌ์šฉ์ž์—๊ฒŒ ์ตœ๊ทผ ๋‰ด์Šค๊ฐ€ ์ฃผ์‹์— ์–ด๋–ค ์˜ํ–ฅ์„ ๋ฏธ์น˜๋Š”์ง€ ๋ณด์—ฌ์ค„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์ด๋ฒคํŠธ ๋งคํ•‘: ํŠน์ • ๋‚ ์งœ์— ์ฃผ์š” ์ด๋ฒคํŠธ(์˜ˆ: ์‹ค์  ๋ฐœํ‘œ, ์ •์ฑ… ๋ณ€๊ฒฝ, ์ฃผ์š” ํšŒ์‚ฌ ๋‰ด์Šค ๋“ฑ)๊ฐ€ ์žˆ์—ˆ๋Š”์ง€๋ฅผ ์ฐจํŠธ์— ํ‘œ์‹œํ•˜๊ณ  ํ•ด๋‹น ์ด๋ฒคํŠธ๊ฐ€ ์ฃผ๊ฐ€์— ๋ฏธ์นœ ์˜ํ–ฅ์„ ์‹œ๊ฐ์ ์œผ๋กœ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ์–ด์š”.

2. ๊ธฐ์ˆ ์  ์ง€ํ‘œ ๊ณ„์‚ฐ ๋ฐ ์‹œ๊ฐํ™”

  • ์ด๋™ ํ‰๊ท ์„  (Moving Averages): ๋‹จ๊ธฐ ๋ฐ ์žฅ๊ธฐ ์ด๋™ ํ‰๊ท ์„ ์„ ์ฐจํŠธ์— ํ•จ๊ป˜ ํ‘œ์‹œํ•˜์—ฌ ๊ณจ๋“  ํฌ๋กœ์Šค๋‚˜ ๋ฐ๋“œ ํฌ๋กœ์Šค๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ํŠธ๋ Œ๋“œ๋ฅผ ์‰ฝ๊ฒŒ ํŒŒ์•…ํ•˜๋Š” ๋ฐ ๋„์›€์„ ์ค๋‹ˆ๋‹ค.
  • RSI (Relative Strength Index): RSI๋Š” ํŠน์ • ์ฃผ์‹์ด ๊ณผ๋งค๋„ ๋˜์—ˆ๋Š”์ง€ ๊ณผ๋งค์ˆ˜ ๋˜์—ˆ๋Š”์ง€๋ฅผ ํŒŒ์•…ํ•˜๋Š” ๋ฐ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค. RSI ๊ทธ๋ž˜ํ”„๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋งค์ˆ˜/๋งค๋„ ํƒ€์ด๋ฐ์— ๋Œ€ํ•œ ์ถ”๊ฐ€์ ์ธ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • MACD (Moving Average Convergence Divergence): MACD๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ ์‚ฌ์šฉ์ž๊ฐ€ ๋ชจ๋ฉ˜ํ…€์˜ ๋ณ€ํ™”๋ฅผ ์‰ฝ๊ฒŒ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

3. ์ฃผ๊ฐ€ ์˜ˆ์ธก ๊ธฐ๋Šฅ

  • ๋‹จ๊ธฐ ์˜ˆ์ธก ๋ชจ๋ธ ์ถ”๊ฐ€: ์ฃผ๊ฐ€์˜ ๋‹จ๊ธฐ ์˜ˆ์ธก์„ ์œ„ํ•ด ARIMA, LSTM, Prophet ๋“ฑ์˜ ํƒ€์ž„ ์‹œ๋ฆฌ์ฆˆ ์˜ˆ์ธก ๋ชจ๋ธ์„ ์ถ”๊ฐ€ํ•˜์—ฌ ์‚ฌ์šฉ์ž์—๊ฒŒ ๋ฉฐ์น  ๋’ค ์ฃผ๊ฐ€์˜ ๋ณ€๋™ ๊ฐ€๋Šฅ์„ฑ์„ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์‹œ๋‚˜๋ฆฌ์˜ค ๊ธฐ๋ฐ˜ ์˜ˆ์ธก: ์—ฌ๋Ÿฌ ๊ฐ€์ง€ ์‹œ๋‚˜๋ฆฌ์˜ค (์˜ˆ: ๊ฒฝ์ œ ์„ฑ์žฅ๋ฅ  ๋ณ€ํ™”, ๊ธˆ๋ฆฌ ์ธ์ƒ ๋“ฑ)์™€ ๊ฐ™์€ ์™ธ๋ถ€ ์š”์ธ์„ ๊ฐ€์ •ํ•˜๊ณ  ์ฃผ๊ฐ€๊ฐ€ ์–ด๋–ป๊ฒŒ ๋ณ€ํ• ์ง€ ์˜ˆ์ธกํ•˜๋Š” ์‹œ๋‚˜๋ฆฌ์˜ค ๋ถ„์„ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

4. ํฌํŠธํด๋ฆฌ์˜ค ๊ด€๋ฆฌ ๋ฐ ๋ฐฑํ…Œ์ŠคํŒ…

  • ๊ฐ€์ƒ ํฌํŠธํด๋ฆฌ์˜ค ๊ด€๋ฆฌ: ์‚ฌ์šฉ์ž๊ฐ€ ๊ฐ€์ƒ์˜ ์ฃผ์‹์„ ๋งค์ˆ˜ํ•˜๊ฑฐ๋‚˜ ๋งค๋„ํ•ด ํฌํŠธํด๋ฆฌ์˜ค๋ฅผ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด ๋ณด์„ธ์š”. ์ด๋ฅผ ํ†ตํ•ด ์‚ฌ์šฉ์ž๋Š” ์ž์‹ ์˜ ์ „๋žต์ด ์–ด๋–ป๊ฒŒ ์ž‘๋™ํ•˜๋Š”์ง€ ์‹œ๋ฎฌ๋ ˆ์ด์…˜ํ•ด๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ๋ฐฑํ…Œ์ŠคํŒ… ๊ธฐ๋Šฅ: ํŠน์ • ์ „๋žต์— ๋”ฐ๋ผ ๊ฐ€์ƒ์œผ๋กœ ํˆฌ์žํ–ˆ์„ ๋•Œ ๊ณผ๊ฑฐ ๋ฐ์ดํ„ฐ์—์„œ ์–ด๋–ค ์„ฑ๊ณผ๋ฅผ ๋ณด์˜€๋Š”์ง€๋ฅผ ํ‰๊ฐ€ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋ฐฑํ…Œ์ŠคํŒ… ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•ด ๋ณด์„ธ์š”. ์ด๋ฅผ ํ†ตํ•ด ์‚ฌ์šฉ์ž๋Š” ์ „๋žต์˜ ์œ ํšจ์„ฑ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

5. ๋ฆฌ์Šคํฌ ํ‰๊ฐ€ ๋ฐ ๋ถ„์‚ฐ ํˆฌ์ž ์ถ”์ฒœ

  • ๋ณ€๋™์„ฑ ๋ถ„์„ (Volatility Analysis): ๊ฐ ์ฃผ์‹์˜ ๋ณ€๋™์„ฑ์„ ์‹œ๊ฐํ™”ํ•˜์—ฌ, ์‚ฌ์šฉ์ž๊ฐ€ ํˆฌ์ž ๋ฆฌ์Šคํฌ๋ฅผ ์ดํ•ดํ•˜๋Š” ๋ฐ ๋„์›€์„ ์ค„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์ƒคํ”„ ์ง€์ˆ˜ (Sharpe Ratio): ์ฃผ์‹์˜ ์ˆ˜์ต๋ฅ ๊ณผ ๋ณ€๋™์„ฑ์„ ๋ฐ”ํƒ•์œผ๋กœ ์ƒคํ”„ ์ง€์ˆ˜๋ฅผ ๊ณ„์‚ฐํ•ด ์ œ๊ณตํ•จ์œผ๋กœ์จ ๋ฆฌ์Šคํฌ ๋Œ€๋น„ ์ˆ˜์ต๋ฅ ์„ ํ‰๊ฐ€ํ•˜๋Š” ๋ฐ ๋„์›€์„ ์ค„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ๋ถ„์‚ฐ ํˆฌ์ž ์ถ”์ฒœ: ์ฃผ์‹ ์™ธ์—๋„ ETF, ์ฑ„๊ถŒ ๋“ฑ ๋ถ„์‚ฐ๋œ ํˆฌ์ž ํฌํŠธํด๋ฆฌ์˜ค๋ฅผ ์ถ”์ฒœํ•ด ๋ฆฌ์Šคํฌ๋ฅผ ์ค„์ด๋Š” ์ „๋žต์„ ์ œ์•ˆํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

6. ์œ ์ € ๊ฐœ์ธํ™” ํ”ผ๋“œ๋ฐฑ ๋ฐ ํ•™์Šต ๊ธฐ๋Šฅ

  • ๊ฐœ์ธํ™”๋œ ํˆฌ์ž ์กฐ์–ธ: ์‚ฌ์šฉ์ž์˜ ํˆฌ์ž ์„ฑํ–ฅ์„ ๋ถ„์„ํ•ด ๊ฐœ์ธํ™”๋œ ํˆฌ์ž ์กฐ์–ธ์„ ์ œ๊ณตํ•ด ๋ณด์„ธ์š”. ์˜ˆ๋ฅผ ๋“ค์–ด, ์‚ฌ์šฉ์ž๊ฐ€ ์ฃผ์‹์˜ ๋ณ€๋™์„ฑ์„ ์„ ํ˜ธํ•˜์ง€ ์•Š๋Š”๋‹ค๋ฉด ์•ˆ์ •์ ์ธ ์ž์‚ฐ ์ถ”์ฒœ์„ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • ํ•™์Šต ์ž๋ฃŒ ์ œ๊ณต: ์ดˆ๋ณด ํˆฌ์ž์ž๋“ค์ด ๊ธฐ๋ณธ์ ์ธ ๊ธฐ์ˆ ์  ๋ถ„์„์ด๋‚˜ ์žฌ๋ฌด ๋ถ„์„์„ ์ดํ•ดํ•  ์ˆ˜ ์žˆ๋„๋ก ๊ด€๋ จ ํ•™์Šต ์ž๋ฃŒ๋‚˜ ๊ฐ„๋‹จํ•œ ํŠœํ† ๋ฆฌ์–ผ์„ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

7. ์‹œ์žฅ ๋Œ€๋น„ ์„ฑ๊ณผ ๋น„๊ต

  • ๋ฒค์น˜๋งˆํฌ ๋น„๊ต: ์‚ฌ์šฉ์ž๊ฐ€ ์„ ํƒํ•œ ์ฃผ์‹์˜ ์„ฑ๊ณผ๋ฅผ ์‹œ์žฅ ์ง€์ˆ˜(์˜ˆ: KOSPI, S&P 500)์™€ ๋น„๊ตํ•˜์—ฌ ํ•ด๋‹น ์ฃผ์‹์ด ์‹œ์žฅ ๋Œ€๋น„ ์–ผ๋งˆ๋‚˜ ์ข‹์€ ์„ฑ๊ณผ๋ฅผ ๋ƒˆ๋Š”์ง€ ํ•œ๋ˆˆ์— ๋ณผ ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์„ ์ถ”๊ฐ€ํ•ด ๋ณด์„ธ์š”.
  • ๋™์ข… ์—…๊ณ„ ๋น„๊ต: ๋™์ผ ์—…์ข…์˜ ๋‹ค๋ฅธ ์ฃผ์‹๊ณผ ๋น„๊ตํ•˜์—ฌ ํ•ด๋‹น ์ฃผ์‹์˜ ์ƒ๋Œ€์  ์œ„์น˜๋ฅผ ํ‰๊ฐ€ํ•  ์ˆ˜ ์žˆ๋„๋ก ์‹œ๊ฐํ™” ์ž๋ฃŒ๋ฅผ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

8. ์†Œ์…œ ๋ฏธ๋””์–ด ํŠธ๋ Œ๋“œ ๋ถ„์„

  • ํŠธ์œ„ํ„ฐ, Reddit, ๊ธฐํƒ€ SNS ๋ถ„์„: ํŠน์ • ์ฃผ์‹์— ๋Œ€ํ•œ ์†Œ์…œ ๋ฏธ๋””์–ด์˜ ๋ฐ˜์‘์„ ์ˆ˜์ง‘ํ•˜๊ณ  ์ด๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ํŠธ๋ Œ๋“œ๋ฅผ ์‹œ๊ฐํ™”ํ•˜์—ฌ ์‚ฌ์šฉ์ž์—๊ฒŒ ํŠธ๋ ˆ์ด๋”ฉ ์•„์ด๋””์–ด๋ฅผ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ฒฐ๋ก 

์ด๋Ÿฌํ•œ ๊ธฐ๋Šฅ๋“ค์€ ์ฃผ์‹์— ๋Œ€ํ•œ ์ดํ•ด๋„๋ฅผ ๋†’์ด๊ณ , ์‚ฌ์šฉ์ž๊ฐ€ ๋” ๋‚˜์€ ๊ฒฐ์ •์„ ๋‚ด๋ฆฌ๋Š” ๋ฐ ํฐ ๋„์›€์„ ์ค„ ์ˆ˜ ์žˆ์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์ถ”์ฒœ๋“œ๋ฆฐ ๊ธฐ๋Šฅ ์ค‘ ์ผ๋ถ€๋Š” ์‚ฌ์šฉ์ž ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ํ’๋ถ€ํ•˜๊ฒŒ ํ•˜๊ณ , ์ผ๋ถ€๋Š” ์‹ค์งˆ์ ์ธ ํˆฌ์ž ๊ฒฐ์ •์— ์ค‘์š”ํ•œ ํ†ต์ฐฐ์„ ์ค„ ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์—, ์ด๋“ค ์ค‘์—์„œ ์—ฌ๋Ÿฌ๋ถ„์˜ ํŒ€ ๋ชฉํ‘œ์™€ ์‚ฌ์šฉ์ž ๋‹ˆ์ฆˆ์— ๋งž๋Š” ๊ธฐ๋Šฅ์„ ์„ ํƒํ•ด ๋ณด์‹œ๋ฉด ์ข‹๊ฒ ์Šต๋‹ˆ๋‹ค.

์–ด๋–ค ๊ธฐ๋Šฅ์ด ์ œ์ผ ํฅ๋ฏธ๋กญ๊ฒŒ ๋Š๊ปด์ง€๋‚˜์š”? ๊ตฌ์ฒด์ ์œผ๋กœ ๊ตฌํ˜„ํ•ด๋ณด๊ณ  ์‹ถ์€ ๋ถ€๋ถ„์ด ์žˆ๋‹ค๋ฉด ์ถ”๊ฐ€์ ์ธ ์„ค๋ช…์ด๋‚˜ ์ฝ”๋“œ ์ƒ˜ํ”Œ๋„ ๋„์™€๋“œ๋ฆด ์ˆ˜ ์žˆ์–ด์š”!


It sounds like a great idea to enhance your Streamlit-based stock information website by incorporating an AI-driven recommendation system! Adding a "Buy" or "Sell" recommendation can add real value to users, making your platform more than just informational—it becomes a decision-making assistant. Here’s how you can go about it:

  1. Define the Scope of AI Recommendations:
    • Determine the features that your AI model will use to predict whether a stock is a buy, hold, or sell. Common features include historical stock prices, technical indicators (e.g., moving averages, RSI), volume, recent news sentiment, or other financial ratios.
  2. Collect Relevant Data:
    • You might need historical data for the stocks you're covering, including daily closing prices, volume, financial indicators, etc.
    • You can get financial data from APIs like Yahoo Finance (yfinance), Alpha Vantage, or Quandl.
    • If you plan to include news sentiment, you could use news APIs or scrape news websites to get recent articles and then perform sentiment analysis.
  3. Train the AI Model:
    • Algorithm: Start simple, with a machine learning model like a Random Forest Classifier or an SVM, which can be a good baseline for classification.
    • Alternatively, you could use a deep learning model if you have enough data or you want to try time series models (e.g., LSTMs).
    • Training Data: Collect data for many stocks, including historical price, volume, and other technical indicators, to train your model to recognize patterns indicative of buy or sell signals.
    • You can also use technical analysis metrics like RSI (Relative Strength Index) or MACD (Moving Average Convergence Divergence) to enhance your prediction capabilities.
  4. Integrate AI into the Streamlit App:
    • Use sklearn or other machine learning libraries to load your trained model.
    • Create an input section where users can provide data about a specific stock (e.g., recent trends, price history) or even allow them to select a stock and pull this data automatically.
    • Make predictions in real-time when a user selects a stock and display the recommendation using a "Buy", "Sell", or "Hold" indicator.
  5. Enhance User Experience:
    • Use Streamlit’s visualization capabilities to add charts and indicators that explain the AI's recommendation.
    • For instance, you could show the stock’s recent trends, highlight key technical indicators used, and display a probability score from the model to show how confident it is in the recommendation.
  6. Example Layout of the App:
    • Header: Brief introduction to what your website does.
    • Sidebar: Selection of the stock, date range, and other relevant filters.
    • Main Section:
      • Stock Information: Show general information about the selected stock, including historical performance and ์‹œ๊ฐํ™” using tools like matplotlib or plotly.
      • AI Recommendation: Show the recommendation (Buy, Sell, Hold) along with a confidence score.
      • Graphs: Plot the stock's recent trend, along with technical indicators that the model is using to make predictions.

Tools and Technologies

  • Data Collection: yfinance, Alpha Vantage API, Quandl.
  • Machine Learning Model: Python (scikit-learn, TensorFlow, or PyTorch).
  • Front-end: Streamlit for website building and visualization (matplotlib, plotly for charts).
  • Deployment: Deploy the Streamlit app using services like Heroku or Streamlit Cloud.

import streamlit as st
import yfinance as yf
from sklearn.externals import joblib

# Load pre-trained model
model = joblib.load('stock_model.pkl')

st.title('Stock Information and AI Recommendation')
stock_symbol = st.text_input('Enter Stock Symbol', 'AAPL')

if st.button('Get Stock Info and Recommendation'):
    stock_data = yf.Ticker(stock_symbol).history(period='1y')
    st.line_chart(stock_data['Close'])
    
    # Get some features for prediction (example)
    features = [stock_data['Close'].iloc[-1], stock_data['Volume'].iloc[-1]]
    recommendation = model.predict([features])[0]
    
    if recommendation == 1:
        st.write("**Recommendation: Buy**")
    elif recommendation == -1:
        st.write("**Recommendation: Sell**")
    else:
        st.write("**Recommendation: Hold**")
728x90
๋ฐ˜์‘ํ˜•
Comments