Exemplo n.º 1
0
@author: Administrator
"""
from sklearn.ensemble import RandomForestClassifier
import pandas as pd
import talib as ta
import sys
local_path = 'C://Users//Administrator/Desktop/'
if local_path not in sys.path:
    sys.path.append(local_path)
from get_data import data_reader as rd
from get_data import tic_toc

rf = RandomForestClassifier()

SS = rd.get_index_day('000905.SH', '2000-01-01', '2018-07-01', freq='1D')

target = []
pct = SS.sclose.pct_change().dropna()
v = pct.values

for i in v:

    if i > 0.01:
        target.append(3)

    elif i < -0.01:

        target.append(0)

    elif i > 0.5:
Exemplo n.º 2
0
import numpy as np
import sys
from sklearn import linear_model

read_path = r'C:\Users\Administrator\Desktop'
if read_path not in sys.path:
    sys.path.append(read_path)

from get_data import data_reader as rd

reg = linear_model.LinearRegression()

today = datetime.datetime.today()
today = str(today)[:10]

ss = rd.get_index_day('000001.SH', '2010-01-01', today, '1D')
ss_min = rd.get_index_min('000300.SH', '2010-01-01', today, '5min')

close = ss.sclose
Return = close.pct_change()
Return = pd.DataFrame(Return)


def regression(x):

    x = np.array(x)

    beta, alpha = np.polyfit(np.arange(len(x)), x, deg=1)

    return beta