第一次绘制K线图与网络图

2020-08-06 14:50:19 浏览数 (1)

01

> library(quantmod) #加载quantmod包

载入需要的程辑包:xts

载入需要的程辑包:zoo

载入程辑包:‘zoo’

The following objects are masked from ‘package:base’:

as.Date, as.Date.numeric

载入需要的程辑包:TTR

Version 0.4-0 included new data defaults. See ?getSymbols.

Learn from a quantmod author: https://www.datacamp.com/courses/importing-and-managing-financial-data-in-r

> getSymbols('^SSEC',from='2011-01-01',to='2012-07-13') #getSymbols函数自动连接Yahoo数据源,读取的数据源是SSEC(上证指数Yahoo的代码),时间范围从2011-01-01到2012-07-13

‘getSymbols’ currently uses auto.assign=TRUE by default, but will

use auto.assign=FALSE in 0.5-0. You will still be able to use

‘loadSymbols’ to automatically load data. getOption("getSymbols.env")

and getOption("getSymbols.auto.assign") will still be checked for

alternate defaults.

This message is shown once per session and may be disabled by setting

options("getSymbols.warning4.0"=FALSE). See ?getSymbols for details.

WARNING: There have been significant changes to Yahoo Finance data.

Please see the Warning section of ‘?getSymbols.yahoo’ for details.

This message is shown once per session and may be disabled by setting

options("getSymbols.yahoo.warning"=FALSE).

[1] "SSEC"

> SSEC

SSEC.Open SSEC.High SSEC.Low SSEC.Close SSEC.Volume SSEC.Adjusted

2011-01-04 2825.329 2855.396 2810.108 2852.648 110000 2852.648

2011-01-05 2833.116 2850.493 2824.296 2839.221 104400 2839.221

2011-01-06 2838.435 2853.875 2816.951 2824.197 84800 2824.197

2011-01-07 2820.665 2868.005 2807.870 2838.801 113200 2838.801

2011-01-10 2832.622 2847.358 2786.861 2791.809 90800 2791.809

2011-01-11 2783.476 2810.762 2770.338 2804.047 80600 2804.047

2011-01-12 2811.785 2828.468 2788.130 2821.305 79200 2821.305

2011-01-13 2830.534 2837.526 2810.874 2827.712 74800 2827.712

2011-01-14 2817.048 2817.048 2780.438 2791.344 76800 2791.344

2011-01-17 2772.450 2780.942 2698.781 2706.660 92600 2706.660

2011-01-18 2696.147 2715.406 2683.367 2708.979 60400 2708.979

2011-01-19 2707.816 2759.602 2700.811 2758.097 78400 2758.097

2011-01-20 2752.799 2752.799 2676.129 2677.652 86000 2677.652

2011-01-21 2668.677 2746.178 2667.286 2715.294 95600 2715.294

2011-01-24 2716.524 2736.109 2690.652 2695.719 88000 2695.719

2011-01-25 2691.693 2701.044 2661.448 2677.432 69400 2677.432

2011-01-26 2677.172 2710.738 2676.769 2708.814 60800 2708.814

2011-01-27 2690.825 2753.001 2677.210 2749.150 105600 2749.150

2011-01-28 2741.314 2759.440 2733.291 2752.750 85400 2752.750

2011-01-31 2751.527 2790.921 2748.538 2790.694 91600 2790.694

2011-02-01 2795.071 2805.049 2785.296 2798.960 73400 2798.960

2011-02-09 2778.701 2804.208 2764.866 2774.065 87200 2774.065

2011-02-10 2769.646 2819.063 2760.175 2818.163 98000 2818.163

2011-02-11 2815.119 2835.411 2807.605 2827.328 107800 2827.328

2011-02-14 2828.571 2906.260 2828.571 2899.134 154200 2899.134

2011-02-15 2900.427 2934.467 2892.637 2899.237 152400 2899.237

2011-02-16 2893.682 2924.188 2882.549 2923.896 127800 2923.896

2011-02-17 2929.255 2939.284 2905.032 2926.964 130400 2926.964

2011-02-18 2924.230 2924.230 2890.262 2899.792 113800 2899.792

2011-02-21 2886.540 2932.820 2884.191 2932.246 118800 2932.246

2011-02-22 2941.318 2944.413 2851.620 2855.516 153000 2855.516

2011-02-23 2844.990 2868.484 2839.195 2862.635 111000 2862.635

