Attaching my results
I am not able to understand how it is giving such a huge return. . .
Attaching my results
I am not able to understand how it is giving such a huge return. . .
Don't have time to go through the code line by line right now, but you might want to check up on how your algorithm utilizes leverage.
Cheers.
It keeps on buying beyond available cash.
I need to implement some way of validating the available cash before creating the order.
Either add this:
if get_open_orders(context.security):
return # Have open orders, do nothin
or this:
for order in get_open_orders(context.security):
cancel_order(order) # Cancel this order.
You aren't accounting for the cost of borrowing money to execute this strategy. You also aren't taking into account that you would have been margin called many, many times if this was actually trading, assuming there is a broker out there that would even let you take on this kind of leverage. You also have a pretty nice starting point at 2011.
Yagnesh,
When you are placing orders you are failing to account for the size of the position currently in your portfolio. If you want to own 100 shares, you have to buy the difference between 100 and the current # of shares you own.
I switched this to use the built-in 'order_target' function which will order the difference between your target and current position. I also added a check for open orders so that it will not trade until previous trades have been completed. This should help you get going again.
David