Exemple #1
0
def Run(codes, task_id=0):
    from pypublish import publish
    pl = publish.Publish()
    df_year = stock.THS().df_year
    df_jll = stock.THS().df_jll
    #myredis.delKeys(myredis.enum.KEY_HISDAT_NO_FUQUAN)
    for code in codes:
        df = df_year[df_year['code'] == code]
        df_hisdat = stock.getHisdatDfRedis(code)
        history_syl = calc_history_syl(df, df_hisdat, 'year')
        ui.DrawTs(pl, history_syl, title=stock.GetCodeName(code).decode('utf8'))
        df = df_jll[df_jll['code'] == code]
        history_syl = calc_history_syl(df, df_hisdat, period='quarter')
        ui.DrawTs(pl, history_syl, title=stock.GetCodeName(code).decode('utf8'))
Exemple #2
0
 def _test1(self):
     t = stock.THS()
     df = t.df_jll
     code = '300033'
     df = df[df['code'] == code][df.columns[2]]
     #series
     df = df[df.map(lambda x: x.strip() != '')]
     df = df.astype(float)
     predict_jll(df)
Exemple #3
0
def SelectCodes():
    df_year = stock.THS().df_year
    df_year = df_year.ix['2010':'2016']
    #历史平均市盈率小于25且净利润逐年上升
    codes = stock.get_codes()
    codes = jbm.find_avg_syl(codes, df_year, 25)
    df_year = df_year[df_year['code'].map(lambda x: x in codes)]
    codes = jbm.find_jll_increase(df_year)
    #codes = agl.array_shuffle(codes)
    #max_row = min(len(codes)-1, 5)
    return codes
Exemple #4
0
 def test_find_avg_syl(self):
     #统计历史平均市盈率小于某值的个数
     scopre = [10, 15, 20, 30]
     nums = []
     codes = stock.get_codes()
     #codes = ['300033']
     df_jll = stock.THS().df_year
     for v in scopre:
         cur_codes = find_avg_syl(codes, df_jll, syl=v)
         print len(cur_codes)
         nums.append(len(cur_codes))
     ui.bar(pl, scopre, nums)
Exemple #5
0
#-*- coding:utf-8 -*-

"""boll分仓, 择时策略"""

import numpy as np
import pandas as pd, pylab as pl
import boll_pramid
import backtest_policy, stock, myenum, agl, account as ac, help, myredis, sign_observation as so, ui,jbm, stock_pinyin as jx
import os,warnings

agl.tic()

#ths = stock.createThs()
g_ths = stock.THS()	

class BollFenCangKline(boll_pramid.Strategy_Boll_Pre):
    """基于日线的boll分仓, 基本指标使用日线Boll以及日线Four"""
    def setParams(self, *args, **kwargs):
	self.base_num =	10000		#第一次买卖的数量    
	self.base_num_ratio = 0.1	#总资金的10%作为初始建仓, 与上一个变量两者可选, 注释该行使用绝对数量
	self.base_ratio	= 0.05		#盈亏区间的比率
	self.base_pramid_ratio = 3	#底部增仓比率
	self.base_rhombus_mid_ratio = 0.3	#仓位形态菱形的下部占比, 当资金不够时, 尽量保留一些资金
	self.base_four = [-0.5, 0.3]		#第一次买卖的技术指标阀值
	for k, v in kwargs.iteritems():
	    setattr(self, k, v)
    def OnFirstRun(self):
	self.key_sell_avg_price = 'BollFenCangKline.SellAvgPrice'+ str(os.getpid())
	self.key_sell_num = 'BollFenCangKline.SellNum'+ str(os.getpid())
	myredis.delKeys('BollFenCangKline')
	#只需要计算一次的数值