For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Problem with Cerebro engine

  • Hello! I am new in python and especcially in backtrader. I run example and get error
    alt text

    alt text

    It's shame for me to ask such stupid question, but I do only first steps.

  • administrators

    Pasting images, even if you may think is visually attractive, is not really helpful, because quoting isn't possible.

    I suggest you have a look at the error trace ... far away from the arrow ... and close to the bottom where it says: "No such file or directory", which means you need to place the file in the place where you are telling the data feed it should be.

  • Thank you for an answer.
    But I really thought it should download data from Yahoo Server and I dont need to save candles in file.

  • administrators

    You are using a data feed named: YahooFinanceCSVData which loads the data from a CSV file. File to which you are pointing in the datapath variable.

    If you want to go online, you can use the example from the homepage: where YahooFinanceData is used (the sources contain also multiple examples)

  • @backtrader thank you, but it doesn't help.

    alt text

  • pip install requests
    solved the problem

  • Let me ask another question.
    I started the script posted on your main page as example. I didn't change any line.
    But it ignored very important signal as you can see on my picture.
    Cross of movings was ignored. Why this happened?
    alt text

  • administrators

    1. You log no information at all and that's the reason you cannot even start seeing why and provide info on the topic. If you want to algotrade, you should produce lots of debugging/logging info.

    2. It was probably an accident waiting to happen.

    The definition of a CrossOver is:

    • upcross = data0(-1) < data1(-1) and data0(0) > data1(0)
    • downcross = data0(-1) > data1(-1) and data0(0) < data1(0)
    • crossover = upcross - downcross

    Although it seems comprehensive a crossing to the upside, for example, it will fail if data0(-1) < data1(-1) happens to be 0, even if data0(0) > data1(0). All the values before the index -1 may have granted a crossing upwards, but at time -1, the difference is nullified and the definition loses sense.

    Because Yahoo adjusts the data after dividends and splits, the point yo mark as "In" is one in which both Simple Moving Averages have the same value before the crossing upwards, which as explained above makes the definition fail.

    Before Yahoo adjusted the prices, this went unnoticed and because Yahoo will again adjust the prices it could have gone unnoticed forever.

    This be fixed by redefining CrossOver to take into account what happened before the 2 input sources (in the example two moving averages) happened to be the same.

    To be included in a release tomorrow.

  • administrators

  • @backtrader thank you for your answer, but I am not so stupid as you think about me (joke). On your image on backtrader main page these deals WERE MADE:
    alt text

  • administrators

    Regardless of the joke, you seem to completely miss the point, because you post the chart from the main page. To what purpose, unknown.

    If you do something and the results are not the expected ones ... a chart IS NOT the answer. Any attempt at being profitable at algotrading will require producing lots of information.

    How do you think that I quickly identified the problem and why the actual data delivered by Yahoo doesn't match what is displayed as an example on the main page?


    As you may see the first thing was producing output to understand that the moving averages were converging during two days to have exactly the same values 21.38 and 21.36. That's why the original definition of the CrossOver indicator is not able to cope with the scenario, because when sma1 > sma2, the condition for the previous day isn't met (it was sma1 < sma2), because the moving averages had exactly the same value.

    Hence the need to change the definition and make the crossover formula consider the last non-zero-difference between the input data feeds, which as shown in the data is -0.08 from 2011-12-15 where the values are 21.31 and 21.39

    You have to consider additionally that the input data will keep on changing, fact which you apparently ignore because you seem fixed on the chart from the main pge, because the prices will be adjusted for dividends and splits. In one year, the prices from MSFT may be halved or doubled and bear no apparent relationship to the chart from the main page.

    This adjustment is what actually created the no-difference conundrum which shows that the simple formula to define a crossover (present in the documentation) was too simple and needed to be extended.

Log in to reply