Ejemplo n.º 1
0
 def test_get_nextday_factor(self):
     forecast_strategy.end_date = '20200930'
     forecast_strategy.pro = tn.get_pro()
     forecast_strategy.calender = forecast_strategy.get_calender('20150101')
     forecast_strategy.yeji_all, b = forecast_strategy.create_forecast_df(
         '20190101', '20200929', '20200930', True)
     result = forecast_strategy.read_result('./data/temp/r11.csv')
     yeji_today = forecast_strategy.read_yeji('./data/temp/yejitoday.csv')
     forecast_strategy.get_nextday_factor(yeji_today, result)
     self.fail()
Ejemplo n.º 2
0
    # yeji, X_test = train_test_split(yeji_all, test_size=0.01, random_state=0)
    """20160101~20180505, 20190617~2020824, 20180115~20191231"""
    start_date = '20160101'
    end_date = '20200904'

    today = '2020903'
    tomorrow = '2020904'

    # yeji_all = yeji_all[yeji_all['forecasttype'].isin(['扭亏'])]
    yeji = yeji_all[(yeji_all['ndate'] > tran_dateformat(start_date))
                    & (yeji_all['ndate'] < tran_dateformat(today))]
    yeji = yeji.drop_duplicates(subset=['instrument', 'ndate'])
    pred_tail = 1  # 公告发布日后pred_tail日收盘价卖出
    pred_head = 0  # 公告发布日后pred_head日开盘价买入

    pro = tn.get_pro()
    # calender = pro.trade_cal(exchange='', start_date=start_date, end_date=end_date)
    calender = get_calender()
    # update_data()
    dp_all = pd.read_csv('./data/dpzz500.csv', converters={'trade_date': str})

    positions = 80  # 单只持仓为15%
    max = 0
    max_pos = 0
    pos_rtn = pd.DataFrame(
        columns=['total_rtn', 'average_pos', 'max_draw_down', 'sharpe_ratio'])
    result = pd.DataFrame(columns=[
        'rtn', 'pure_rtn', 'zz500_rtn', 'net_rtn', 'in_date', 'out_date',
        'code', 'pub_date', 'sum_pure_return', 'forecasttype', 'zfpx',
        'positions'
    ])
Ejemplo n.º 3
0
import datetime
import time

import pandas as pd
from sqlalchemy import create_engine

from util import tunshare

engine = create_engine(
    'mysql+pymysql://root:myh123@localhost:3307/quant?charset=utf8',
    pool_recycle=1)
pro = tunshare.get_pro()


def get_stock_forecast_updatedate():
    global engine
    sql = "select act_pubtime from  quant.stock_forecast order by act_pubtime desc limit 1"
    return pd.read_sql(sql, engine).act_pubtime.values[0]


def get_stock_forecast_data(begin_date, end_date):
    global engine
    sql = f"select * from  quant.stock_forecast as a where a.publish_date between '{begin_date}' and '{end_date}' " \
          f"order by act_pubtime"
    return pd.read_sql(sql, engine)


def get_k_data(ts_code, start, end) -> pd.DataFrame:
    global engine
    sql = "SELECT * FROM quant.stock_daily where ts_code ='" + ts_code + "' and trade_date between '" + start + "' and '" + end + "'"
    df = pd.read_sql(sql, engine)
Ejemplo n.º 4
0
def get_append_head(start, end):
    df = ts.get_pro().moneyflow_hsgt(start_date=start, end_date=end)
    save_csv_noindex(df, '../data/fund/his/north/', 'north-dapan.csv', mod='a')