2011-02-24 2861.393 2881.537 2854.563 2878.603 109800 2878.603

2011-02-25 2876.777 2890.324 2848.650 2878.565 100000 2878.565

2011-02-28 2880.170 2906.169 2861.817 2905.053 118800 2905.053

2011-03-01 2906.285 2931.580 2901.552 2918.920 136600 2918.920

2011-03-02 2905.514 2924.963 2883.566 2913.808 133400 2913.808

2011-03-03 2918.731 2937.557 2900.761 2902.978 150400 2902.978

2011-03-04 2902.190 2944.459 2898.084 2942.306 118200 2942.306

2011-03-07 2952.721 3000.429 2952.721 2996.211 160200 2996.211

2011-03-08 2996.727 3001.625 2976.600 2999.942 126600 2999.942

2011-03-09 3002.546 3012.044 2989.342 3002.154 124800 3002.154

2011-03-10 2995.768 2995.768 2954.367 2957.143 123800 2957.143

2011-03-11 2942.419 2966.980 2927.683 2933.796 116000 2933.796

2011-03-14 2923.982 2939.652 2914.458 2937.627 117000 2937.627

2011-03-15 2927.984 2927.984 2850.945 2896.256 155000 2896.256

2011-03-16 2894.252 2934.018 2894.252 2930.804 130800 2930.804

2011-03-17 2906.955 2935.625 2885.651 2897.298 137800 2897.298

2011-03-18 2920.806 2930.606 2900.872 2906.885 100600 2906.885

2011-03-21 2913.913 2927.073 2895.154 2909.137 96800 2909.137

2011-03-22 2917.687 2923.392 2884.751 2919.142 95200 2919.142

2011-03-23 2919.016 2950.422 2911.626 2948.477 112600 2948.477

2011-03-24 2949.850 2958.663 2942.134 2946.706 109000 2946.706

2011-03-25 2948.542 2985.083 2946.697 2977.814 136400 2977.814

2011-03-28 2985.356 3005.782 2979.196 2984.005 156000 2984.005

2011-03-29 2979.865 2994.174 2953.540 2958.077 168600 2958.077

2011-03-30 2955.453 2968.182 2935.747 2955.771 126400 2955.771

2011-03-31 2954.653 2961.630 2914.384 2928.111 109000 2928.111

2011-04-01 2932.481 2967.847 2924.394 2967.410 99800 2967.410

2011-04-06 2964.212 3005.238 2963.899 3001.360 141600 3001.360

2011-04-07 3003.204 3012.288 2990.311 3007.909 124800 3007.909

2011-04-08 3005.368 3031.097 2998.340 3030.021 114400 3030.021

2011-04-11 3037.910 3059.567 3019.885 3022.746 147200 3022.746

2011-04-12 3012.795 3039.124 3003.445 3021.369 146000 3021.369

2011-04-13 3006.830 3050.401 2994.465 3050.397 128200 3050.397

2011-04-14 3049.667 3058.239 3036.726 3042.635 129400 3042.635

2011-04-15 3036.345 3062.530 3020.156 3050.526 128600 3050.526

2011-04-18 3040.531 3067.456 3037.189 3057.329 137400 3057.329

2011-04-19 3038.807 3038.807 2996.222 2999.041 141800 2999.041

2011-04-20 3005.975 3019.123 2992.672 3007.037 119800 3007.037

2011-04-21 3021.770 3035.471 3012.544 3026.667 121600 3026.667

2011-04-22 3025.698 3032.965 3004.465 3010.517 118600 3010.517

2011-04-25 3003.031 3003.610 2964.643 2964.951 117400 2964.951

2011-04-26 2956.949 2970.278 2931.502 2938.981 95200 2938.981

2011-04-27 2946.327 2961.133 2907.662 2925.408 105400 2925.408

2011-04-28 2937.947 2953.193 2884.839 2887.043 105200 2887.043

2011-04-29 2886.629 2913.556 2871.010 2911.510 87600 2911.510

2011-05-03 2911.510 2933.460 2890.225 2932.188 96400 2932.188

2011-05-04 2916.845 2916.970 2860.075 2866.017 111400 2866.017

2011-05-05 2854.768 2880.125 2849.910 2872.404 91000 2872.404

2011-05-06 2842.764 2881.706 2834.456 2863.886 91000 2863.886

2011-05-09 2868.235 2885.178 2861.419 2872.460 81600 2872.460

