文档库 最新最全的文档下载
当前位置:文档库 › K线图

K线图

使用R语言绘制K线图

远目量化

K线图

最高价

最低价

收盘价

开盘价最高价

最低价

开盘价

收盘价红色蜡烛图(阳线)

绿色蜡烛图(阴线)

远目量化

chartSeries

library(quantmod)

getSymbols("GOOG",src="yahoo",from="2016‐01‐01", to='2016‐05‐30') chartSeries(GOOG)

橙色:收盘价低于开盘价绿色:收盘价高于开盘价背景:黑色

默认形式

导入包

library(quantmod)

远目量化

远目量化

library(package,

help, pos = 2, lib.loc = NULL,

character.only = FALSE, logical.return = FALSE, warn.conflicts = TRUE, quietly = FALSE,

verbose = getOption("verbose"))

package, help the name of a package, given as a name or literal character string, or a character string, depending on whethercharacter.only is FALSE (default) or TRUE).pos the position on the search list at which to attach the loaded namespace. Can also be the name of a position on the current search list as given by search ().lib.loc a character vector describing the location of R library trees to search through, or NULL. The default value of NULLcorresponds to all libraries currently known to .libPaths (). Non-existent library trees are silently ignored.

character.only a logical indicating whether package or help can be assumed to be character strings.logical.return logical. If it is TRUE,FALSE or TRUE is returned to indicate success.

warn.conflicts logical. If TRUE, warnings are printed about conflicts from attaching the new package. A conflict is a function masking a function, or a non-function masking a non-function.

verbose a logical. If TRUE, additional diagnostics are printed.

quietly

a logical. If TRUE, no message confirming package attaching is printed, and most often, no errors/warnings are printed if package attaching fails.

导入包

library

远目量化

quantmod

quantmod是由Jeffrey A.Ryan编写的一个关于金融分析的扩展包,利用它能够获得股票等相关资产的数据。这个包还提供了作图和金融分析工具。

导入包

getSymbols

getSymbols("GOOG",

src="yahoo",

from="2016‐01‐01",

to='2016‐05‐30')

远目量化

getSymbols

getSymbols(Symbols = NULL,

语法env = parent.frame(),

reload.Symbols = FALSE,

verbose = FALSE,

warnings = TRUE,

src = "yahoo",

symbol.lookup = TRUE,

auto.assign = getOption('getSymbols.auto.assign',TRUE), ...)

Symbols a character vector specifying the names of each symbol to be loaded

env where to create objects. Setting env=NULL is equal to auto.assign=FALSE

reload.Symbols boolean to reload current symbols in specified environment. (FALSE)

verbose boolean to turn on status of retrieval. (FALSE)

warnings boolean to turn on warnings. (TRUE)

src character string specifying sourcing method. (yahoo)

symbol.lookup retrieve symbol's sourcing method from external lookup (TRUE)

auto.assign should results be loaded to env If FALSE, return results instead. As of 0.4-0, this is the same as setting env=NULL. Defaults to TRUE

file.path character string of file location

...additional parameters

远目量化

chartSeries

chartSeries(GOOG)

远目量化

远目量化

chartSeries

library(quantmod)

getSymbols("GOOG",src="yahoo",from="2016‐01‐01", to='2016‐05‐30') chartSeries(GOOG)

橙色:收盘价低于开盘价绿色:收盘价高于开盘价背景:黑色

默认形式

chartSeries(x,

type = c("auto", "candlesticks", "matchsticks", "bars","line"),

subset = NULL,

show.grid = TRUE,

name = NULL,

time.scale = NULL,

log.scale = FALSE,

TA = 'addVo()',

TAsep=';',

line.type = "l",

bar.type = "ohlc",

theme = chartTheme("black"),

layout = NA,

major.ticks='auto',

minor.ticks=TRUE,

yrange=NULL, plot=TRUE,

up.col,

dn.col,

color.vol = TRUE,

multi.col = FALSE,

...)函数语法

chartSeries

远目量化

x an OHLC object -see details

type style of chart to draw

subset xts style date subsetting argument

show.grid display price grid lines?

name name of chart

time.scale what is the timescale? automatically deduced (broken)

log.scale should the y-axis be log-scaled?

TA a vector of technical indicators and params, or character strings TAsep TA delimiter for TA strings

line.type type of line in line chart

bar.type type of barchart -ohlc or hlc

theme a chart.theme object

layout if NULL bypass internal layout

major.ticks where should major ticks be drawn

minor.ticks should minor ticks be draw?

yrange override y-scale

plot should plot be drawn

up.col up bar/candle color

dn.col down bar/candle color

color.vol color code volume?

multi.col 4 color candle pattern

...additional parameters 参数含义

chartSeries

远目量化

chartSeries

自定义参数theme = chartTheme("black")

name=‘谷歌K线图’

up.col=‘red’

dn.col=‘green’

远目量化

远目量化

chartSeries

theme = chartTheme(“while")name =‘谷歌K线图’up.col =‘red’dn.col =‘green’

library(quantmod);

getSymbols("GOOG",src="yahoo",from="2016‐01‐01", to='2016‐06‐03')

chartSeries(GOOG,theme ='white',name='谷歌K 线图',up.col = 'red',dn.col = 'green')

传统方式

远目量化

chartSeries

theme = chartTheme(“white")

name =‘谷歌K线图’up.col =‘red’dn.col =‘green’

library(quantmod);

getSymbols("GOOG",src="yahoo",from="2016‐01‐01", to='2016‐05‐30')

chartSeries(GOOG,theme = 'white',name='谷歌',TA=NULL,up.col = 'red',dn.col = 'green')

不含成交量

TA=NULL

远目量化

chartSeries

library(quantmod);

getSymbols("GOOG",src="yahoo",from="2016‐01‐01", to='2016‐05‐30') GOOGW<‐to.weekly(GOOG)

chartSeries(GOOGW,theme = 'white',name='谷歌周线图',up.col = 'red',dn.col = 'green')

周K线图

GOOGW<‐to.weekly(GOOG)

相关文档