Your best approach:
Load it with pandas.read_csv
Separate by symbol by using, for example, the clause where (that is, you create a mask that considers only the name of a ticker)
Write the result of each mask to a separate csv file.
The last step can actually be forfeited, because you end up with several pandas.DataFrames which can be directly fed to cerebro via PandasData
@Jenel-Videos said in StringIO Object to DataFeed:
data = btfeed.GenericCSVData(
After creating file (a pseudo-file) actually, why do you pass a string instead of the file-like object which you have already created?
The documentation says it:
Specific parameters (or specific meaning):
- ``dataname``: The filename to parse or a file-like object
Thanks for your help. I have the following:
lines = ('AcctValue', 'MA')
params = dict(ma_len=20)
def __init__(self, type):
self.l.AcctValue = self._owner.broker.get_value()
if type == 'SMA':
self.l.MA = bt.ind.MovingAverageSimple(self.l.AcctValue, period=self.p.ma_len)
elif type == 'EMA':
self.l.MA = bt.ind.ExponentialMovingAverage(self.l.AcctValue, period=self.p.ma_len)
But I get:
TypeError: 'float' object is not callable
Is there a specific way to store and subsequently use the value of the broker in this case?
Don't take me for rude, but you say "trailing stop fired ...." and I could also say "trailing stop not fired ...".
There is no indication as to what you are doing, what's happening, if that is actually the right behavior.
Even if what you say would make some sense ... the following is completely wrong:
@fede3u said in Trailing stop fired by High and Low instead of Close price:
How can I modify the logic of the bt.Order.StopTrail.
You can also go and try to modify how the markets work. It may be easier and it will probably fit what you have backtested with something you have modified to fit your wishes and not to try to model how things work in the reality.
If StopTrail doesn't do what you expect, these are the possible reasons:
You don't know how such an order works in real markets
You do, but it's not the order type which fits what you try to model, but you have still chosen to do it.
Imho: very wrong way to approach your backtesting.
AFAIU, upon resampling new bars are built aggregating the information from the originals bars of the feed with a smaller timeframe. Those new bars have no knowledge about the non-standard attributes of the originals bars ( only datetime, high, low, open, close, volume and openinterest fields are processed), nor they know anything about how to aggregate such fields. This may explain the behavior you saw.
The plotting code doesn't do recursion and doesn't see see the embedded indicators. The solutions you attempted as shown in the documentation page you linked are for the indicators and operations which happen directly in the strategy code.
The only trick I can offer you (not tested)
Create your indicator.
Create moving averages of period 1 which use your embedded indicators as data
my_indicator = MyIndicator(....)
emb_ind_1 = bt.ind.SMA(my_indicator.embedded_indicator1, period=1)
Now, the SMA doesn't know still where to plot itself, because the indicators won't be plotted.
emb_ind_1.plotinfo.plotmaster = self.data
emb_ind_1.plotinfo.subplot = True
which says that they should be considered indicators of self.data for plotting purposes and be plotted in an own sub-graph.