2011-05-10 2876.980 2891.034 2865.104 2890.634 81200 2890.634

2011-05-11 2890.353 2897.141 2868.349 2883.420 92400 2883.420

2011-05-12 2864.976 2876.448 2843.097 2844.083 100200 2844.083

2011-05-13 2846.311 2871.992 2832.254 2871.031 93200 2871.031

2011-05-16 2864.377 2877.091 2846.306 2849.067 84600 2849.067

2011-05-17 2846.447 2869.230 2821.203 2852.773 94800 2852.773

2011-05-18 2846.725 2877.427 2843.676 2872.771 76800 2872.771

2011-05-19 2879.387 2884.141 2856.829 2859.574 77000 2859.574

2011-05-20 2858.311 2866.763 2850.445 2858.459 70800 2858.459

2011-05-23 2853.286 2853.286 2771.117 2774.569 98600 2774.569

2011-05-24 2766.059 2771.748 2744.777 2767.056 74800 2767.056

2011-05-25 2764.560 2771.177 2737.330 2741.741 74400 2741.741

2011-05-26 2755.394 2764.890 2734.536 2736.527 78800 2736.527

2011-05-27 2739.387 2746.842 2708.548 2709.947 82600 2709.947

2011-05-30 2704.485 2728.062 2689.206 2706.361 65200 2706.361

2011-05-31 2707.559 2744.934 2702.095 2743.472 68000 2743.472

2011-06-01 2737.057 2744.559 2726.495 2743.572 68600 2743.572

2011-06-02 2715.316 2727.995 2676.538 2705.181 86000 2705.181

2011-06-03 2701.773 2732.427 2701.250 2728.020 68000 2728.020

2011-06-07 2720.970 2745.770 2717.313 2744.300 65000 2744.300

2011-06-08 2742.042 2754.122 2715.250 2750.288 74200 2750.288

2011-06-09 2743.539 2747.332 2702.695 2703.345 83400 2703.345

2011-06-10 2696.130 2707.742 2672.320 2705.143 73400 2705.143

2011-06-13 2687.653 2703.423 2669.396 2700.379 63000 2700.379

2011-06-14 2696.223 2735.552 2691.671 2730.040 83000 2730.040

2011-06-15 2717.677 2730.476 2705.072 2705.431 74800 2705.431

2011-06-16 2685.632 2691.944 2663.120 2664.282 71000 2664.282

2011-06-17 2661.414 2675.027 2641.392 2642.818 64400 2642.818

2011-06-20 2635.834 2637.883 2610.990 2621.253 60000 2621.253

2011-06-21 2628.022 2648.024 2618.807 2646.483 64800 2646.483

2011-06-22 2648.534 2657.725 2633.474 2649.321 58400 2649.321

2011-06-23 2640.660 2693.417 2630.336 2688.249 73800 2688.249

2011-06-24 2678.052 2759.710 2674.303 2746.211 125800 2746.211

2011-06-27 2746.787 2769.042 2743.496 2758.230 101600 2758.230

2011-06-28 2759.713 2763.280 2736.398 2759.202 88200 2759.202

2011-06-29 2757.400 2759.231 2727.253 2728.483 88200 2728.483

2011-06-30 2729.992 2774.365 2729.992 2762.076 91000 2762.076

2011-07-01 2767.833 2778.668 2752.966 2759.362 92000 2759.362

2011-07-04 2770.940 2813.270 2770.940 2812.818 122000 2812.818

2011-07-05 2812.722 2818.141 2799.110 2816.354 110200 2816.354

2011-07-06 2811.815 2811.815 2780.729 2810.479 103200 2810.479

2011-07-07 2813.193 2825.123 2793.892 2794.267 116600 2794.267

2011-07-08 2797.026 2807.379 2784.125 2797.773 86200 2797.773

2011-07-11 2789.454 2807.322 2780.665 2802.692 86000 2802.692

2011-07-12 2783.722 2783.722 2752.186 2754.582 96600 2754.582

2011-07-13 2756.032 2797.266 2756.032 2795.476 92000 2795.476

2011-07-14 2798.212 2811.704 2788.982 2810.444 104600 2810.444

2011-07-15 2803.585 2821.339 2794.159 2820.169 107400 2820.169

2011-07-18 2821.358 2826.959 2807.108 2816.688 108200 2816.688

2011-07-19 2804.923 2809.315 2790.685 2796.983 92800 2796.983

