如何预估通胀率?通过央行数据来统计一波

1 前言

最近突然想统计下中国这些年的通胀率,然后就简单写了一个脚本,大致评估下近10年的通胀情况,跟预期结果差不多,平均8%左右的通胀率。

2 M2 定义

广义货币供应量(M2)是指流通于银行体系之外的现金加上企业存款、居民储蓄存款以及其他存款,它包括了一切可能成为现实购买力的货币形式,通常反映的是社会总需求变化和未来通胀的压力状态。近年来,很多国家都把M2作为货币供应量的调控目标。

3 近10年M2情况

年份期末余额(亿元人民币)
2022年期末2664320.84
2021年期末2382899.56
2020年期末2186795.89
2019年期末1986488.82
2018年期末1826744.22
2017年期末1690235.31
2016年期末1550066.67
2015年期末1392278.11
2014年期末1228374.81
2013年期末1106524.98
2012年期末974148.80

4 脚本统计增量和增长率

代码示例:

/**
 * <p>
 * 最近10年货币通胀率估算
 * <p>
 * 2022年期末   M2    2664320.84 (亿)
 * 2021年期末   M2    2382899.56
 * 2020年期末   M2    2186795.89
 * 2019年期末   M2    1986488.82
 * 2018年期末   M2    1826744.22
 * 2017年期末   M2    1690235.31
 * 2016年期末   M2    1550066.67
 * 2015年期末   M2    1392278.11
 * 2014年期末   M2    1228374.81
 * 2013年期末   M2    1106524.98
 * 2012年期末   M2    974148.80
 * <p/>
 *
 * @param args
 * @return void
 * @Date 2023/2/23 15:20
 */
public static void main(String[] args) {
    int startYear = 2012;
    int endYear = 2023;

    //最近10年货币通胀率估算
    List<Map<Integer, BigDecimal>> dataList = new ArrayList<>();
    Map<Integer, BigDecimal> map = new HashMap<>(16);
    map.put(2012, BigDecimal.valueOf(974148.80));
    map.put(2013, BigDecimal.valueOf(1106524.98));
    map.put(2014, BigDecimal.valueOf(1228374.81));
    map.put(2015, BigDecimal.valueOf(1392278.11));
    map.put(2016, BigDecimal.valueOf(1550066.67));
    map.put(2017, BigDecimal.valueOf(1690235.31));
    map.put(2018, BigDecimal.valueOf(1826744.22));
    map.put(2019, BigDecimal.valueOf(1986488.82));
    map.put(2020, BigDecimal.valueOf(2186795.89));
    map.put(2021, BigDecimal.valueOf(2382899.56));
    map.put(2022, BigDecimal.valueOf(2664320.84));
    dataList.add(map);

    //增速
    List<Map<Integer, String>> resultList = new ArrayList<>();
    Map<Integer, String> dealMap = new TreeMap<>();
    BigDecimal lastTempValue = BigDecimal.ZERO;
    for (int i = startYear; i < endYear; i++) {
        Map<Integer, BigDecimal> filterDataMap = dataList.get(0);
        for (Map.Entry<Integer, BigDecimal> entryMap : filterDataMap.entrySet()) {
            if (entryMap.getKey() != i) {
                continue;
            }

            BigDecimal currentValue = entryMap.getValue();
            if (i == 2012) {
                lastTempValue = currentValue;
                continue;
            }

            BigDecimal decimal = currentValue.subtract(lastTempValue).divide(lastTempValue, 8, RoundingMode.HALF_UP);
            dealMap.put(i, getPercentFormat(decimal));
            lastTempValue = currentValue;
        }
    }

    resultList.add(dealMap);
    System.out.println(JSON.toJSONString(resultList));
}

/**
 * <p>
 * Get amount in percentage format
 * <p/>
 *
 * @param bigDecimal
 * @return java.text.DecimalFormat
 * @Date 2021/12/9 21:44
 */
public static String getPercentFormat(BigDecimal bigDecimal) {
    //Create a percentage format for China
    NumberFormat perFormat = NumberFormat.getPercentInstance(Locale.CHINA);
    try {
        DecimalFormat percentFormat = (DecimalFormat) perFormat;
        //Setting the Pattern will invalidate the percentage format and the built-in format   percentFormat.applyPattern("##.00")
        //Set the minimum number of decimal places to 2
        percentFormat.setMinimumFractionDigits(2);
        return percentFormat.format(bigDecimal);
    } catch (Exception e) {
        log.error("Abnormal value conversion ", e);
    }

    return null;
}

public static class AscBigDecimalComparator implements Comparator<Map.Entry<Integer, String>> {
    //然后通过比较器来实现排序
    @Override
    public int compare(Map.Entry<Integer, String> o1, Map.Entry<Integer, String> o2) {
        return o1.getValue().compareTo(o2.getValue());
    }

}

5 执行结果

执行结果:

[{2013:"13.59%",2014:"11.01%",2015:"13.34%",2016:"11.33%",2017:"9.04%",2018:"8.08%",2019:"8.74%",2020:"10.08%",2021:"8.97%",2022:"11.81%"}]

6 图表展示

https://echarts.apache.org/examples/zh/editor.html?c=line-style

代码内容如下:

option = {
  xAxis: {
    type: 'category',
   data: ['2013', '2014', '2015', '2016', '2017', '2018', '2019', '2020', '2021', '2022']
  },
  yAxis: {
    type: 'value'
  },
  series: [
    {
      data: [13.59, 11.01, 13.34, 11.33, 9.04, 8.08, 8.74,10.08,8.97,11.81],
      type: 'line',
      symbol: 'triangle',
      symbolSize: 20,
      lineStyle: {
        color: '#5470C6',
        width: 4,
        type: 'dashed'
      },
      itemStyle: {
        borderWidth: 3,
        borderColor: '#EE6666',
        color: 'yellow'
      }
    }
  ]
};

效果如下:

在这里插入图片描述

在这里插入图片描述

写博客是为了记住自己容易忘记的东西,另外也是对自己工作的总结,希望尽自己的努力,做到更好,大家一起努力进步!

如果有什么问题,欢迎大家一起探讨,代码如有问题,欢迎各位大神指正!

给自己的梦想添加一双翅膀,让它可以在天空中自由自在的飞翔!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值