Cash greater than value when using Long signal
When trying to replicate the examples on the Strategy with Signals documentation page, I have run into some weird results. Specifically, I am testing out how to use long signals (bt.SIGNAL_LONG). I expect that when using long only, my cash should never exceed my value, which I do find is what happens when I am using one of the sample datasets in the Github repo (2006-day-002.txt).
However, when I switch to using my own data source, after a sell signal, cash increases past value, and remains until a buy signal (which I think is what a short should do?).
I suppose my first question is: When using signals as long only, should cash ever be greater than value?
And if not, what are some possible explanations for what is happening here?
My theory is that there is a fundamental piece of finance that I am misunderstanding.
As an aside, I've disabled loading volume in the sample dataset because I lack volume information in my dataset. Since the signals are only based on SMA, I don't think that this would be a problem.
I appreciate the help. Thanks.
class SMACloseSignal(bt.Indicator): lines = ('signal',) params = (('period', 30),) def __init__(self): self.lines.signal = self.data - bt.indicators.SMA(period=self.p.period) class SMAExitSignal(bt.Indicator): lines = ('signal',) params = (('p1', 5), ('p2', 30),) def __init__(self): sma1 = bt.indicators.SMA(period=self.p.p1) sma2 = bt.indicators.SMA(period=self.p.p2) self.lines.signal = sma1 - sma2 ######################### data = btfeeds.GenericCSVData( dataname="2006-day-002.txt", nullvalue=0.0, dtformat=('%Y-%m-%d'), datetime=0, high=2, low=3, open=1, close=4, volume=-1, openinterest=-1, ) cerebro = bt.Cerebro() cerebro.broker.set_cash(100000) cerebro.adddata(data) cerebro.add_signal(bt.SIGNAL_LONG, SMACloseSignal, period=30) cerebro.run() cerebro.plot() plt.gcf().set_size_inches(20, 10)