·µ»ØÁбí

ºÚÂí¾¯Ê¾Ö¸±ê¹«Ê½Éî¶È½âÎö£ºÍÚ¾òDZÔÚ·çÏÕ£¬½ÒʾÕæÏàµÄ¾ö²ß¹¤¾ß

[Ö¸±ê¹«Ê½]
2354355 Lv.2

רÀ¸

²é¿´:124 ÆÀÂÛ:1 ¸´ÖÆ ÏÔʾȫ²¿Â¥²ã µ¹Ðòä¯ÀÀ |
Ìøתµ½Ö¸¶¨Â¥²ã
ÉèÖÃ
¹ØÓÚºÚÂí¾¯Ê¾Ö¸±ê¹«Ê½µÄÉî¶È½âÎö£¬ÕâÊÇÒ»¸öΪͶ×ÊÕßÍÚ¾òDZÔÚ·çÏÕ¡¢½ÒʾÕæÏàµÄÖØÒª¾ö²ß¹¤¾ß¡£ÔÚ¹ÉƱÊг¡ÖУ¬ËùνµÄºÚÂí³£³£ÈÃÈËÄÑÒÔ×½Ãþ£¬µ«Æä±³ºóµÄ·çÏÕ¾¯Ê¾Ö¸±ê¹«Ê½È´ÄܽÒʾÕæÏà¡£
ÏÂÃæÊǺÚÂí¾¯Ê¾Ö¸±ê¹«Ê½µÄÂß¼­ºÍÔ´Âë½âÊÍ¡£
###½âÊÍ###£º·çÏÕÔ¤¾¯Ö¸±ê¹«Ê½£¬¹ÉƱͶ×Ê£¬ºÚÂíµÄÕæÏà  
  
Ò»¡¢ºÚÂí¾¯Ê¾Ö¸±ê¹«Ê½µÄÂß¼­·ÖÎö£º  

ºÚÂí¾¯Ê¾Ö¸±ê¹«Ê½ÊÇͨ¹ý¶Ô¹ÉƱÊг¡Êý¾ÝµÄÉî¶ÈÍÚ¾òºÍ·ÖÎö£¬´Ó¶øÔ¤²â¿ÉÄÜ´æÔڵķçÏÕ£¬²¢ÌáÐÑͶ×ÊÕß×¢ÒâDZÔÚ·çÏÕµÄÒ»ÖÖ¹¤¾ßËüͨ¹ýÌض¨µÄËã·¨ºÍÄ£ÐÍ£¬½«Êг¡Êý¾Ý½øÐзÖÀàºÍÆÀ¹À£¬×îÖյóöÒ»¸ö¹ØÓÚ·çÏÕÔ¤¾¯µÄÖ¸±êÖµ¸ÃÖ¸±êÖµµÄ¸ßµÍ¿ÉÒÔ·´Ó³¹ÉƱÊг¡µÄÎȶ¨ÐÔÓ밲ȫÐÔºÚÂí¾¯Ê¾Ö¸±ê¹«Ê½¹Ø×¢µÄÊÇÕûÌåÊг¡·çÏÕ¶ø²»Êǵ¥Ò»¹ÉƱ£¬¸üÈ«ÃæµØ²¶×½Êг¡·çÏÕ¶ÔÓÚ¹ÉƱµÄͶ»úÕßÀ´Ëµ£¬¾ßÓÐÇ°Õ°ÐԵľ¯Ê¾Ö¸±êÄܹ»¸üºÃµØ°ÑÎÕÊг¡µÄÂö²«£¬¼°Ê±¹æ±ÜDZÔÚ·çÏÕ
¶þ¡¢ºÚÂí¾¯Ê¾Ö¸±ê¹«Ê½µÄÔ´Âë½âÎö£º  
ºÚÂí¾¯Ê¾Ö¸±ê¹«Ê½¿ÉÒÔͨ¹ý¶àÖÖÈí¼þº¯ÊýʵÏÖÒÔÏÂÊÇÒ»¸ö¼ò»¯°æµÄÔ´ÂëʾÀý£¨¼ÙÉèʹÓõÄÊÇPythonÓïÑÔ£©£º

