def __init__(self, strategy, index_code=None): """ :param strategy: 策略 :param index_code: index基准利率代码应该同tushare保持一致 sh 上证指数 sz 深圳成指 hs300 沪深300指数 sz50 上证50指数 zxb 中小板指数 cyb 创业板指数 :return: """ self.__baseRet_code = index_code self.__baseRet_data = None self.__currBaseRet = [] self.__last_baseRet = 0.0 self.__baseRet = dataseries.SequenceDataSeries() self.__betaRet = dataseries.SequenceDataSeries() self.__alphaRet = dataseries.SequenceDataSeries() self.__sharpeRet = dataseries.SequenceDataSeries() self.__LongestDrawDown = dataseries.SequenceDataSeries() self.__MaxDrawDown = dataseries.SequenceDataSeries() self.__ret_analyzer = returns.Returns() self.__sharpe_ratio = sharpe.SharpeRatio(False) self.__draw_down = drawdown.DrawDown() self.__beta = Beta() strategy.attachAnalyzer(self.__ret_analyzer) strategy.attachAnalyzer(self.__sharpe_ratio) strategy.attachAnalyzer(self.__draw_down) strategy.attachAnalyzer(self.__beta) strategy.attachAnalyzer(self)
from gamma import Gamma from inv_gamma import Inverse_gamma from student_t import Student_t from uniform import Uniform from numpy import array x = array([1.2, 1.5, 2.1, 5.4]) x2 = array([.1, .3, .4, .7]) mu, sigma, alpha, beta, k, gamma, d1, d2, kk, theta = [ 1.2, 2.3, .4, .5, 4, 3, 4, 6, 1.6, .7 ] lnorm = Lognorm(mu, sigma) norm = Normal(mu, sigma) beta = Beta(alpha, beta) chi = Chi(k) chi2 = Chi_square(k) exp = Exponential(gamma) f = F_dist(d1, d2) gamma = Gamma(kk, theta) invgamma = Inverse_gamma(mu, sigma) t = Student_t(d2) uniform = Uniform(alpha, d2) print 'lnorm.cdf(x): ', lnorm.cdf(x) print 'norm.cdf(x): ', norm.cdf(x) print 'beta.cdf(x2): ', beta.cdf(x2) print 'chi.cdf(x): ', chi.cdf(x) print 'chi2.cdf(x): ', chi2.cdf(x) print 'exp.cdf(x): ', exp.cdf(x)