Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
new to quantopian with questions about first samples.

notional = context.portfolio.positions[context.aapl].amount * price

I think notional is the total value of your portfolio. But under the process of backtesting, I really don't know what's the value of my long position nor short position.
What I know is the return.
#if price < vwap * 0.995 and notional > context.min_notional:
order(context.aapl,-100)
# elif price > vwap * 1.005 and notional < context.max_notional:
order(context.aapl,+100)

the algorithm only tells the return, I don't really how many trade I made. if too many trades are made.. If too many trades are many, it may not be realistic.
So the problem is I don't know what's going on. what is my P&L. what is my notional positon.

6 responses

Hello Xun,

Here's some code that will limit the number of orders placed. Perhaps it will provide some insight.

Grant

Hi,Grant.
I've another problem,on the right part , I could enter begin date, end date, and $money which I assume total amount notional to begin with. So I tried to short or buy 50 shares aapl, and set the $=1, which is not enough to buy one share. but the backtest still works....

Hello Xun,

Would you be willing to post your code here? You can paste it into the text editor, or if you run a full backtest, you can use the "Add Backtest" button. I/we can then modify your code directly to address your question.

If you haven't already, I suggest adding log.debug statements at various points in your code so you can see what's happening.

Grant

Xun, at this point we have only reporting, not controls, around notional value and cash management. When you start an algorithm, that "initial capital" setting is used to calculate your returns, but is not used as a restriction. Since it's not automated within our system; you have to build code to do so.

See the attached backtest. It starts with a million dollars, and it checks before each trade to see how much cash is left. It's an example of how you'd put in cash limits.

As a side note, even this code is imperfect. All orders in Quantopian (so far) are market orders. So you might think you have enough money, but when your order actually fills, it might fill higher than you expected.

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Whoops, forgot the backtest:

Hello Dan (and Xun),

I concluded with the OLMAR algorithm that it requires a small positive cash balance to avoid borrowing (negative cash), as the portfolio is rebalanced by the algorithm. I haven't sorted out how to remedy the problem yet. It'd be kinda handy if one could just set a minimum cash balance to be maintained as a "side fund." If you set the default to zero, it might preclude some of the outrageous returns folks have published here (unless Quantopian has really deep pockets to loan out the money... : ) ).

Grant