# ÒýÈë±ØÒªµÄ¿â
import pandas as pd
import numpy as np
import datetime as dt
from statsmodels.tsa.stattools import rolling_mean, rolling_std
from sklearn.linear_model import LinearRegression

# ¼ÓÔعÉƱÊý¾Ý
data = pd.read_csv('stock_data.csv')

# ¶¨ÒåºÚÂí¾¯Ê¾Ö¸±êº¯Êý
def black_horse_warning(data, window_size=20):
    # ¼ÆËãÒƶ¯Æ½¾ùÏߣ¨´ú±í³¤ÆÚÇ÷ÊÆ£©
    rolling_avg = rolling_mean(data['Close'], window=window_size)
    # ¼ÆËãÒƶ¯±ê×¼²î£¨´ú±í¶ÌÆÚ²¨¶¯£©
    rolling_std_dev = rolling_std(data['Close'], window=window_size)
    # ¹¹½¨ÏßÐԻعéÄ£ÐÍÔ¤²â¹É¼ÛÇ÷ÊÆ
    model = LinearRegression().fit(pd.DataFrame({'time': data['Date']}), data['Close'])
    # ¼ÆËãÔ¤²âÎó²î£¨²Ð²î£©
    residuals = data['Close'] - model.predict(pd.DataFrame({'time': data['Date']}))
    # ¸ù¾ÝÒƶ¯Æ½¾ùÏß¡¢Òƶ¯±ê×¼²îºÍ²Ð²î¼ÆËã·çÏÕÔ¤¾¯Ö¸±êÖµ
    warning_index = np.sqrt((rolling_std_dev2) (residuals2))
    return warning_index

# ʹÓú¯Êý¼ÆËã·çÏÕÔ¤¾¯Ö¸±êÖµ²¢±£´æ½á¹û
warning_index = black_horse_warning(data)
data['Warning_Index'] = warning_index
data.to_csv('stock_data_with_warning_index.csv')
  
ÔÚÕâ¸ö¼òµ¥µÄʾÀýÖУ¬ºÚÂí¾¯Ê¾Ö¸±ê¹«Ê½µÄ¼ÆËãÖ÷Òª°üÀ¨ÁËÒƶ¯Æ½¾ùÏß¼ÆËã¡¢Òƶ¯±ê×¼²î¼ÆËãÒÔ¼°»ùÓÚÏßÐԻعéÄ£Ð͵ÄÔ¤²âÎó²î¼ÆËãÈ»ºó»ùÓÚÕâÈý¸ö½á¹ûÀ´¼ÆËã·çÏÕÔ¤¾¯Ö¸±êÖµ
Èý¡¢  
#ºÚÂí¾¯Ê¾Ö¸±ê¹«Ê½ #·çÏÕÔ¤¾¯ #¹ÉƱÊг ¡#Êý¾ÝÍÚ¾ò #·çÏÕ·ÖÎö #¾ö²ß¹¤¾ß #¹ÉÊÐͶ×Ê #Òƶ¯Æ½¾ùÏß #Òƶ¯±ê×¼²î #ÏßÐԻعéÄ£ÐÍ
944.middle
2099944 Lv.3

רÀ¸

·¢±íÓÚ:2024-6-25 08:48 ¸´ÖÆ ²é¿´È«²¿Â¥²ã ÆÁ±Î
´ò°åµÄµÚÒ»µÀÐÄÀíÕÏ°­ÊÇÄã±ØÐëÏû³ýÄãÏà±ÈÓÚ±ðÈ˵ÄÓÅÔ½¸Ð¡£
ÄúÐèÒªµÇ¼ºó²Å¿ÉÒÔ»ØÌû µÇ¼

±¾°æ»ý·Ö¹æÔò ¡¶ÀíÏëÂÛ̳·þÎñЭÒé¡·¼° ¡¶ÃâÔðÉùÃ÷¡·¡£

Â¥Ö÷
2Â¥
¹ã¸æ
¹ã¸æ
Õ¾³¤ÍƼö /2

×îÐÂÖ÷Ìâ