2011-07-20 2810.436 2817.285 2779.381 2794.205 84000 2794.205

2011-07-21 2795.896 2799.852 2763.418 2765.894 81800 2765.894

2011-07-22 2769.863 2782.169 2763.800 2770.790 70200 2770.790

2011-07-25 2759.628 2759.628 2680.747 2688.746 111200 2688.746

2011-07-26 2685.754 2704.939 2677.119 2703.026 72800 2703.026

2011-07-27 2690.144 2726.802 2680.433 2723.492 80400 2723.492

2011-07-28 2701.771 2712.090 2684.661 2708.777 78400 2708.777

2011-07-29 2706.497 2721.530 2681.272 2701.729 75400 2701.729

2011-08-01 2697.575 2712.888 2688.529 2703.783 59000 2703.783

2011-08-02 2689.971 2689.971 2651.281 2679.259 70000 2679.259

2011-08-03 2659.118 2688.065 2654.364 2678.485 64000 2678.485

2011-08-04 2683.191 2698.815 2675.534 2684.039 58800 2684.039

2011-08-05 2620.277 2644.581 2605.136 2626.423 78600 2626.423

2011-08-08 2599.289 2614.190 2497.918 2526.816 110400 2526.816

2011-08-09 2468.032 2537.409 2437.680 2526.070 103800 2526.070

2011-08-10 2562.393 2579.156 2544.952 2549.176 100400 2549.176

2011-08-11 2508.857 2582.155 2505.012 2581.508 95600 2581.508

2011-08-12 2593.395 2605.447 2585.846 2593.173 97200 2593.173

2011-08-15 2598.138 2627.104 2584.407 2626.770 88600 2626.770

2011-08-16 2627.854 2636.360 2601.501 2608.166 85200 2608.166

2011-08-17 2603.961 2617.165 2596.039 2601.261 70200 2601.261

2011-08-18 2601.990 2603.485 2556.859 2559.472 71000 2559.472

2011-08-19 2519.645 2538.272 2513.754 2534.358 70600 2534.358

2011-08-22 2534.570 2553.415 2507.782 2515.863 61200 2515.863

2011-08-23 2524.877 2554.178 2514.949 2554.019 61000 2554.019

2011-08-24 2562.411 2569.278 2536.256 2541.091 65400 2541.091

2011-08-25 2546.402 2616.303 2545.054 2615.261 104600 2615.261

2011-08-26 2602.208 2616.636 2593.238 2612.188 77800 2612.188

2011-08-29 2595.466 2595.466 2570.844 2576.413 73600 2576.413

2011-08-30 2592.597 2615.135 2563.689 2566.595 76000 2566.595

2011-08-31 2566.529 2574.415 2545.096 2567.340 59200 2567.340

2011-09-01 2569.799 2584.804 2547.854 2556.042 57200 2556.042

2011-09-02 2551.556 2557.310 2517.618 2528.280 54400 2528.280

2011-09-05 2510.100 2510.100 2478.195 2478.739 55000 2478.739

[到达getOption("max.print") -- 略过205行]]

> SSEC[1,]

SSEC.Open SSEC.High SSEC.Low SSEC.Close SSEC.Volume SSEC.Adjusted

2011-01-04 2825.329 2855.396 2810.108 2852.648 110000 2852.648

> candleChart(last(SSEC,'4 months'),theme = chartTheme('white'),TA=NULL) #绘制K线图,时间是最近4个月,即4月到7月。主题使用白色蜡烛图,不使用其他技术指标(TA)

> addMACD() #添加MACD指标,使用默认参数

0

2

> library(igraph) #加载igraph包

载入程辑包:‘igraph’

The following objects are masked from ‘package:BiocGenerics’:

normalize, union

The following objects are masked from ‘package:stats’:

decompose, spectrum

The following object is masked from ‘package:base’:

union

> g <- barabasi.game(100,m=1)

>plot(g, #对象为g

vertex.size=4,#顶点大小设置4

vertex.label=NA,#顶点标签设置无

edge.arrow.size=0.1,#点连线之间的箭头大小

edge.color="grey40",#点之间连线的颜色设置

layout=layout.fruchterman.reingold,#整体布局

vertex.color="red",#顶点的颜色设置为红色

frame=TRUE#绘图包括整体边框)

注:以上内容均从高山《R语言与Bioconductor生物信息学应用》中所学

sse

0 人点赞