@support
What if I or my family members wanted to invest in my own strategy?
Where can I find information on Quantiacs 'live' hedge fund services please?
Is that a different company? I cannot find a tab for investors on the site?
Thanks.
Posts made by spancham
-
RE: Strategy Funding
-
Pairs trading with states iterations
Hi @support
I am trying to merge my pairs strategy with the Quantiacs states iterations example.
It runs but I am still not certain if my code is correct however.
Can you have a look at my code below please and see if the implementation is correct?
What corrections would you make?
Don't be concerned that I am posting it here, these are not all the parameters or the futures contracts that I would use.import xarray as xr import numpy as np import qnt.data as qndata import qnt.backtester as qnbt def load_data(period): data = qndata.futures_load_data(tail=period) return data def strategy(data, state): zthreshold = 1.25 lookback_trading_days = 60 markets = ['F_GC', 'F_SI'] close = data.sel(field='close', asset=markets).transpose('time', 'asset') last_close = close.ffill('time').isel(time=-1) # state may be null, so define a default value if state is None: state = { "zscore": last_close, "zscore_prev": last_close, "output": xr.zeros_like(last_close) } zscore_prev = state['zscore'] zscore_prev_prev = state['zscore_prev'] output_prev = state['output'] # align the arrays to prevent problems in case the asset list changes zscore_prev, zscore_prev_prev, last_close = xr.align(zscore_prev, zscore_prev_prev, last_close, join='right') s1 = close[-lookback_trading_days:, 0] s2 = close[-lookback_trading_days:, 1] # Compute mean of the spread up to now mvavg = np.mean(np.log(s1/s2)) # Compute stdev of the spread up to now stdev = np.std(np.log(s1/s2)) # Compute current spread current_spread = np.log(s1[-1] / s2[-1]) # Compute z-score zscore = (current_spread - mvavg) / stdev if stdev > 0 else 0 if zscore >= zthreshold: output = [-0.5, 0.5] elif zscore <= -zthreshold: output = [0.5, -0.5] else: output = output_prev next_state = { "zscore": zscore, "zscore_prev": zscore_prev, "output": output } return xr.DataArray(output, dims=['asset'], coords=dict(asset=markets)), next_state weights, state = qnbt.backtest( competition_type="futures", # Futures contest lookback_period=100, # lookback in calendar days test_period=16*365, strategy=strategy, analyze=True, build_plots=True, collect_all_states=False # if it is False, then the function returns the last state, otherwise - all states )
Thank you!
-
RE: Share the state between iterations
@support
ok I did what @antinomy said below and the 'state' strategy worked.
https://quantiacs.com/community/topic/46/macroeconomic-data-with-quantiacs/3?_=1619554449031However, it broke my old strategies. So he further suggested to:
https://quantiacs.com/community/topic/46/macroeconomic-data-with-quantiacs/5?_=1619556376479
And my old strategies are running again.Ok, so looks like for now for all strategies without a state I have to output and pass None to weights for the state & pass a state variable to the strategy.
Will keep you updated. Thanks for looking into the issue. -
RE: Share the state between iterations
@support
I am working in the Quantiacs online env in my account, why doesn't it catch the latest libraries?
Anyway, I created a new Jupyter notebook with the strategy as suggested and it still does NOT work, same error msg. -
RE: Share the state between iterations
@support
Sorry friend, that still does not work.
I am working in the Quantiacs online cloud Jupyter environment.
I am NOT working locally.
I copied your example template as is and just added load_data().
Below is what I am running:import xarray as xr import numpy as np import qnt.data as qndata import qnt.backtester as qnbt def load_data(period): data = qndata.futures_load_data(tail=period) return data def strategy(data, state): close = data.sel(field="close") last_close = close.ffill('time').isel(time=-1) # state may be null, so define a default value if state is None: state = { "ma": last_close, "ma_prev": last_close, "output": xr.zeros_like(last_close) } ma_prev = state['ma'] ma_prev_prev = state['ma_prev'] output_prev = state['output'] # align the arrays to prevent problems in case the asset list changes ma_prev, ma_prev_prev, last_close = xr.align(ma_prev, ma_prev_prev, last_close, join='right') ma = ma_prev.where(np.isfinite(ma_prev), last_close) * 0.97 + last_close * 0.03 buy_signal = np.logical_and(ma > ma_prev, ma_prev > ma_prev_prev) stop_signal = ma < ma_prev_prev output = xr.where(buy_signal, 1, output_prev) output = xr.where(stop_signal, 0, output) next_state = { "ma": ma, "ma_prev": ma_prev, "output": output } return output, next_state weights, state = qnbt.backtest( competition_type="futures", # Futures contest lookback_period=365, # lookback in calendar days start_date="2006-01-01", strategy=strategy, analyze=True, build_plots=True, collect_all_states=False # if it is False, then the function returns the last state, otherwise - all states )
Error I'm getting is:
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-1-434dffafaefc> in <module> 50 analyze=True, 51 build_plots=True, ---> 52 collect_all_states=False # if it is False, then the function returns the last state, otherwise - all states 53 ) TypeError: backtest() got an unexpected keyword argument 'collect_all_states'
The reason I want to get the 'state' working is that I have a pairs trading strategy that needs it.
Any help would be greatly appreciated.
Thanks.In a related issue, when I run the macroeconomic example, I get the following error:
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-1-62eeefb4e65f> in <module> 76 strategy=strategy, 77 analyze=True, ---> 78 build_plots=True 79 ) ~/book/qnt/backtester.py in backtest(competition_type, strategy, load_data, lookback_period, test_period, start_date, window, step, analyze, build_plots) 66 data, time_series = extract_time_series(data) 67 print("Run pass...") ---> 68 result = strategy(data) 69 if result is None: 70 log_err("ERROR! Strategy output is None!") TypeError: strategy() missing 1 required positional argument: 'state'
-
RE: Share the state between iterations
Hi @support
Thanks but I tried that and it still did not work.
Just so you understand, I do NOT work locally, I only work in the Quantiacs online cloud Jupyter env.
I ran the update you suggested in my Quantiacs online Jupyter and it still did not work. I'm guessing you guys keep the env updated though.
I'm still getting the same error:
TypeError: backtest() got an unexpected keyword argument 'collect_all_states'Any suggestions pls?
-
RE: Strategy Funding
@support
Thank you. That is the level of detail I was looking for.
I presume you meant though the quant would receive a fixed management fee of $10K per month for $1M of funding on a 1.0 Sharpe Ratio strategy? -
RE: Share the state between iterations
@support
Please advise what to do here. Thanks.--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-1-434dffafaefc> in <module> 50 analyze=True, 51 build_plots=True, ---> 52 collect_all_states=False # if it is False, then the function returns the last state, otherwise - all states 53 ) TypeError: backtest() got an unexpected keyword argument 'collect_all_states'
-
How to install Python Talib
@support
Can you advise how to install the standard Python Talib in my Quantiacs online Jupyter?
link text
There are technical indicators in the Python Talib I would like to use that are not in the qnta lib?
Thank you. -
RE: Macroeconomic Data with Quantiacs
Thanks @antinomy!
That works. -
RE: Strategy Funding
@support
Thank you for responding.- Can you give me an idea pls what is the monthly $ amount a quant can make from the fixed fee? Just a ballpark range.
- What is a 'long track record'? How much time would the strategy have to be running?
-
RE: Macroeconomic Data with Quantiacs
@news-quantiacs
Thanks, well done!
How do you get 'state' though?TypeError Traceback (most recent call last) <ipython-input-1-8e93b849784e> in <module> 79 strategy=strategy, 80 analyze=True, ---> 81 build_plots=True 82 ) ~/book/qnt/backtester.py in backtest(competition_type, strategy, load_data, lookback_period, test_period, start_date, window, step, analyze, build_plots) 66 data, time_series = extract_time_series(data) 67 print("Run pass...") ---> 68 result = strategy(data) 69 if result is None: 70 log_err("ERROR! Strategy output is None!") TypeError: strategy() missing 1 required positional argument: 'state'
-
Strategy Funding
Hi guys,
I have a question about strategy funding.
I read somewhere that if you give out a $1M of funding, let's say the strategy developer wins a contest, then the strat dev will earn a percentage (e.g. 10%) of the quarterly earnings if the strat makes a profit for that quarter and so on. And if the strat loses for the quarter then the dev does not make any money but does not lose any money either.
My question is this:
If you guys are able to get investors for the dev's strat, let's say $10M hypothetically, will the dev get to share in the greater amount of earnings percentage wise from the $10M, or will the dev only get a percentage of earnings from the $1M?
That was long winded but I hope you understand my question.
Thanks. -
RE: Machine Learning Strategy
@support
ok guys, I tried what you suggested and I am running into all sorts of problems.
I want to pass several features altogether in one dataframe.
Are you guys thinking that I want to 'test' one feature at a time and that is why you are suggesting working with more than one dataframe?
Here is an example of some code I tried, but I would still have to merge the dataframes in order to pass the feature set to the classifier:def get_features(data): # let's come up with features for machine learning # take the logarithm of closing prices def remove_trend(prices_pandas_): prices_pandas = prices_pandas_.copy(True) assets = prices_pandas.columns print(assets) for asset in assets: print(prices_pandas[asset]) prices_pandas[asset] = np.log(prices_pandas[asset]) return prices_pandas # Feature 1 price = data.sel(field="close").ffill('time').bfill('time').fillna(0) # fill NaN price_df = price.to_dataframe() # Feature 2 vol = data.sel(field="vol").ffill('time').bfill('time').fillna(0) # fill NaN vol_df = vol.to_dataframe() # Merge dataframes for_result = pd.merge(price_df, vol_df, on='time') for_result = for_result.drop(['field_x', 'field_y'], axis=1) features_no_trend_df = remove_trend(for_result) return features_no_trend_df
Can you help with some code as to what you are suggesting?
Thanks -
RE: Machine Learning Strategy
Hi @support
Ok, let me think about what you are suggesting & see if I can get that to work.
Will let you know.
Thanks. -
RE: Machine Learning Strategy
- Can you help pls with an example on how to include more than one feature, such as from the fields (OHLCV)?
- And also from the qnt.ta library?
I am running into a problem converting the feature set to pandas when there are more than one features.
price = data.sel(field="close").ffill('time').bfill('time').fillna(0) # fill NaN for_result = price.to_pandas()
Thank you.