def test_add_group(self): subject = u'组名' subtitle = u'子标题' subtitle2 = u'首页子标题' description = u'描述' create_time = datetime.now() update_time = datetime.now() reason = u'组合理由' highlight = u'组合亮点' reason_update = u'更新理由' related = u'相关说明' group = Group.add(subject, subtitle, subtitle2, description, create_time, update_time, reason, highlight, reason_update, related) self.assertTrue(group) self.assertEqual(group.subject, subject) self.assertEqual(group.subtitle, subtitle) self.assertEqual(group.subtitle2, subtitle2) self.assertEqual(group.description, description) self.assertEqual(group.create_time.date(), create_time.date()) self.assertEqual(group.update_time.date(), update_time.date()) self.assertEqual(group.reason, reason) self.assertEqual(group.highlight, highlight) self.assertEqual(group.reason_update, reason_update) self.assertEqual(group.related, related)
def detail(id, follow=False): cur_path = 'fund' group = Group.get(id) funds = group.get_funds_m2m() if g.user: is_liked = Subscription.is_like(group.id, g.user.id) if not group: return redirect('/') # 读取周报 weeklys = FundWeekly.get_articles_by_category(category=group.id, limit=2) return render_template('fund/detail.html', **locals())
def income_user_chart2(): """ 取得用户的基金组合关注收益率 for new chart """ if not g.user: return jsonify(r=False) likes = Subscription.get_by_user(g.user.id) info = [] incomes = [] jincomes = {} for like in likes: least_income = None incomes = IncomeUser.get_near_day(like.group_id, g.user.id, 7)[::-1] for income in incomes: key = str(income.day)[5:].replace('-', '/') if not jincomes.get(key): jincomes[key] = {} jincomes[key][str(income.group_id)] = income.income least_income = income.income group = Group.get(like.group_id) arts = FundWeekly.get_articles_by_category(category=group.id, limit=1) if len(arts): group.article = arts[0] gjson = { 'group_id': like.group_id, 'group_subject': group.subject, # 'group_total_income': group.total_income, 'like_date': like.create_time.strftime('%Y.%m.%d'), 'group_yesterday_income': group.yesterday_income, 'group_created': group.create_time.strftime('%Y.%m.%d'), 'group_income': least_income, 'group_article': group.article.id if hasattr(group, 'article') else None, 'group_article_read': group.article.has_read(g.user.id) if hasattr(group, 'article') else None, } info.append(gjson) return jsonify(r=True, info=info, incomes=jincomes)
def income_user_chart(): """ 取得用户的基金组合关注收益率 """ if not g.user: return jsonify(r=False) likes = Subscription.get_by_user(g.user.id) user_incomes = [] for like in likes: incomes = IncomeUser.get_near_day(like.group_id, g.user.id, 7)[::-1] group = Group.get(like.group_id) arts = FundWeekly.get_articles_by_category(category=group.id, limit=1) if len(arts): group.article = arts[0] like_income = { 'like_date': like.create_time.strftime('%Y.%m.%d'), 'group_id': like.group_id, 'group_subject': group.subject, # 'group_total_income': group.total_income, 'group_yesterday_income': group.yesterday_income, 'group_created': group.create_time.strftime('%Y.%m.%d'), 'group_article': group.article.id if hasattr(group, 'article') else None, 'group_article_read': group.article.has_read(g.user.id) if hasattr(group, 'article') else None, 'data': [], } for income in incomes: like_income['data'].append({ 'id': income.id, 'group_id': income.group_id, 'day': income.day.strftime('%Y-%m-%d'), 'income': income.income }) user_incomes.append(like_income) return jsonify(r=True, incomes=user_incomes)
def income_chart(group_id): """ 取得一个基金组合的收益率 """ incomes = Income.get_near_day(group_id, 1000)[::-1] group = Group.get(group_id) data = [] least_income = 0 for income in incomes: data.append({ 'id': income.id, 'group_id': income.group_id, 'day': income.day.strftime('%Y-%m-%d'), 'income': income.income, 'income_stock': income.income_stock, }) least_income = income.income return jsonify(r=True, data=data, group_subject=group.subject, group_created=group.create_time.strftime('%Y-%m-%d'), group_income=least_income)
def home(): cur_path = 'fund' groups_without_like = Group.paginate() user_like_count = Subscription.get_user_count() if not g.user: return render_template('fund/index.html', **locals()) # 取用户like的组合 likes = Subscription.get_by_user(g.user.id) groups = [] for group in groups_without_like: group.is_liked = False arts = FundWeekly.get_articles_by_category(category=group.id, limit=1) if len(arts): group.article = arts[0] for like in likes: if str(group.id) == str(like.group_id): group.is_liked = True break groups.append(group) return render_template('fund/user.html', **locals())
def main(): """计算历史收益""" client = MassClient(MASS_API_URL, MASS_API_TOKEN) groups = Group.paginate() for group in groups: compute_history_income(group, client)
from datetime import datetime from core.models.fund.group import Group from core.models.fund.fund import Fund from core.models.fund.income import Income if __name__ == '__main__': g1 = Group.add( u"主题精选", u"基金投资组合", u"充分参与3-5个优势主题,灵活规避单一板块波动风险", u"国企改革、一带一路、互联网+等众多主题基金短期波动剧烈,主题精选同时" u"把握多个未来潜力主题,规避单一板块波动风险,尽享市场收益。", datetime(year=2014, month=12, day=31), datetime(year=2014, month=12, day=31), u"好规划基金研究团队通过对市场趋势与热点机会深入研究,把握不同热门主题" u"的轮动规律,精选最适合当前市场的主题构建组合。并紧跟市场变化,及时动" u"态调整组合配置,分享主题收益,充分规避风险。", u"同时参与到一带一路、医药医疗、国企改革、并购重组、信息产业五大主题的" u"基金投资中,充分享受市场利好", u"结合近期对市场主题轮动规律的深入研究,“主题精选”组合优选“国企改革”、" u"“一带一路”、“互联网+”、“重组概念”、“医药”等五大主题,并筛选相关主题" u"概念下,具备优势的基金产品。", u"经济转型、改革提速的大背景下,主题型热点机会突出,但主题型行情分布广" u"泛,且单一主题阶段性特征鲜明,波动幅度巨大,而且,同一主题下的基金产" u"品同样差异悬殊,普通投资者难于把握。“主题精选”组合为您精选未来市场最" u"具优势的投资主题,并结合市场变化,及时动态调整,而且帮您优选相关主题" u"下最具优势的基金,让您充分分享牛市下的主题盛宴。") g1.add_fund(Fund.add(u'470006', u'汇添富医药'), u"医药主题基金,国内医药行业长期投资价值突出,该基金在医药主题基金中具" u"备优势。") g1.add_fund(Fund.add(u'100056', u'富国低碳环保'), u"虽名为低碳环保主题基金,但所投主题阶段调整较大,基金经历在主题机会把" u"握及股票选择方面,均展现出突出的能力。") g1.add_fund(Fund.add(u'000925', u'汇添富外延增长主题'),
params = (day,) db.execute(sql, params) db.commit() def clear_income_user_by_date(day): sql = 'delete from funcombo_income_user where day=%s' params = (day,) db.execute(sql, params) db.commit() def update_net_worth(group, client): sql = ('select id, day from funcombo_income' ' where group_id=%s and net_worth<0.000001') params = (group.id) rs = db.execute(sql, params) for x in rs: net_worth = compute_net_worth(group, x[1], client) sql = 'update funcombo_income set net_worth=%s where id=%s' params = (net_worth, x[0]) db.execute(sql, params) db.commit() if __name__ == '__main__': client = MassClient(MASS_API_URL, MASS_API_TOKEN) groups = Group.paginate() for group in groups: update_net_worth(group, client) clear_income_cache(group)