quantitative-finance

Vectorized implementation of exponentially weighted moving standard deviation using R?

纵然是瞬间 提交于 2021-02-20 05:13:26
问题 I am trying to implement a vectorized exponentially weighted moving standard deviation using R. Is this the correct approach? ewma <- function (x, alpha) { c(stats::filter(x * ratio, 1 - ratio, "recursive", init = x[1])) } ewmsd <- function(x, alpha) { sqerror <- na.omit((x - lag(ewma(x, ratio)))^2) ewmvar <- c(stats::filter(sqerror * ratio, 1 - ratio, "recursive", init = 0)) c(NA, sqrt(ewmvar)) } I'm guessing it's not, since its output is different from Python's pandas.Series.ewm.std()

Vectorized implementation of exponentially weighted moving standard deviation using R?

▼魔方 西西 提交于 2021-02-20 05:12:33
问题 I am trying to implement a vectorized exponentially weighted moving standard deviation using R. Is this the correct approach? ewma <- function (x, alpha) { c(stats::filter(x * ratio, 1 - ratio, "recursive", init = x[1])) } ewmsd <- function(x, alpha) { sqerror <- na.omit((x - lag(ewma(x, ratio)))^2) ewmvar <- c(stats::filter(sqerror * ratio, 1 - ratio, "recursive", init = 0)) c(NA, sqrt(ewmvar)) } I'm guessing it's not, since its output is different from Python's pandas.Series.ewm.std()

Pandas P&L rollup to the next business day

烂漫一生 提交于 2021-02-10 17:50:29
问题 I'm having a hard time trying to do this efficiently. I have some stocks and daily P&L info in a dataframe. In reality, I have millions of rows of data so efficiency matters a lot! The Dataframe looks like : ------------------------------- | Date | Security | P&L | ------------------------------- | 2016-01-01 | AAPL | 100 | ------------------------------- | 2016-01-02 | AAPL | 200 | ------------------------------- | 2016-01-03 | AAPL | 300 | ------------------------------- | 2016-01-04 | AAPL

Can't install TA-lib python issue with Microsoft Visual Studio

让人想犯罪 __ 提交于 2021-02-08 11:15:42
问题 Trying to do a simple pip install TA-lib but am getting errors, in install Microsoft visual studios 14 but still the problem persists. error code http://pastebin.com/h4jHWd1m I tried to install it manually but get this: setup.py:77: UserWarning: Cannot find ta-lib library, installation may fail. warnings.warn('Cannot find ta-lib library, installation may fail.') running install running build running build_py running build_ext building 'talib.common' extension C:\Program Files (x86)\Microsoft

Can't install TA-lib python issue with Microsoft Visual Studio

烂漫一生 提交于 2021-02-08 11:15:32
问题 Trying to do a simple pip install TA-lib but am getting errors, in install Microsoft visual studios 14 but still the problem persists. error code http://pastebin.com/h4jHWd1m I tried to install it manually but get this: setup.py:77: UserWarning: Cannot find ta-lib library, installation may fail. warnings.warn('Cannot find ta-lib library, installation may fail.') running install running build running build_py running build_ext building 'talib.common' extension C:\Program Files (x86)\Microsoft

Efficiently calculating point of control with pandas

馋奶兔 提交于 2021-02-08 10:35:13
问题 My algorithm stepped up from 35 seconds to 15 minutes runtime when implementing this feature over a daily timeframe. The algo retrieves daily history in bulk and iterates over a subset of the dataframe (from t0 to tX where tX is the current row of iteration). It does this to emulate what would happen during the real time operations of the algo. I know there are ways of improving it by utilizing memory between frame calculations but I was wondering if there was a more pandas-ish implementation

request to IB responds differently when in a loop

谁说我不能喝 提交于 2021-02-08 08:26:22
问题 I just don't understand what is going on here. I'm a bit new to wrappers and IB. Here is my function that overrides and parses the XML. Should the XML be parsed in the main? I just want to get the fundamental data for all the symbols in my CSV file. When I comment out the loop and run an individual request it works, sometimes. What's going on here? class TestApp(EWrapper, EClient): def __init__(self): EWrapper.__init__(self) EClient.__init__(self, wrapper=self) self.csv = pd.read_csv('getfund

request to IB responds differently when in a loop

ⅰ亾dé卋堺 提交于 2021-02-08 08:26:20
问题 I just don't understand what is going on here. I'm a bit new to wrappers and IB. Here is my function that overrides and parses the XML. Should the XML be parsed in the main? I just want to get the fundamental data for all the symbols in my CSV file. When I comment out the loop and run an individual request it works, sometimes. What's going on here? class TestApp(EWrapper, EClient): def __init__(self): EWrapper.__init__(self) EClient.__init__(self, wrapper=self) self.csv = pd.read_csv('getfund

Trying to write a code which gives the strategy a buffer time before it takes the next trades

﹥>﹥吖頭↗ 提交于 2021-01-28 07:09:36
问题 What I'm trying to achieve is a "gap" of a few candles, say 4 in this case before the next trade happens Here nexT is the number of bars, before which the next trade should not take place But the value of nextT always resets to 0, everytime the code runs. What can be a possible modification to the code that the value of nexT does not reset automatically. //@version=4 strategy("RSI Strategy", overlay=true) //timeframe //timframe FromMonth = input(defval = 9, title = "From Month", minval = 1)

How to calculate the trendline for stock price

女生的网名这么多〃 提交于 2020-12-27 08:11:17
问题 I am trying to calculate and draw the trendlines for stock prices. I did some searches and thought for a whole day, there is no a really good idea on how to do. I have daily price history and want to find the cross point between trendline and price line. Could you provide some ideas or guidances? Thank you so much!!! 回答1: import pandas as pd import quandl as qdl from scipy.stats import linregress # get AAPL 10 years data data = qdl.get("WIKI/AAPL", start_date="2007-01-01", end_date="2017-05