l*******r 发帖数: 3799 | 1 in R:
library(quantmod) # A library for stock analysis
DJIA <- c("MMM", "AA", "AXP", "T", "BAC", "BA", "CAT", "CVX", "TRV", "KO", "
DD", "XOM", "GE", "CSCO", "HPQ", "HD", "IBM", "INTC", "JNJ", "JPM", "KFT", "
MCD", "MRK", "MSFT", "PFE", "PG", "UTX", "VZ", "WMT", "DIS")
getSymbols(DJIA) # Download historical data for Dow 30 stocks
getSymbols("^DJI") # Download historical data for Dow index
x <- do.call("rbind", lapply(DJIA, function(x) get(x)[, 4])) # Extract
close price
plot |
|
P**H 发帖数: 2272 | 2 比如我取到SINA的DF后,
getSymbols("SINA", from="2011-01-01", to="2011-05-15")
必须用SINA变量才能引用里面的数据,我现在需要把SINA的数据放到一个变量Symbol,
类似这样:
Symbol <- getSymbols("SINA", from="2011-01-01", to="2011-05-15") //这个结果
是错误的
然后我调用SymbolClose <- Cl(Symbol)就得到当前股票的收盘数据序列,不想用每个
股票的代号去引用,这样我可以把整个TA指数写入函数中而不用hardcode股票名称。
有人知道怎么做吗? |
|
a*****e 发帖数: 1717 | 3 Here's python one I used before,
drawbacks:
1. data pacing violation, limit on size of each quote, interval etc.
2. futures symbols are less standardized
3. IB data sucks, but ok for median to long term backtest
4. the ibpy is out-dated, you have to update yourself to get new
features.
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from ib.ext.Contract import Contract
from ib.opt import ibConnection, message
from time import sleep
from datetime import date
import pyodbc, os, sys
# print all mess... 阅读全帖 |
|
b****5 发帖数: 449 | 4 给想要学习R 做简单统计的朋友们,放进去自己改改应该能跑了。这个是新手练习向的。
应该是我发的最后一个主贴了,股版还是吵架的多,讨论技术的确实少。马上回国工作
了也不能看了。
最后可以看出某些股票最多连跌多少天。希望给大家帮助。
这个娱乐性质比较强,真正的model远比这个复杂。
library(quantmod)
library(PerformanceAnalytics)
#library(plyr)
source("calc_return.R")
ticker = "IWM"
bench = "SPY"
start_t = '2010-12-30'
end_t = '2016-01-20'
raw_bench = getSymbols(Symbols=bench,auto.assign = F, from= start_t,to= end_
t)
raw_prices = getSymbols(Symbols=ticker,auto.assign = F, from= start_t,to=
end_t)
dates = index(raw_prices)
l_dates = le... 阅读全帖 |
|
e*n 发帖数: 1511 | 5 【 以下文字转载自 Stock 讨论区 】
发信人: mitbbs2020 (bbc), 信区: Stock
标 题: Re: 【Stragety论坛】Trading with correlations.
发信站: BBS 未名空间站 (Sun Jul 25 19:52:04 2010, 美东)
用option当然可以,但不是必须,
用option可以得到更高的leverage,
但是缺点是散户量小,不容易实现market neutral。
比如1.37的hedge ratio,你要long 137和short 100个才能实现。
13和10就不那么好,而且不容易adjust,看附图就知道不怎么neutral的情况。
说stock不便于对冲,这点我不懂你什么意思。
这本身就是market neutral的strategy。
我测试过DISCA和AXP(paper account),追踪了至少2个月,涨跌幅从来没超过3%的,
但是这反过来说明这不是一对好的pair。
别的pair,没有任何leverage,一年可以做到100%以上的也有,如果我实际做stock到
这个%,
已经很满意了... 阅读全帖 |
|
D*****l 发帖数: 554 | 6 Merging Current Stock Quotes with Historical Prices
By systematicinvestor
#*****************************************************************
# Load historical data
#******************************************************************
load.packages('quantmod')
tickers = spl('VTI,EFA,SHY')
data <- new.env()
getSymbols(tickers, src = 'yahoo', from = '1980-01-01', env = data, auto.
assign = T)
for(i in ls(data)) data[[i]] = adjustOHLC(data[[i]], use.Adjusted=T) ... 阅读全帖 |
|
s*****n 发帖数: 5488 | 7 library(quantmod)
getSymbols(c("MSFT", "AAPL", GOOG")
you are done. |
|
s*****n 发帖数: 5488 | 8 library(quantmod)
getSymbols(c("MSFT", "AAPL", GOOG")
you are done. |
|
s*****n 发帖数: 5488 | 9 QQ是学数学的?R的会?看上去次日收益mean是-0.2个百分点。周收益是-0.5个百分点。
library(quantmod)
getSymbols("SPY", from="1900-01-01")
a=SPY[(SPY$SPY.Close - SPY$SPY.Open > SPY$SPY.Open * 0.007) & (SPY$SPY.Open
- lag(SPY$SPY.Close) < -0.01 * SPY$SPY.Open)]
i = index(a)
r1=SPY$SPY.Close - lag(SPY$SPY.Close, -1)
r=SPY$SPY.Close - lag(SPY$SPY.Close, -5)
merge(a,r[i], r1[i])
summary(r1[i])
summary(r[i])
summary(r1[i])
Index SPY.Close
Min. :1994-03-02 Min. :-12.8500
1st Qu.:2000-04-05 1st Qu.: -1.295... 阅读全帖 |
|
发帖数: 1 | 10 特别是用循环的的时候,存在很多股票的数据无法成功下载。不知道是我网络的问题,
还是??有克服的办法吗? |
|
J*X 发帖数: 1001 | 11 This is common. I guess because it's free. You can try to use catch and
throw |
|
发帖数: 1 | 12 谢谢JTX大牛,什么是 catch and throw |
|
|
m*p 发帖数: 1331 | 14 太感谢啦!quantmod挺容易上手的。
我用了getsymbol,发现只能download到从2007开始的OHLC,不知道怎么下载更长的历
史数据? |
|
w******e 发帖数: 142 | 15 R现在有一个很好的package,还带了很多technical analysis的function
library(quantmod)
graphics.off()
#get the C price from yahoo
getSymbols('C',src='yahoo',from = "1994-01-01")
chartSeries(C,subset='last 4 months',TA=NULL,theme=chartTheme('white')) |
|