quantitative-finance

Getting stock news data from google in R [closed]

岁酱吖の 提交于 2019-12-07 17:23:10
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 9 months ago . I can use quantmod to get historical data and close-to-realtime quotes for stocks. I can also use quantmod to get financials data from Google. Are there any existing R packages that would let me grab Google's news feed for a given stock? If not, is there a package for reading and parsing RSS feeds in R? 回答1:

Error: C stack usage 7970184 is too close to the limit

[亡魂溺海] 提交于 2019-12-07 14:10:29
问题 I would like to compute the RSI function, which is given as follows: RSI = 100 * RS / ( 1 + RS ), where RS = n_up / n_down and n_up( t ) = ( 1 - b ) * n_up( t - 1 ) + b * U( t ), and n_down( t ) = ( 1 - b ) * n_down( t - 1 ) + b * D( t ). where U( t ) = 1 for P( t ) > P( t - 1 ) and 0 otherwise; and D( t ) = 1 for P( t ) < P( t - 1 ) and 0 otherwise. So here is my code: p <- data[,6] rsi <- function(P,t,n) { U <- function(P,t) { if (diff(P)[t] > 0) { return(1) } else { return(0) } } D <-

Create efficient frontier in PortfolioAnalytics without an xts object

十年热恋 提交于 2019-12-07 07:25:15
问题 Is there a way to create an efficient frontier in the PortfolioAnalytics package without specifying an xts object of asset returns? Instead I'd like to supply the vector of expected returns and the covariance matrix. 回答1: There are two ways. First you can supply a list containing containing your matrices with the structure shown below and then call optimize.portfolio including this list as an argument. # num_assets is the number of assets in the portfolio momentargs <- list() momentargs$mu <-

Pandas DataFrame column assignment ValueError: Wrong number of items passed

烂漫一生 提交于 2019-12-06 13:23:23
I am having an issue with a script that was functioning prior to an upgrade of Anaconda (thus an upgrade of pandas and numpy) I have a DataFrame that I would like to use one column from and multiply by the values in a column of another DataFrame, outputting the final value to a column in a new DataFrame. As I said this code was working until I upgraded to pandas 0.17. class MarketOnClosePortfolio(Portfolio): def __init__(self, symbol, bars, signals, initial_capital=10000.0): self.symbol = symbol self.bars = bars self.signals = signals self.initial_capital = float(initial_capital) self

How to look back at previous rows from within Pandas dataframe function call?

坚强是说给别人听的谎言 提交于 2019-12-06 09:09:37
问题 I am researching/backtesting a trading system. I have a Pandas dataframe containing OHLC data and have added several calculated columns which identify price patterns that I will use as signals to initiate positions. I would now like to add a further column that will keep track of the current net position. I have tried using df.apply(), but passing the dataframe itself as the argument instead of the row object, as with the latter I seem to be unable to look back at previous rows to determine

Error: C stack usage 7970184 is too close to the limit

感情迁移 提交于 2019-12-06 00:44:03
I would like to compute the RSI function, which is given as follows: RSI = 100 * RS / ( 1 + RS ), where RS = n_up / n_down and n_up( t ) = ( 1 - b ) * n_up( t - 1 ) + b * U( t ), and n_down( t ) = ( 1 - b ) * n_down( t - 1 ) + b * D( t ). where U( t ) = 1 for P( t ) > P( t - 1 ) and 0 otherwise; and D( t ) = 1 for P( t ) < P( t - 1 ) and 0 otherwise. So here is my code: p <- data[,6] rsi <- function(P,t,n) { U <- function(P,t) { if (diff(P)[t] > 0) { return(1) } else { return(0) } } D <- function(P,t) { if (diff(P)[t] < 0) { return(1) } else { return(0) } } recursive.n_up <- function(P,t,b) {

How to use a custom calendar in a custom zipline bundle?

限于喜欢 提交于 2019-12-05 02:54:24
问题 I have the following code in my viacsv.py file that aims to allow a custom bundle to be ingested: # # Ingest stock csv files to create a zipline data bundle import os import numpy as np import pandas as pd import datetime boDebug=True # Set True to get trace messages from zipline.utils.cli import maybe_show_progress def viacsv(symbols,start=None,end=None): # strict this in memory so that we can reiterate over it. # (Because it could be a generator and they live only once) tuSymbols = tuple

Adding Multiple Chart Series in Quantmod R

时光总嘲笑我的痴心妄想 提交于 2019-12-05 00:55:28
问题 I am trying to plot two charts on one chartSeries in quantmod in R. I am having some difficulty doing this. library(quantmod) tickers <- c('GLD', 'GDX') data <- new.env() getSymbols(tickers, src = 'yahoo', from = '1980-01-01', env = data) chartSeries(Cl(data$GLD), TA="addTA(Cl(data$GDX), on=1)") addRSI() 回答1: You could use chart_Series instead of chartSeries . chart_Series(Cl(data$GLD)) add_TA(Cl(data$GDX), on = 1) And then if you want RSI below in a sub panel, just add add_RSI() . Another

How to look back at previous rows from within Pandas dataframe function call?

断了今生、忘了曾经 提交于 2019-12-04 18:58:37
I am researching/backtesting a trading system. I have a Pandas dataframe containing OHLC data and have added several calculated columns which identify price patterns that I will use as signals to initiate positions. I would now like to add a further column that will keep track of the current net position. I have tried using df.apply(), but passing the dataframe itself as the argument instead of the row object, as with the latter I seem to be unable to look back at previous rows to determine whether they resulted in any price patterns: open_campaigns = [] Campaign = namedtuple('Campaign', 'open

Is there any elegant way to define a dataframe with column of dtype array?

点点圈 提交于 2019-12-04 17:10:35
问题 I want to process stock level-2 data in pandas. Suppose there are four kinds data in each row for simplicity: millis: timestamp, int64 last_price: the last trade price, float64, ask_queue: the volume of ask side, a fixed size (200) array of int32 bid_queue: the volume of bid side, a fixed size (200) array of int32 Which can be easily defined as a structured dtype in numpy: dtype = np.dtype([ ('millis', 'int64'), ('last_price', 'float64'), ('ask_queue', ('int32', 200)), ('bid_queue', ('int32',