Replies: 2 comments 2 replies
-
This is the supported and recommended approach. Anything you pass in as data will be available the same way as computed indicators and OHLC price points are. You may then save the computed statistics (and such, whatever you're after) into an object and process it after backtest run. For rolling VWAP, I'd do: class Example(Strategy):
def init(self):
df = self.data.df
def VWAP(prices, volume, n):
return (prices * volume).rolling(n).sum() / volume.rolling(n).sum()
self.vwap = self.I(VWAP, df.Close, df.Volume, 20)
... Have it plotted and all. |
Beta Was this translation helpful? Give feedback.
-
On second read, I don't quite get it ...
Why not just place multiple orders? 🤨 Something like: signal = signal.rolling(n).max() # spread the signal to n bars
order_size = order_size / n |
Beta Was this translation helpful? Give feedback.
-
Is there a simple way to create an order type that will simulate a "fill price" based on average prices in the future? eg. TWAP (time weighted average price) VWAP (volume weighted average price). I was thinking about an instance variable in Order like 'limit' or 'stop' in the meantime, I was thinking I might modify the data creating additional columns VWAP and TWAP in addition to {open, high, low, close}. VWAP and TWAP would contain future information for trade purposes but not for signal purposes.
The justification is obviously to simulate more real world hypotheticals. If managing meaningful capital, orders would need to be spread out over time and volume once the signal recommends a trade.
I realize this is meant to be a lightweight simple to use package, so maybe this is too much to think of from a feature perspective, but perhaps there is a simple work around that I can put together as an example for the docs.
Beta Was this translation helpful? Give feedback.
All reactions