task_fundPerformance.dos 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. module fundit::task_fundPerformance
  2. use fundit::fundCalculator
  3. use fundit::dataPuller
  4. use fundit::returnCalculator
  5. use fundit::indicatorCalculator
  6. /*
  7. * 定时任务:最新净值触发的业绩指标计算
  8. *
  9. * @param entityType <STRING>: 'MF', 'HF'...
  10. * @param date <DATETIME>: 净值更新时间
  11. *
  12. * TODO: 目前收益表在MySQL中,所以需要将计算的最新收益与MySQL中的历史数据合并
  13. */
  14. def calFundPerformance(entityType, date) {
  15. very_old_date = 1990.01.01;
  16. if(find(['HF', 'MF'], entityType) < 0) return null;
  17. // 取有最新净值变动的基金列表
  18. tb_cal_funds = get_entity_list_by_nav_updatetime(entityType, NULL, date, true);
  19. // 分批跑
  20. i = 0;
  21. batch_size = 1000;
  22. do {
  23. funds = tb_cal_funds[i:batch_size]
  24. // 计算月收益
  25. rets = mix_monthly_returns(entityType, funds);
  26. // TODO: 最新更新的收益存入数据库
  27. // 计算月度指标
  28. rets.rename!('cumulative_nav', 'nav');
  29. indicators = cal_monthly_indicators(entityType, 'PBI', rets);
  30. // TODO: 最新更新的指标存入数据库
  31. i += batch_size;
  32. } while (i < batch_size);
  33. // } while (i <= tb_cal_funds.size());
  34. return;
  35. }