Quantstrat - applystrategy on subset of mktdata

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Quantstrat - applystrategy on subset of mktdata

Rmetrics mailing list
Hello all,
I am interested in backtesting the strategy on subset of mktdata  but somehow the below approach is resulting into errors.
################# yy="2016"out<-applyStrategy(strat.st , portfolios=portfolio.st, mktdata = mktdata[yy])
##################
I understand i can do it in 2 steps where in first step i calculate indicators/signals on the full time series and in second step only supply the subset of mktdata to portfolio for backtest.  But i was wondering if there is a way to do this in single step itself ? I think the problem is that the full mktdata is added to portfolio.st and not the subset of it ?
Any pointers will be helpful,
Regards,Mayank

        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Quantstrat - applystrategy on subset of mktdata

braverock
On Thu, 2016-12-15 at 06:31 +0000, Mayank Singhal via R-SIG-Finance
wrote:

> I am interested in backtesting the strategy on subset of mktdata  but
> somehow the below approach is resulting into errors.
> ################# yy="2016"out<-applyStrategy(strat.st ,
> portfolios=portfolio.st, mktdata = mktdata[yy])
> ##################
> I understand i can do it in 2 steps where in first step i calculate
> indicators/signals on the full time series and in second step only
> supply the subset of mktdata to portfolio for backtest.  But i was
> wondering if there is a way to do this in single step itself ? I
> think the problem is that the full mktdata is added to portfolio.st
> and not the subset of it ?
> Any pointers will be helpful,
> Regards,Mayank

You don't give enough information here for anyone to help you.

Please follow the Posting Guide:

https://www.r-project.org/posting-guide.html

and create a minimal reproducible example.

Also, per the posting guide, don't post HTML, as it makes your
formatting impossible to cut and paste from, even if there were a full
example here.

Brian

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Clarification on trailing stop.

Michael Chen


Hi all,

I am little confused regarding the "prefer" setting in trailing stop orders (may also apply to normal orders).  Setting prefer = "High",  as presented in the Luxor example, means to me that the trailing stop is set at the preset threshold level less than the most recent high.  Default prefer is set for 'Close'.   Prefer= sets the price column to use from data object (mktdata),  but I also read from well-informed bloggers that setting prefer = 'Open' means that after the condition is satisfied, the execution of the order will be at the Open of next bar instead of the Close.  So, is "Prefer=" setting defines the data column to be used in the apply rule calculations or is it used for preference for the point of execution for the order?  or both?

thanks again and I apologize if this has been answered before.  my search didn't reveal anything.

Michael


        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clarification on trailing stop.

braverock
On Tue, 2016-12-27 at 08:07 +0000, Michael Chen wrote:

> I am little confused regarding the "prefer" setting in trailing stop
> orders (may also apply to normal orders).  Setting prefer =
> "High",  as presented in the Luxor example, means to me that the
> trailing stop is set at the preset threshold level less than the most
> recent high.  Default prefer is set for 'Close'.   Prefer= sets the
> price column to use from data object (mktdata),  but I also read from
> well-informed bloggers that setting prefer = 'Open' means that after
> the condition is satisfied, the execution of the order will be at the
> Open of next bar instead of the Close.  So, is "Prefer=" setting
> defines the data column to be used in the apply rule calculations or
> is it used for preference for the point of execution for the
> order?  or both?
>
> thanks again and I apologize if this has been answered before.  my
> search didn't reveal anything.


The prefer= argument is passed to the getPrice() fn, and will determine
the price column that is used to set your threshold.

stoplimit orders will execute at the limit, so it should be 'High' +/-
threshold (depending on whether you are buying or selling)

Regards,

Brian

-- 
Brian G. Peterson 
http://braverock.com/brian/ 
Ph: 773-459-4973 
IM: bgpbraverock

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clarification on trailing stop.

Michael Chen
Thanks Brian, as always.    Just to make sure, for all order types, "prefer=",  sets the column data for calculation and therefore for excution.   So, stoplimit/trailing stop orders are excute at that limit ('prefer=high' +/- threshold), but market orders are executed at the next bar (if my indicator uses Cl for normal entry), then useing "prefer=open" will get the transaction price at open of the next bar.

________________________________
From: Brian G. Peterson <[hidden email]>
Sent: Tuesday, December 27, 2016 2:35 PM
To: Michael Chen; [hidden email]
Subject: Re: [R-SIG-Finance] Clarification on trailing stop.

On Tue, 2016-12-27 at 08:07 +0000, Michael Chen wrote:

> I am little confused regarding the "prefer" setting in trailing stop
> orders (may also apply to normal orders).  Setting prefer =
> "High",  as presented in the Luxor example, means to me that the
> trailing stop is set at the preset threshold level less than the most
> recent high.  Default prefer is set for 'Close'.   Prefer= sets the
> price column to use from data object (mktdata),  but I also read from
> well-informed bloggers that setting prefer = 'Open' means that after
> the condition is satisfied, the execution of the order will be at the
> Open of next bar instead of the Close.  So, is "Prefer=" setting
> defines the data column to be used in the apply rule calculations or
> is it used for preference for the point of execution for the
> order?  or both?
>
> thanks again and I apologize if this has been answered before.  my
> search didn't reveal anything.


The prefer= argument is passed to the getPrice() fn, and will determine
the price column that is used to set your threshold.

stoplimit orders will execute at the limit, so it should be 'High' +/-
threshold (depending on whether you are buying or selling)

Regards,

Brian

--
Brian G. Peterson
http://braverock.com/brian/
Brian G. Peterson<http://braverock.com/brian/>
braverock.com
BRIAN G. PETERSON 773-459-4973. [hidden email]. download resume as PDF SUMMARY. Senior quantitative trader, financial analyst, technical architect, and project ...


Ph: 773-459-4973
IM: bgpbraverock

        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Clarification on trailing stop.

braverock
On 12/27/2016 10:09 PM, Michael Chen wrote:
> Thanks Brian, as always.    Just to make sure, for all order types,
> "prefer=",  sets the column data for calculation and therefore for
> excution.   So, stoplimit/trailing stop orders are excute at that
> limit ('prefer=high' ± threshold), but market orders are executed at
> the next bar (if my indicator uses Cl for normal entry), then useing
> "prefer=open" will get the transaction price at open of the next
> bar.

It would be prefer="open", but yes.

Also be aware that this is a bit sloppy.  Real markets don't trade in bars.

Most investors don't really have access to the opening or closing
auctions if building backtests on daily data.  As noted in the
documentation and I have noted elsewhere, intraday historical data is
readily available, so in most cases you would likely be better served
using intraday data and something like a VWAP price if you have the data
available.

in any case, the prefer= argument is a pass-through to getPrice.
quantstrat will make reasonable guesses based on your data if it is not
set.  see

?getPrice

for more information on how getPrice works to extract price data.

Regards,

Brian

--
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock

_______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-finance
-- Subscriber-posting only. If you want to post, subscribe first.
-- Also note that this is not the r-help list where general R questions should go.
Loading...