2301_78298262 2023-05-30 16:59 采纳率: 0%
浏览 106

python 金融数据挖掘第9章 复习思考题2题,表9-5数据 贷款申请。

求python 金融数据挖掘第9章 复习思考题2的答案!问题如图img

img

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2023-05-30 20:48
    关注
    • 这篇博客: Python金融大数据分析——第5章 数据可视化 笔记中的 5.2 金融学图表 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
    • 金融数据的蜡烛图

      """
      # import matplotlib.finance as mpf # 这个方法过期了 
      # MatplotlibDeprecationWarning: The finance module has been deprecated in mpl 2.0 and will be removed in mpl 2.2. Please use the module mpl_finance instead. warnings.warn(message, mplDeprecation, stacklevel=1)
      # 要用下面的方法 import mpl_finance as mpf
      # 安装方法: >pip install https://github.com/matplotlib/mpl_finance/archive/master.zip
      """
      import mpl_finance as mpf
      
      # start = (2014, 5, 1)
      # end = (2014, 6, 30)
      # quotes = mpf._quotes_historical_yahoo('GDAXI', start, end)
      # 由于伟大的墙,调取不到国外的数据,这里用tushare获取600118中国卫星的数据
      import tushare as ts
      import datetime
      from matplotlib.pylab import date2num
      
      start = '2018-05-01'
      end = '2018-06-30'
      k_d = ts.get_k_data('600118', start, end, ktype='D')
      k_d.head()
      k_d.date = k_d.date.map(lambda x: date2num(datetime.datetime.strptime(x, '%Y-%m-%d')))
      quotes = k_d.values
      
      fig, ax = plt.subplots(figsize=(8, 5))
      fig.subplots_adjust(bottom=0.2)
      mpf.candlestick_ochl(ax, quotes, width=0.6, colorup='r', colordown='g', alpha=0.8)
      plt.grid(True)
      ax.xaxis_date()
      # dates on the x-axis
      ax.autoscale_view()
      plt.setp(plt.gca().get_xticklabels(), rotation=30)
      

      k_d.head()输入的结果:

       dateopenclosehighlowvolumecode
      772018-05-0223.0522.4523.1022.2590673.0600118
      782018-05-0322.3022.5222.5821.7178948.0600118
      792018-05-0422.5022.3522.5822.2158511.0600118
      802018-05-0722.4922.7022.7122.3058248.0600118
      812018-05-0822.8023.0723.4522.75115629.0600118

      最后的图片:
      金融数据的烛柱图
      金融数据每日摘要图表

      # 金融数据每日摘要图表
      fig, ax = plt.subplots(figsize=(8, 5))
      fig.subplots_adjust(bottom=0.2)
      mpf._plot_day_summary(ax, quotes, colorup='r', colordown='g')
      plt.grid(True)
      ax.xaxis_date()
      # dates on the x-axis
      ax.autoscale_view()
      plt.setp(plt.gca().get_xticklabels(), rotation=30)
      plt.title('金融数据每日摘要图表')
      

      金融数据每日摘要图表

      蜡烛图和成交量柱状图组合而成的图表

      # 蜡烛图和成交量柱状图组合而成的图表
      fig, (ax1, ax2) = plt.subplots(2, sharex=True, figsize=(8, 6))
      mpf.candlestick_ochl(ax1, quotes, width=0.6, colorup='r', colordown='g', alpha=0.8)
      ax1.set_title('中国卫星')
      ax1.set_ylabel('index level')
      plt.grid(True)
      ax1.xaxis_date()
      plt.bar(quotes[:,0],quotes[:,5],width=0.5)
      ax2.set_ylabel('volume')
      ax2.grid(True)
      plt.setp(plt.gca().get_xticklabels(), rotation=30)
      

      蜡烛图和成交量柱状图组合而成的图表

      ##5.3 3D绘图
      (模拟)隐含波动率的 3D 曲面图

      # 
      strike = np.linspace(50, 150, 24)
      ttm = np.linspace(0.5, 2.5, 24)
      strike, ttm = np.meshgrid(strike, ttm)
      iv = (strike - 100) ** 2 / (100 * strike) / ttm
      # generate fake implied volatilities
      
      from mpl_toolkits.mplot3d import Axes3D
      
      fig = plt.figure(figsize=(9, 6))
      ax = fig.gca(projection='3d')
      surf = ax.plot_surface(strike, ttm, iv, rstride=2, cstride=2, cmap=plt.cm.coolwarm, linewidth=0.5, antialiased=True)
      ax.set_xlabel('strike')
      ax.set_ylabel('time-to-maturity')
      ax.set_zlabel('implied volatility')
      fig.colorbar(surf, shrink=0.5, aspect=5)
      

      (模拟)隐含波动率的 3D 曲面图

      plot_surface参数

      参数描述
      X,Y,Z2D数组形式的数据值
      rstride数组行距(步长大小)
      cstride数组列距(步长大小)
      color曲面块颜色
      cmap曲面块颜色映射
      facecolors单独曲面块表面颜色
      norm将值映射为颜色的 Nonnalize实例
      vmin映射的最小值
      vmax映射的最大值

      (模拟)隐含波动率的 3D 散点图

      #(模拟)隐含波动率的 3D 散点图
      fig = plt.figure(figsize=(8, 5))
      ax = fig.add_subplot(111,projection='3d')
      ax.view_init(30,60)
      ax.scatter(strike, ttm, iv, zdir='z',s=25,c='b',marker='^')
      ax.set_xlabel('strike')
      ax.set_ylabel('time-to-maturity')
      ax.set_zlabel('implied volatility')
      

      这里写图片描述

      end

    评论

报告相同问题?

问题事件

  • 创建了问题 5月30日