def fund_nav_str_view(request, p_fund_id, p_year): try: t_fund = FundClearInfoModel.get_fund(p_fund_id) t_fdata = FundClearDataModel.get_by_key_name( FundClearDataModel.compose_key_name(p_fund_id, p_year), t_fund) nav_dict = t_fdata._get_nav_dict() nav_dict = collections.OrderedDict(sorted(nav_dict.items())) nav_info = '' for t_key, t_entry in nav_dict.items(): nav_info += '{}:{}<br>\n'.format(t_key, t_entry) next_year = int(p_year) - 1 t_fdata = FundClearDataModel.get_by_key_name( FundClearDataModel.compose_key_name(p_fund_id, next_year), t_fund) if t_fdata is None or len(t_fdata._get_nav_dict()) == 0: next_year_link = 'NAV End' else: next_year_link = '<a href="/mf/fc/nav_str/{}/{}/">{}</a>'.format( p_fund_id, next_year, 'next') args = { 'tpl_section_title': 'fund {} year {}, {}'.format(p_fund_id, p_year, next_year_link), 'tpl_info': nav_info, } return render_to_response('mf_simple_info.tpl.html', args) except Exception, e: err_msg = 'fund_nav_str_view ERROR: {}'.format(e) logging.error(err_msg) args = { 'tpl_info': err_msg, } return render_to_response('mf_simple_info.tpl.html', args)
def reload_funddata_taskhandler(request): ''' reload task should delete all existing entity and then start a download all task ''' try: response = HttpResponse('reload_funddata_taskhandler') p_fund_id = str(request.REQUEST['PARAM1']) t_fund = FundClearInfoModel.get_fund(p_fund_id) for t_data in FundClearDataModel.all().ancestor(t_fund): logging.debug( 'reload_funddata_taskhandler: remove FundClearDataModel key {}' .format(t_data.key().name())) t_data.delete() taskqueue.add( method='GET', url=get_update_funddata_taskhandler_url(p_fund_id=p_fund_id, p_type='all'), countdown=3, ) logging.debug( 'reload_funddata_taskhandler: add update task for {}'.format( p_fund_id)) response.status_code = httplib.OK return response except Exception, e: err_msg = '{}'.format(e) logging.error('reload_funddata_taskhandler ERROR: {}'.format(err_msg)) response.status_code = httplib.INTERNAL_SERVER_ERROR return response
def current_nav(request, p_fund_id): ''' get func latest NAV with id p_fund_id ''' t_fund = FundClearInfoModel.get_fund(p_fund_id) t_list = t_fund.get_value_list() return HttpResponse(t_list[-1][1])
def get(self, request, p_fund_id, p_year, *args, **kwargs): t_fund = FundClearInfoModel.get_fund(p_fund_id) t_fdata = FundClearDataModel.get_by_key_name( FundClearDataModel.compose_key_name(p_fund_id, p_year), t_fund) nav_dict = t_fdata._get_nav_dict() nav_dict = collections.OrderedDict(sorted(nav_dict.items())) json_nav = [[key, nav_dict[key][1]] for key in nav_dict] return HttpResponse(json.dumps(json_nav, indent=2))
def fc2_review_update_taskhandler(request): response = HttpResponse('fc2_review_update_taskhandler') try: f_fund_id = request.REQUEST['PARAM1'] t_fund = FundClearInfoModel.get_fund(f_fund_id) t_fund.load_all_nav() IndexReviewModel._update_review(t_fund) response.status_code = httplib.OK except Exception, e: response.status_code = httplib.INTERNAL_SERVER_ERROR logging.error('fc2_review_update_taskhandler exception: {msg}'.format( msg=str(e)))
def bb_view(request, p_fund_id, p_b_type=BB_TYPE_DAILY, p_timeframe=None, p_sdw=None, p_month=18): t_fund = FundClearInfoModel.get_fund(p_fund_id) if p_b_type == BB_TYPE_DAILY: if p_timeframe is None: p_timeframe = 130 p_sdw = 100 p_month = 6 t_date_since = date.today() + relativedelta(months=-(p_month * 2)) year_since = t_date_since.year t_fund.get_value_list(year_since) else: if p_timeframe is None: p_timeframe = 26 p_sdw = 100 p_month = 12 return bb_tool._bb_view(t_fund, t_fund.title, p_b_type, p_timeframe, p_sdw, p_month)
def get_mfreport_by_id(cls, p_fund_id, p_currency_type): report = MFReport(fund_id=p_fund_id, currency_type=p_currency_type) report.m_fund = FundClearInfoModel.get_fund( p_fund_id) # FundClearModel.get_fund(report.fund_id) report.m_exchange = bot_ex.BotExchangeInfoModel.get_bot_exchange( bot_ex.CURRENCY_JPY) if report.m_fund is None or report.m_exchange is None: logging.warning( __name__ + ', get_mfreport_by_id: fund or exchange data download fail!!!') return None report.report_nav = report.m_fund.get_sample_value_list( report._sample_date_list) report.report_exchange = report.m_exchange.get_sample_value_list( report._sample_date_list) report._get_history_cost_n_share_report() report._get_history_market_value_report() return report
def _bb_view(p_fund_id, p_b_type, p_timeframe, p_sdw): func = '{} {}'.format(__name__, '_bb_view') t_fund = FundClearInfoModel.get_fund(p_fund_id) if p_b_type == BB_TYPE_DAILY: BB_VIEW_MONTHS = 7 t_date_since = date.today() + relativedelta( months=-(BB_VIEW_MONTHS * 2)) year_since = t_date_since.year t_value_list = t_fund.get_value_list(year_since) else: #-> BB_TYPE_WEEKLY BB_VIEW_MONTHS = 14 t_date_since = date.today() + relativedelta( months=-(2 * BB_VIEW_MONTHS)) t_offset = 2 - t_date_since.weekday() t_date_since += relativedelta(days=t_offset) t_date_list = [] while t_date_since <= date.today(): t_date_list.append(t_date_since) t_date_since += relativedelta(days=+7) t_value_list = t_fund.get_sample_value_list(t_date_list) sma, tb1, tb2, bb1, bb2 = get_bollingerbands(t_value_list, p_timeframe, float(p_sdw) / 100) t_content_heads = ['Date', 'NAV', 'BB2', 'BB1', 'SMA', 'TB1', 'TB2'] t_content_rows = {} t_lastdate = t_value_list[-1][0] t_view_date_since = date.today() + relativedelta(months=-BB_VIEW_MONTHS) t_ndx = 0 for ndx2, t_list in enumerate([t_value_list, bb2, bb1, sma, tb1, tb2]): for ndx, t_entry in enumerate(t_list): if t_entry[0] < t_view_date_since: t_ndx = ndx else: t_key = t_entry[0].strftime('%Y%m%d') if t_key in t_content_rows.keys(): t_content_rows[t_entry[0].strftime("%Y%m%d")] += [ '{:.2f}'.format(t_entry[1]) ] else: t_content_rows[t_entry[0].strftime("%Y%m%d")] = [ t_entry[0].strftime("%Y/%m/%d"), t_entry[1] ] t_entry[0] = calendar.timegm((t_entry[0]).timetuple()) * 1000 del t_list[:(t_ndx + 1)] t_content_rows = collections.OrderedDict(sorted(t_content_rows.items())) t_keys = sorted(t_content_rows.keys()) for i in range(5): t_key_1, t_key_2 = t_keys[-i - 1], t_keys[-i - 2] #-> add % for NAV t_value_1 = float(t_content_rows[t_key_1][1]) t_value_2 = float(t_content_rows[t_key_2][1]) if t_value_2 != 0: t_content_rows[t_key_1][1] = '{} ({:.2%})'.format( t_value_1, ((t_value_1 / t_value_2) - 1)) #-> add % for SMA t_value_1 = float(t_content_rows[t_key_1][4]) t_value_2 = float(t_content_rows[t_key_2][4]) if t_value_2 != 0: t_content_rows[t_key_1][4] = '{} ({:.2%})'.format( t_value_1, ((t_value_1 / t_value_2) - 1)) #-> add bb width t_value_1 = float(t_content_rows[t_key_1][2]) t_value_2 = float(t_content_rows[t_key_1][6]) t_content_rows[t_key_1][6] = '{} (BW:{})'.format( t_value_2, (t_value_2 - t_value_1)) tbl_content = { 'heads': t_content_heads, 'rows': reversed(t_content_rows.values()), } t_label = ' lastDate:{}, {},TF:{},SDW:{}'.format(str(t_lastdate), p_b_type, p_timeframe, p_sdw) plot = { 'data': '{data: ' + str(sma).replace('L', '') + \ ', label: "' + t_label + '", color: "black", lines: {show: true}, yaxis: 4},' + \ '{data: ' + str(t_value_list).replace('L', '') + \ ', color: "blue", lines: {show: true}, yaxis: 4},' + \ '{data: ' + str(tb1).replace('L', '') + \ ', color: "red", lines: {show: true}, yaxis: 4},' + \ '{data: ' + str(tb2).replace('L', '') + \ ', color: "purple", lines: {show: true}, yaxis: 4},' + \ '{data: ' + str(bb1).replace('L', '') + \ ', color: "red", lines: {show: true}, yaxis: 4},' + \ '{data: ' + str(bb2).replace('L', '') + \ ', color: "purple", lines: {show: true}, yaxis: 4},' } args = { 'tpl_img_header': t_fund.title, # FundCodeModel.get_fundname(p_fund_id), 'plot': plot, 'tpl_section_title': 'Fund {} View ;{}; TF:{}; SD_W: {}'.format(p_b_type, p_fund_id, p_timeframe, p_sdw), 'tbl_content': tbl_content, } return render_to_response('mf_simple_flot.tpl.html', args)
def nav_view(request, p_fund_id): f_fund_id = p_fund_id t_fund = FundClearInfoModel.get_fund(f_fund_id) year_since = date.today().year - 3 t_fund.get_value_list(year_since) IndexReviewModel._update_review(t_fund) t_review = IndexReviewModel.get_index_review(t_fund) if t_review is None: args = { 'tpl_img_header': FundCodeModel.get_fundname(f_fund_id), } return render_to_response('mf_my_japan.tpl.html', args) t_content_heads = [] t_content_rows = {} t_nav_list = list(t_review.index_list()) for t_entry in t_nav_list: t_content_rows[t_entry[0].strftime('%Y%m%d')] = ( t_entry[0].strftime('%Y/%m/%d'), ) t_content_rows[t_entry[0].strftime('%Y%m%d')] += (t_entry[1], ) t_entry[0] = calendar.timegm((t_entry[0]).timetuple()) * 1000 t_content_heads.append('Date') t_content_heads.append('NAV') t_yoy_1_list = list(t_review.yoy_list(1)) for t_entry in t_yoy_1_list: t_content_rows[t_entry[0].strftime('%Y%m%d')] += ('{:.2f}%'.format( t_entry[1]), ) t_entry[0] = calendar.timegm((t_entry[0]).timetuple()) * 1000 t_content_heads.append('YoY_1') t_yoy_2_list = list(t_review.yoy_list(2)) for t_entry in t_yoy_2_list: t_content_rows[t_entry[0].strftime('%Y%m%d')] += ('{:.2f}%'.format( t_entry[1]), ) t_entry[0] = calendar.timegm((t_entry[0]).timetuple()) * 1000 t_content_heads.append('YoY_2') t_data_str = '' t_data_str += '{data: ' + str(t_nav_list).replace( 'L', '') + ', label:"NAV", yaxis: 4},' t_data_str += '{data: ' + str(t_yoy_1_list).replace( 'L', '') + ', label:"YoY_1", yaxis: 5},' t_data_str += '{data: ' + str(t_yoy_2_list).replace( 'L', '') + ', label:"YoY_2", yaxis: 5},' plot = { 'data': t_data_str, } t_content_rows = collections.OrderedDict(sorted(t_content_rows.items())) tbl_content = { 'heads': t_content_heads, 'rows': t_content_rows.values(), } args = { 'tpl_img_header': FundCodeModel.get_fundname(f_fund_id), 'tpl_section_title': _("HEAD_FUND_REVIEW"), #_("TITLE_NAV_REVIEW_DETAIL"), 'plot': plot, 'tbl_content': tbl_content, } return render_to_response('mf_my_japan.tpl.html', args)